Skip to content

Commit

Permalink
fix: prevent commit status update in incorrect MR (#2636)
Browse files Browse the repository at this point in the history
* fix: prevent commit status in incorrect MR
  - closes #2484

* chore: update test 'TestGitlabClient_UpdateStatus'
  • Loading branch information
michelmzs authored Nov 4, 2022
1 parent 4cc5cf6 commit 479f2b7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions server/events/vcs/gitlab_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion server/events/vcs/gitlab_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 479f2b7

Please sign in to comment.