Skip to content

Commit 9641d8e

Browse files
authored
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
1 parent 6fdd4b1 commit 9641d8e

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

server/events/vcs/gitlab_client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,13 +413,13 @@ func (g *GitlabClient) UpdateStatus(logger logging.SimpleLogging, repo models.Re
413413
return err
414414
}
415415
if mr.HeadPipeline != nil {
416-
logger.Info("Head pipeline found for merge request %d, source '%s'. pipelineID '%s'",
416+
logger.Info("Head pipeline found for merge request %d, source '%s'. pipelineID '%d'",
417417
pull.Num, mr.HeadPipeline.Source, mr.HeadPipeline.ID)
418418
pipelineID = gitlab.Ptr(mr.HeadPipeline.ID)
419419

420-
// let's check to see if the pipeline sha matches the head commit.
420+
// if these don't match then there has been a new commit so let's return
421421
if mr.HeadPipeline.SHA != pull.HeadCommit {
422-
logger.Err("Head pipeline SHA does not match pull head commit")
422+
return errors.Errorf("mr.HeadPipeline.SHA: '%s' does not match pull.HeadCommit '%s'", mr.HeadPipeline.SHA, pull.HeadCommit)
423423
}
424424
break
425425
}

server/events/vcs/gitlab_client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ func TestGitlabClient_UpdateStatus(t *testing.T) {
298298
testServer := httptest.NewServer(
299299
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
300300
switch r.RequestURI {
301-
case "/api/v4/projects/runatlantis%2Fatlantis/statuses/sha":
301+
case "/api/v4/projects/runatlantis%2Fatlantis/statuses/67cb91d3f6198189f433c045154a885784ba6977":
302302
gotRequest = true
303303

304304
body, err := io.ReadAll(r.Body)
@@ -337,7 +337,7 @@ func TestGitlabClient_UpdateStatus(t *testing.T) {
337337
models.PullRequest{
338338
Num: 1,
339339
BaseRepo: repo,
340-
HeadCommit: "sha",
340+
HeadCommit: "67cb91d3f6198189f433c045154a885784ba6977",
341341
HeadBranch: "test",
342342
}, c.status, "src", "description", "https://google.com")
343343
Ok(t, err)

0 commit comments

Comments
 (0)