From 9641d8e65d1dbd58ea70d9cbc6d21432e80d33e1 Mon Sep 17 00:00:00 2001 From: Andrew Fitzpatrick Date: Mon, 11 Mar 2024 11:15:52 +0000 Subject: [PATCH] fix: err if gitlab shas dont match (#5) * fix: gitlab update status should return error if the shas dont match * test: add real sha to tests * test: add the sha to the mock server too --- server/events/vcs/gitlab_client.go | 6 +++--- server/events/vcs/gitlab_client_test.go | 4 ++-- 2 files changed, 5 insertions(+), 5 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 } diff --git a/server/events/vcs/gitlab_client_test.go b/server/events/vcs/gitlab_client_test.go index 0ce23a9c64..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) @@ -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)