From abb815e9c3eb7e3c45f2eab6bc85d060af8f7d03 Mon Sep 17 00:00:00 2001 From: "Michel Z. Santello" Date: Wed, 2 Nov 2022 11:46:01 -0300 Subject: [PATCH 1/2] fix: prevent commit status in incorrect MR - closes https://github.com/runatlantis/atlantis/issues/2484 --- server/events/vcs/gitlab_client.go | 1 + 1 file changed, 1 insertion(+) diff --git a/server/events/vcs/gitlab_client.go b/server/events/vcs/gitlab_client.go index feeacc3573..26eb93f223 100644 --- a/server/events/vcs/gitlab_client.go +++ b/server/events/vcs/gitlab_client.go @@ -249,6 +249,7 @@ func (g *GitlabClient) UpdateStatus(repo models.Repo, pull models.PullRequest, s Context: gitlab.String(src), Description: gitlab.String(description), TargetURL: &url, + Ref: gitlab.String(pull.HeadBranch), }) return err } From a0e9134038048542ea13c18792014e67ccf4274e Mon Sep 17 00:00:00 2001 From: "Michel Z. Santello" Date: Wed, 2 Nov 2022 12:36:56 -0300 Subject: [PATCH 2/2] chore: update test 'TestGitlabClient_UpdateStatus' --- server/events/vcs/gitlab_client_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/events/vcs/gitlab_client_test.go b/server/events/vcs/gitlab_client_test.go index cd16009d0e..bbc6ace218 100644 --- a/server/events/vcs/gitlab_client_test.go +++ b/server/events/vcs/gitlab_client_test.go @@ -212,7 +212,7 @@ func TestGitlabClient_UpdateStatus(t *testing.T) { body, err := io.ReadAll(r.Body) Ok(t, err) - exp := fmt.Sprintf(`{"state":"%s","context":"src","target_url":"https://google.com","description":"description"}`, c.expState) + exp := fmt.Sprintf(`{"state":"%s","ref":"test","context":"src","target_url":"https://google.com","description":"description"}`, c.expState) Equals(t, exp, string(body)) defer r.Body.Close() // nolint: errcheck w.Write([]byte("{}")) // nolint: errcheck @@ -241,6 +241,7 @@ func TestGitlabClient_UpdateStatus(t *testing.T) { Num: 1, BaseRepo: repo, HeadCommit: "sha", + HeadBranch: "test", }, c.status, "src", "description", "https://google.com") Ok(t, err) Assert(t, gotRequest, "expected to get the request")