From e2b250fc47672eeffe38c51f20c08d5d51653c7a Mon Sep 17 00:00:00 2001 From: Fitz Date: Mon, 15 Apr 2024 14:49:49 +0100 Subject: [PATCH] if no pipeline found check for merge results pipeline --- pkg/controller/pipelines.go | 16 ++++++++++++++++ pkg/schemas/ref.go | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) 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"