Skip to content

Commit faeb579

Browse files
handle both ref name syntax for pipelines api
1 parent 2024af8 commit faeb579

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pkg/controller/pipelines.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ func (c *Controller) PullRefMetrics(ctx context.Context, ref schemas.Ref) error
5353
return fmt.Errorf("error fetching project pipelines for %s: %v", ref.Project.Name, err)
5454
}
5555

56+
// when "Enable merged results pipelines" is enabled (or other cases), the refName needs to end by /merge instead of /head
57+
if len(pipelines) == 0 && ref.Kind == schemas.RefKindMergeRequest {
58+
refName = fmt.Sprintf("refs/merge-requests/%s/merge", ref.Name)
59+
pipelines, _, err = c.Gitlab.GetProjectPipelines(ctx, ref.Project.Name, &goGitlab.ListProjectPipelinesOptions{
60+
// We only need the most recent pipeline
61+
ListOptions: goGitlab.ListOptions{
62+
PerPage: 1,
63+
Page: 1,
64+
},
65+
Ref: &refName,
66+
})
67+
if err != nil {
68+
return fmt.Errorf("error fetching project pipelines for %s: %v", ref.Project.Name, err)
69+
}
70+
}
71+
5672
if len(pipelines) == 0 {
5773
log.WithFields(logFields).Debug("could not find any pipeline for the ref")
5874

0 commit comments

Comments
 (0)