mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2026-04-15 01:41:56 +00:00
Add pull request closed event (#2684)
- [x] updates docs - [x] adjust UI - [x] show correct icon - [x] show correct link (to pr) - [x] add as option in secret edit - [x] parse webhook - [x] update tests - [x] github merged - [x] github closed - [x] gitea merged - [x] gitea closed - [x] bitbucket merged - [x] bitbucket closed - [x] gitlab merged - [x] gitlab closed closes #286
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -32,10 +32,12 @@ import (
|
||||
const (
|
||||
hookField = "payload"
|
||||
|
||||
actionOpen = "opened"
|
||||
actionSync = "synchronize"
|
||||
actionOpen = "opened"
|
||||
actionClose = "closed"
|
||||
actionSync = "synchronize"
|
||||
|
||||
stateOpen = "open"
|
||||
stateOpen = "open"
|
||||
stateClose = "closed"
|
||||
)
|
||||
|
||||
// parseHook parses a GitHub hook from an http.Request request and returns
|
||||
@@ -140,18 +142,19 @@ func parseDeployHook(hook *github.DeploymentEvent) (*model.Repo, *model.Pipeline
|
||||
}
|
||||
|
||||
// parsePullHook parses a pull request hook and returns the Repo and Pipeline
|
||||
// details. If the pull request is closed nil values are returned.
|
||||
// details.
|
||||
func parsePullHook(hook *github.PullRequestEvent, merge bool) (*github.PullRequest, *model.Repo, *model.Pipeline, error) {
|
||||
// only listen to new merge-requests and pushes to open ones
|
||||
if hook.GetAction() != actionOpen && hook.GetAction() != actionSync {
|
||||
return nil, nil, nil, nil
|
||||
}
|
||||
if hook.GetPullRequest().GetState() != stateOpen {
|
||||
if hook.GetAction() != actionOpen && hook.GetAction() != actionSync && hook.GetAction() != actionClose {
|
||||
return nil, nil, nil, nil
|
||||
}
|
||||
|
||||
event := model.EventPull
|
||||
if hook.GetPullRequest().GetState() == stateClose {
|
||||
event = model.EventPullClosed
|
||||
}
|
||||
|
||||
pipeline := &model.Pipeline{
|
||||
Event: model.EventPull,
|
||||
Event: event,
|
||||
Commit: hook.GetPullRequest().GetHead().GetSHA(),
|
||||
ForgeURL: hook.GetPullRequest().GetHTMLURL(),
|
||||
Ref: fmt.Sprintf(headRefs, hook.GetPullRequest().GetNumber()),
|
||||
|
||||
@@ -79,23 +79,7 @@ func Test_parser(t *testing.T) {
|
||||
})
|
||||
|
||||
g.Describe("given a pull request hook", func() {
|
||||
g.It("should skip when action is not open or sync", func() {
|
||||
req := testHookRequest([]byte(fixtures.HookPullRequestInvalidAction), hookPull)
|
||||
p, r, b, err := parseHook(req, false)
|
||||
g.Assert(r).IsNil()
|
||||
g.Assert(b).IsNil()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(p).IsNil()
|
||||
})
|
||||
g.It("should skip when state is not open", func() {
|
||||
req := testHookRequest([]byte(fixtures.HookPullRequestInvalidState), hookPull)
|
||||
p, r, b, err := parseHook(req, false)
|
||||
g.Assert(r).IsNil()
|
||||
g.Assert(b).IsNil()
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(p).IsNil()
|
||||
})
|
||||
g.It("should extract repository and pipeline details", func() {
|
||||
g.It("should handle a PR hook when PR got opened or pushed to", func() {
|
||||
req := testHookRequest([]byte(fixtures.HookPullRequest), hookPull)
|
||||
p, r, b, err := parseHook(req, false)
|
||||
g.Assert(err).IsNil()
|
||||
@@ -104,6 +88,24 @@ func Test_parser(t *testing.T) {
|
||||
g.Assert(p).IsNotNil()
|
||||
g.Assert(b.Event).Equal(model.EventPull)
|
||||
})
|
||||
g.It("should handle a PR closed hook when PR got closed", func() {
|
||||
req := testHookRequest([]byte(fixtures.HookPullRequestClosed), hookPull)
|
||||
p, r, b, err := parseHook(req, false)
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(r).IsNotNil()
|
||||
g.Assert(b).IsNotNil()
|
||||
g.Assert(p).IsNotNil()
|
||||
g.Assert(b.Event).Equal(model.EventPullClosed)
|
||||
})
|
||||
g.It("should handle a PR closed hook when PR got merged", func() {
|
||||
req := testHookRequest([]byte(fixtures.HookPullRequestMerged), hookPull)
|
||||
p, r, b, err := parseHook(req, false)
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(r).IsNotNil()
|
||||
g.Assert(b).IsNotNil()
|
||||
g.Assert(p).IsNotNil()
|
||||
g.Assert(b.Event).Equal(model.EventPullClosed)
|
||||
})
|
||||
})
|
||||
|
||||
g.Describe("given a deployment hook", func() {
|
||||
|
||||
Reference in New Issue
Block a user