Skip to content

Commit

Permalink
if no pipeline found check for merge results pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
fitz7 committed Apr 15, 2024
1 parent f3ed829 commit e2b250f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions pkg/controller/pipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion pkg/schemas/ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit e2b250f

Please sign in to comment.