Skip to content

Commit

Permalink
fix: err if gitlab shas dont match (#5)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
fitz7 authored Mar 11, 2024
1 parent 6fdd4b1 commit 9641d8e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions server/events/vcs/gitlab_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions server/events/vcs/gitlab_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9641d8e

Please sign in to comment.