From ee85dbd934fd809cf73a1b8676026a067bfbf219 Mon Sep 17 00:00:00 2001 From: Fitz Date: Fri, 8 Mar 2024 17:59:31 +0000 Subject: [PATCH 1/3] fix: gitlab update status should return error if the shas dont match --- server/events/vcs/gitlab_client.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/events/vcs/gitlab_client.go b/server/events/vcs/gitlab_client.go index cd21386c00..4676e856e5 100644 --- a/server/events/vcs/gitlab_client.go +++ b/server/events/vcs/gitlab_client.go @@ -413,13 +413,13 @@ func (g *GitlabClient) UpdateStatus(logger logging.SimpleLogging, repo models.Re return err } if mr.HeadPipeline != nil { - logger.Info("Head pipeline found for merge request %d, source '%s'. pipelineID '%s'", + logger.Info("Head pipeline found for merge request %d, source '%s'. pipelineID '%d'", pull.Num, mr.HeadPipeline.Source, mr.HeadPipeline.ID) pipelineID = gitlab.Ptr(mr.HeadPipeline.ID) - // let's check to see if the pipeline sha matches the head commit. + // if these don't match then there has been a new commit so let's return if mr.HeadPipeline.SHA != pull.HeadCommit { - logger.Err("Head pipeline SHA does not match pull head commit") + return errors.Errorf("mr.HeadPipeline.SHA: '%s' does not match pull.HeadCommit '%s'", mr.HeadPipeline.SHA, pull.HeadCommit) } break } From a44c0583b512037e5f3e1f5ee97336fa81a6c6df Mon Sep 17 00:00:00 2001 From: Fitz Date: Fri, 8 Mar 2024 18:07:29 +0000 Subject: [PATCH 2/3] test: add real sha to tests --- server/events/vcs/gitlab_client_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/events/vcs/gitlab_client_test.go b/server/events/vcs/gitlab_client_test.go index 0ce23a9c64..20697cece3 100644 --- a/server/events/vcs/gitlab_client_test.go +++ b/server/events/vcs/gitlab_client_test.go @@ -337,7 +337,7 @@ func TestGitlabClient_UpdateStatus(t *testing.T) { models.PullRequest{ Num: 1, BaseRepo: repo, - HeadCommit: "sha", + HeadCommit: "67cb91d3f6198189f433c045154a885784ba6977", HeadBranch: "test", }, c.status, "src", "description", "https://google.com") Ok(t, err) From 10f8efe4aca9aebaa862ed2c6ec695b8a6c3503b Mon Sep 17 00:00:00 2001 From: Fitz Date: Fri, 8 Mar 2024 18:12:26 +0000 Subject: [PATCH 3/3] test: add the sha to the mock server too --- server/events/vcs/gitlab_client_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/events/vcs/gitlab_client_test.go b/server/events/vcs/gitlab_client_test.go index 20697cece3..820b65d65e 100644 --- a/server/events/vcs/gitlab_client_test.go +++ b/server/events/vcs/gitlab_client_test.go @@ -298,7 +298,7 @@ func TestGitlabClient_UpdateStatus(t *testing.T) { testServer := httptest.NewServer( http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { switch r.RequestURI { - case "/api/v4/projects/runatlantis%2Fatlantis/statuses/sha": + case "/api/v4/projects/runatlantis%2Fatlantis/statuses/67cb91d3f6198189f433c045154a885784ba6977": gotRequest = true body, err := io.ReadAll(r.Body)