From f42ca324454868bbf4e43ad09c7b75f6c7159b84 Mon Sep 17 00:00:00 2001 From: Alec Hinh Date: Wed, 16 Aug 2023 10:38:13 -0500 Subject: [PATCH 1/2] Add fallback behavior for when getting latest pipeline ID fails due to no merge request pipelines configured Signed-off-by: Alec Hinh --- pkg/vcs/gitlab/mr_status_updater.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/vcs/gitlab/mr_status_updater.go b/pkg/vcs/gitlab/mr_status_updater.go index b8e2955..0ae1711 100644 --- a/pkg/vcs/gitlab/mr_status_updater.go +++ b/pkg/vcs/gitlab/mr_status_updater.go @@ -168,12 +168,23 @@ func (p *RunStatusUpdater) getLatestPipelineID(rmd runstream.RunMetadata) *int { return nil } log.Trace().Interface("pipelines", pipelines).Msg("retrieved pipelines for commit") + var pipelineID *int if len(pipelines) > 0 { for _, p := range pipelines { if p.GetSource() == "merge_request_event" { - return gogitlab.Int(p.GetID()) + pipelineID = gogitlab.Int(p.GetID()) + return pipelineID } } + // If we can't find a merge request CI/CD pipeline for the commit + // Return the last pipeline ID in the pipelines array as the ID as a fallback. + // If there are no pipelines, TFC will send the external status update to nil which will create + // a pipeline that subsequent function calls will use. + if pipelineID == nil { + log.Debug().Msg("No merge request pipeline ID found for the commit. Using latest pipeline ID as fallback...") + pipelineID = gogitlab.Int(pipelines[len(pipelines)-1].GetID()) + return pipelineID + } } return nil } From 7f10ed576150d737e72ce86aeb82d923e3d98080 Mon Sep 17 00:00:00 2001 From: Alec Hinh Date: Wed, 16 Aug 2023 12:25:05 -0500 Subject: [PATCH 2/2] Update comments IRT fallback Signed-off-by: Alec Hinh --- pkg/vcs/gitlab/mr_status_updater.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pkg/vcs/gitlab/mr_status_updater.go b/pkg/vcs/gitlab/mr_status_updater.go index 0ae1711..2984c2c 100644 --- a/pkg/vcs/gitlab/mr_status_updater.go +++ b/pkg/vcs/gitlab/mr_status_updater.go @@ -176,10 +176,8 @@ func (p *RunStatusUpdater) getLatestPipelineID(rmd runstream.RunMetadata) *int { return pipelineID } } - // If we can't find a merge request CI/CD pipeline for the commit - // Return the last pipeline ID in the pipelines array as the ID as a fallback. - // If there are no pipelines, TFC will send the external status update to nil which will create - // a pipeline that subsequent function calls will use. + // Fallback behavior if Gitlab doesn't find any merge request pipelines + // Returns last pipeline ID in the pipelines list if pipelineID == nil { log.Debug().Msg("No merge request pipeline ID found for the commit. Using latest pipeline ID as fallback...") pipelineID = gogitlab.Int(pipelines[len(pipelines)-1].GetID())