From d813c927356577bcb03e1f1ce01ed63b46c9dacc Mon Sep 17 00:00:00 2001 From: Anbraten <6918444+anbraten@users.noreply.github.com> Date: Fri, 9 Feb 2024 16:06:10 +0100 Subject: [PATCH] Fix correctly handle gitlab pr closed events --- server/forge/gitlab/convert.go | 2 +- server/forge/gitlab/gitlab_test.go | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/server/forge/gitlab/convert.go b/server/forge/gitlab/convert.go index 6f08a6b61e..7c8f4995bd 100644 --- a/server/forge/gitlab/convert.go +++ b/server/forge/gitlab/convert.go @@ -112,7 +112,7 @@ func convertMergeRequestHook(hook *gitlab.MergeEvent, req *http.Request) (int, * } pipeline.Event = model.EventPull - if obj.State == "closed" { + if obj.State == "closed" || obj.State == "merged" { pipeline.Event = model.EventPullClosed } diff --git a/server/forge/gitlab/gitlab_test.go b/server/forge/gitlab/gitlab_test.go index 4b69ba7169..5197b9d012 100644 --- a/server/forge/gitlab/gitlab_test.go +++ b/server/forge/gitlab/gitlab_test.go @@ -156,6 +156,7 @@ func Test_GitLab(t *testing.T) { assert.Equal(t, "develop", hookRepo.Branch) assert.Equal(t, "refs/heads/main", pipeline.Ref) assert.Equal(t, []string{"cmd/cli/main.go"}, pipeline.ChangedFiles) + assert.Equal(t, model.EventPush, pipeline.Event) } }) }) @@ -178,6 +179,7 @@ func Test_GitLab(t *testing.T) { assert.Equal(t, "develop", hookRepo.Branch) assert.Equal(t, "refs/tags/v22", pipeline.Ref) assert.Len(t, pipeline.ChangedFiles, 0) + assert.Equal(t, model.EventTag, pipeline.Event) } }) }) @@ -201,6 +203,7 @@ func Test_GitLab(t *testing.T) { assert.Equal(t, "woodpecker", hookRepo.Name) assert.Equal(t, "Update client.go 🎉", pipeline.Title) assert.Len(t, pipeline.ChangedFiles, 0) // see L217 + assert.Equal(t, model.EventPull, pipeline.Event) } }) @@ -251,6 +254,7 @@ func Test_GitLab(t *testing.T) { assert.Equal(t, "woodpecker-test", hookRepo.Name) assert.Equal(t, "Add new file", pipeline.Title) assert.Len(t, pipeline.ChangedFiles, 0) // see L217 + assert.Equal(t, model.EventPullClosed, pipeline.Event) } }) @@ -271,6 +275,7 @@ func Test_GitLab(t *testing.T) { assert.Equal(t, "woodpecker-test", hookRepo.Name) assert.Equal(t, "Add new file", pipeline.Title) assert.Len(t, pipeline.ChangedFiles, 0) // see L217 + assert.Equal(t, model.EventPullClosed, pipeline.Event) } }) @@ -282,12 +287,13 @@ func Test_GitLab(t *testing.T) { ) req.Header = testdata.ReleaseHookHeaders - hookRepo, build, err := client.Hook(ctx, req) + hookRepo, pipeline, err := client.Hook(ctx, req) assert.NoError(t, err) - if assert.NotNil(t, hookRepo) && assert.NotNil(t, build) { - assert.Equal(t, "refs/tags/0.0.2", build.Ref) + if assert.NotNil(t, hookRepo) && assert.NotNil(t, pipeline) { + assert.Equal(t, "refs/tags/0.0.2", pipeline.Ref) assert.Equal(t, "ci", hookRepo.Name) - assert.Equal(t, "created release Awesome version 0.0.2", build.Message) + assert.Equal(t, "created release Awesome version 0.0.2", pipeline.Message) + assert.Equal(t, model.EventRelease, pipeline.Event) } }) })