Skip to content

Commit

Permalink
gitlab: link latest commit to the correct pipeline
Browse files Browse the repository at this point in the history
PR runatlantis#4785 was a partial fix, as it might link a commit to the wrong pipeline when
GitLab is slow to update the HeadPipeline.

This patch ensures the latest commit is always linked to the correct
pipeline by querying the pipeline associated with the commit's ref,
instead of relying on HeadPipeline.

Tested in our environment and it looks good so far.

Signed-off-by: Raul Gutierrez Segales <rsegales@nvidia.com>
  • Loading branch information
rgs1 committed Aug 21, 2024
1 parent ee1134f commit 9422ae0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions server/events/vcs/gitlab_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,9 @@ func (g *GitlabClient) UpdateStatus(logger logging.SimpleLogging, repo models.Re
if err != nil {
return err
}
if mr.HeadPipeline != nil {
logger.Debug("Head pipeline found for merge request %d, source '%s'. refTarget '%s'",
pull.Num, mr.HeadPipeline.Source, mr.HeadPipeline.Ref)
if mr.HeadPipeline != nil && mr.SHA == mr.HeadPipeline.SHA {
logger.Debug("Head pipeline found for merge request %d, source '%s'. refTarget '%s' SHA '%s'",
pull.Num, mr.HeadPipeline.Source, mr.HeadPipeline.Ref, mr.HeadPipeline.SHA)
// set pipeline ID for the req once found
pipelineID = gitlab.Ptr(mr.HeadPipeline.ID)
break
Expand Down

0 comments on commit 9422ae0

Please sign in to comment.