diff --git a/pkg/controller/pipelines.go b/pkg/controller/pipelines.go index 81734343..95266cf8 100644 --- a/pkg/controller/pipelines.go +++ b/pkg/controller/pipelines.go @@ -53,6 +53,22 @@ func (c *Controller) PullRefMetrics(ctx context.Context, ref schemas.Ref) error return fmt.Errorf("error fetching project pipelines for %s: %v", ref.Project.Name, err) } + if len(pipelines) == 0 && ref.Kind == schemas.RefKindMergeRequest { + refName = fmt.Sprintf("refs/merge-requests/%s/merge", ref.Name) + pipelines, _, err = c.Gitlab.GetProjectPipelines(ctx, ref.Project.Name, &goGitlab.ListProjectPipelinesOptions{ + // We only need the most recent pipeline + ListOptions: goGitlab.ListOptions{ + PerPage: 1, + Page: 1, + }, + Ref: &refName, + }) + + if err != nil { + return fmt.Errorf("error fetching project pipelines for %s: %v", ref.Project.Name, err) + } + } + if len(pipelines) == 0 { log.WithFields(logFields).Debug("could not find any pipeline for the ref") diff --git a/pkg/schemas/ref.go b/pkg/schemas/ref.go index 8f403a86..17314103 100644 --- a/pkg/schemas/ref.go +++ b/pkg/schemas/ref.go @@ -10,7 +10,7 @@ import ( ) const ( - mergeRequestRegexp string = `^((\d+)|refs/merge-requests/(\d+)/head)$` + mergeRequestRegexp string = `^((\d+)|refs/merge-requests/(\d+)/(?:head|merge))$` // RefKindBranch refers to a branch. RefKindBranch RefKind = "branch"