From 1531c349a086c40ab1e46d61fb02587f15469488 Mon Sep 17 00:00:00 2001 From: Edmond Date: Wed, 7 Jul 2021 00:15:49 +0800 Subject: [PATCH 1/8] add merged field to pull request struct --- scm/driver/github/pr.go | 1 + 1 file changed, 1 insertion(+) diff --git a/scm/driver/github/pr.go b/scm/driver/github/pr.go index 39c5d20e2..3f114aa7b 100644 --- a/scm/driver/github/pr.go +++ b/scm/driver/github/pr.go @@ -101,6 +101,7 @@ type pr struct { AvatarURL string `json:"avatar_url"` } } `json:"base"` + Merged bool `json:"merged"` MergedAt null.String `json:"merged_at"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` From 3f1f53e2bd5c485a7901d8d27ec552c40f59ca54 Mon Sep 17 00:00:00 2001 From: Edmond Date: Wed, 7 Jul 2021 00:24:03 +0800 Subject: [PATCH 2/8] use parsed merged field directly --- scm/driver/github/pr.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scm/driver/github/pr.go b/scm/driver/github/pr.go index 3f114aa7b..6439ae06c 100644 --- a/scm/driver/github/pr.go +++ b/scm/driver/github/pr.go @@ -155,7 +155,7 @@ func convertPullRequest(from *pr) *scm.PullRequest { Link: from.HTMLURL, Diff: from.DiffURL, Closed: from.State != "open", - Merged: from.MergedAt.String != "", + Merged: from.Merged, Head: scm.Reference{ Name: from.Head.Ref, Path: scm.ExpandRef(from.Head.Ref, "refs/heads"), From 3582ca23f38b6a2580d1f783c7ea97e1ede76a97 Mon Sep 17 00:00:00 2001 From: Edmond Date: Wed, 7 Jul 2021 00:25:16 +0800 Subject: [PATCH 3/8] set pr merge action if it is merged and closed --- scm/driver/github/webhook.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/scm/driver/github/webhook.go b/scm/driver/github/webhook.go index 4aa87f5c4..dd7200e2b 100644 --- a/scm/driver/github/webhook.go +++ b/scm/driver/github/webhook.go @@ -156,13 +156,10 @@ func (s *webhookService) parsePullRequestHook(data []byte) (scm.Webhook, error) case "edited": dst.Action = scm.ActionUpdate case "closed": - // TODO(bradrydzewski) github does not provide a merged action, - // but this is provided by gitlab and bitbucket. Is it possible - // to emulate the merge action? - - // if merged == true - // dst.Action = scm.ActionMerge - dst.Action = scm.ActionClose + if dst.Merged: + dst.Action = scm.ActionMerge + else: + dst.Action = scm.ActionClose case "reopened": dst.Action = scm.ActionReopen case "synchronize": From 4523e751a57dac5da59c7370f0ce455741bc1775 Mon Sep 17 00:00:00 2001 From: Edmond Date: Wed, 7 Jul 2021 00:30:14 +0800 Subject: [PATCH 4/8] fix typo --- scm/driver/github/webhook.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scm/driver/github/webhook.go b/scm/driver/github/webhook.go index dd7200e2b..ccbab373a 100644 --- a/scm/driver/github/webhook.go +++ b/scm/driver/github/webhook.go @@ -156,10 +156,11 @@ func (s *webhookService) parsePullRequestHook(data []byte) (scm.Webhook, error) case "edited": dst.Action = scm.ActionUpdate case "closed": - if dst.Merged: + if dst.Merged { dst.Action = scm.ActionMerge - else: + } else { dst.Action = scm.ActionClose + } case "reopened": dst.Action = scm.ActionReopen case "synchronize": From f2f8308d5c1457daa93f3c48cd3dd6e748a16139 Mon Sep 17 00:00:00 2001 From: Edmond Date: Wed, 7 Jul 2021 00:32:50 +0800 Subject: [PATCH 5/8] fix error --- scm/driver/github/webhook.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scm/driver/github/webhook.go b/scm/driver/github/webhook.go index ccbab373a..a473d9223 100644 --- a/scm/driver/github/webhook.go +++ b/scm/driver/github/webhook.go @@ -156,7 +156,7 @@ func (s *webhookService) parsePullRequestHook(data []byte) (scm.Webhook, error) case "edited": dst.Action = scm.ActionUpdate case "closed": - if dst.Merged { + if dst.PullRequest.Merged { dst.Action = scm.ActionMerge } else { dst.Action = scm.ActionClose From b4e8c67f4ac2d9de0550a8b47a2831992c2bd573 Mon Sep 17 00:00:00 2001 From: Edmond Date: Wed, 7 Jul 2021 00:58:50 +0800 Subject: [PATCH 6/8] set merged to true to fix test case --- scm/driver/github/testdata/pr.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scm/driver/github/testdata/pr.json b/scm/driver/github/testdata/pr.json index edcc02d7c..3a7e28906 100644 --- a/scm/driver/github/testdata/pr.json +++ b/scm/driver/github/testdata/pr.json @@ -371,7 +371,7 @@ "site_admin": false }, "merge_commit_sha": "e5bd3914e2e596debea16f433f57875b5b90bcd6", - "merged": false, + "merged": true, "mergeable": true, "merged_by": { "login": "octocat", @@ -398,4 +398,4 @@ "deletions": 3, "changed_files": 5, "maintainer_can_modify": true -} \ No newline at end of file +} From d737085bb5e97727f929c6f7f9369a4b16db8ec4 Mon Sep 17 00:00:00 2001 From: Edmond Date: Wed, 7 Jul 2021 01:06:31 +0800 Subject: [PATCH 7/8] add merged = true field to fix test case --- scm/driver/github/testdata/pulls.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scm/driver/github/testdata/pulls.json b/scm/driver/github/testdata/pulls.json index 611d7d71d..8eccca7ee 100644 --- a/scm/driver/github/testdata/pulls.json +++ b/scm/driver/github/testdata/pulls.json @@ -370,6 +370,7 @@ "received_events_url": "https://api.github.com/users/octocat/received_events", "type": "User", "site_admin": false - } + }, + "merged": true } -] \ No newline at end of file +] From f97ab81ab708cc179fa920546b5880c0af7765da Mon Sep 17 00:00:00 2001 From: Edmond Luo Date: Wed, 7 Jul 2021 01:41:19 +0800 Subject: [PATCH 8/8] revert change --- scm/driver/github/pr.go | 3 +-- scm/driver/github/testdata/pr.json | 4 ++-- scm/driver/github/testdata/pulls.json | 5 ++--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/scm/driver/github/pr.go b/scm/driver/github/pr.go index 6439ae06c..39c5d20e2 100644 --- a/scm/driver/github/pr.go +++ b/scm/driver/github/pr.go @@ -101,7 +101,6 @@ type pr struct { AvatarURL string `json:"avatar_url"` } } `json:"base"` - Merged bool `json:"merged"` MergedAt null.String `json:"merged_at"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` @@ -155,7 +154,7 @@ func convertPullRequest(from *pr) *scm.PullRequest { Link: from.HTMLURL, Diff: from.DiffURL, Closed: from.State != "open", - Merged: from.Merged, + Merged: from.MergedAt.String != "", Head: scm.Reference{ Name: from.Head.Ref, Path: scm.ExpandRef(from.Head.Ref, "refs/heads"), diff --git a/scm/driver/github/testdata/pr.json b/scm/driver/github/testdata/pr.json index 3a7e28906..edcc02d7c 100644 --- a/scm/driver/github/testdata/pr.json +++ b/scm/driver/github/testdata/pr.json @@ -371,7 +371,7 @@ "site_admin": false }, "merge_commit_sha": "e5bd3914e2e596debea16f433f57875b5b90bcd6", - "merged": true, + "merged": false, "mergeable": true, "merged_by": { "login": "octocat", @@ -398,4 +398,4 @@ "deletions": 3, "changed_files": 5, "maintainer_can_modify": true -} +} \ No newline at end of file diff --git a/scm/driver/github/testdata/pulls.json b/scm/driver/github/testdata/pulls.json index 8eccca7ee..611d7d71d 100644 --- a/scm/driver/github/testdata/pulls.json +++ b/scm/driver/github/testdata/pulls.json @@ -370,7 +370,6 @@ "received_events_url": "https://api.github.com/users/octocat/received_events", "type": "User", "site_admin": false - }, - "merged": true + } } -] +] \ No newline at end of file