Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix correctly handle gitlab pr closed events #3362

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/forge/gitlab/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
14 changes: 10 additions & 4 deletions server/forge/gitlab/gitlab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
})
Expand All @@ -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)
}
})
})
Expand All @@ -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)
}
})

Expand Down Expand Up @@ -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)
}
})

Expand All @@ -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)
}
})

Expand All @@ -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)
}
})
})
Expand Down