Skip to content

Commit af18e5c

Browse files
authored
Merge pull request #36 from ahinh43/duplicate-message-posting
Have `getLatestPipelineID` return branch pipeline ID if no merge request pipeline was found
2 parents f55683f + 238f4b4 commit af18e5c

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

pkg/vcs/gitlab/mr_status_updater.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,21 @@ func (p *RunStatusUpdater) getLatestPipelineID(ctx context.Context, rmd runstrea
177177
return nil
178178
}
179179
log.Trace().Interface("pipelines", pipelines).Msg("retrieved pipelines for commit")
180+
var pipelineID *int
180181
if len(pipelines) > 0 {
181182
for _, p := range pipelines {
182183
if p.GetSource() == "merge_request_event" {
183-
return gogitlab.Int(p.GetID())
184+
pipelineID = gogitlab.Int(p.GetID())
185+
return pipelineID
184186
}
185187
}
188+
// Fallback behavior if Gitlab doesn't find any merge request pipelines
189+
// Returns last pipeline ID in the pipelines list
190+
if pipelineID == nil {
191+
log.Debug().Msg("No merge request pipeline ID found for the commit. Using latest pipeline ID as fallback...")
192+
pipelineID = gogitlab.Int(pipelines[len(pipelines)-1].GetID())
193+
return pipelineID
194+
}
186195
}
187196
return nil
188197
}

0 commit comments

Comments
 (0)