Skip to content

Commit 75d6480

Browse files
committed
support head and base ref and sha for prs
1 parent dee92a8 commit 75d6480

17 files changed

+112
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## Unreleased
88
### Added
9+
- Support Head and Base sha for GitHub pull request, from [@bradrydzewski](https://github.com/bradrydzewski).
910
- Support Before sha for Bitbucket, from [@jkdev81](https://github.com/jkdev81).
11+
- Support for creating GitHub deployment hooks, from [@bradrydzewski](https://github.com/bradrydzewski).
1012

1113
### Fixed
1214
- Fix issue getting a GitLab commit by ref, from [@bradrydzewski](https://github.com/bradrydzewski).

scm/driver/bitbucket/webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ func convertPushHook(src *pushHook) *scm.PushHook {
493493
change := src.Push.Changes[0]
494494
namespace, name := scm.Split(src.Repository.FullName)
495495
dst := &scm.PushHook{
496-
Ref: scm.ExpandRef(change.New.Name, "refs/heads/"),
496+
Ref: scm.ExpandRef(change.New.Name, "refs/heads/"),
497497
Before: change.Old.Target.Hash,
498498
Commit: scm.Commit{
499499
Sha: change.New.Target.Hash,

scm/driver/gitea/webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (s *webhookService) Parse(req *http.Request, fn scm.SecretFunc) (scm.Webhoo
6666
if signature == "" && secret == "" {
6767
return hook, scm.ErrSignatureInvalid
6868
}
69-
69+
7070
// test signature if header not set and secret is in payload
7171
if signature == "" && secret != "" && secret != key {
7272
return hook, scm.ErrSignatureInvalid

scm/driver/github/pr.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ func convertPullRequest(from *pr) *scm.PullRequest {
115115
Link: from.DiffURL,
116116
Closed: from.State != "open",
117117
Merged: from.MergedAt.String != "",
118+
Head: scm.Reference{
119+
Name: from.Head.Ref,
120+
Path: scm.ExpandRef(from.Head.Ref, "refs/heads"),
121+
Sha: from.Head.Sha,
122+
},
123+
Base: scm.Reference{
124+
Name: from.Base.Ref,
125+
Path: scm.ExpandRef(from.Base.Ref, "refs/heads"),
126+
Sha: from.Base.Sha,
127+
},
118128
Author: scm.User{
119129
Login: from.User.Login,
120130
Avatar: from.User.AvatarURL,

scm/driver/github/repo.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ func convertHookEvents(from scm.HookEvents) []string {
209209
events = append(events, "create")
210210
events = append(events, "delete")
211211
}
212+
if from.Deployment {
213+
events = append(events, "deployment")
214+
}
212215
return events
213216
}
214217

scm/driver/github/repo_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ func TestHookEvents(t *testing.T) {
432432
{
433433
in: scm.HookEvents{
434434
Branch: true,
435+
Deployment: true,
435436
Issue: true,
436437
IssueComment: true,
437438
PullRequest: true,
@@ -440,7 +441,7 @@ func TestHookEvents(t *testing.T) {
440441
ReviewComment: true,
441442
Tag: true,
442443
},
443-
out: []string{"push", "pull_request", "pull_request_review_comment", "issues", "issue_comment", "create", "delete"},
444+
out: []string{"push", "pull_request", "pull_request_review_comment", "issues", "issue_comment", "create", "delete", "deployment"},
444445
},
445446
}
446447
for i, test := range tests {

scm/driver/github/testdata/pr.json.golden

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@
1010
"Link": "https://github.com/octocat/Hello-World/pull/1347.diff",
1111
"Closed": false,
1212
"Merged": true,
13+
"Base": {
14+
"Sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e",
15+
"Path": "refs/heads/master",
16+
"Name": "master"
17+
},
18+
"Head": {
19+
"Sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e",
20+
"Path": "refs/heads/new-topic",
21+
"Name": "new-topic"
22+
},
1323
"Author": {
1424
"Login": "octocat",
1525
"Name": "",

scm/driver/github/testdata/pulls.json.golden

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@
1111
"Link": "https://github.com/octocat/Hello-World/pull/1347.diff",
1212
"Closed": false,
1313
"Merged": true,
14+
"Base": {
15+
"Sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e",
16+
"Path": "refs/heads/master",
17+
"Name": "master"
18+
},
19+
"Head": {
20+
"Sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e",
21+
"Path": "refs/heads/new-topic",
22+
"Name": "new-topic"
23+
},
1424
"Author": {
1525
"Login": "octocat",
1626
"Name": "",

scm/driver/github/testdata/webhooks/pr_closed.json.golden

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@
2525
"Link": "https://github.com/bradrydzewski/drone-test-go/pull/1.diff",
2626
"Closed": true,
2727
"Merged": false,
28+
"Base": {
29+
"Sha": "86378926c25f4b8310d3cc37f215eb6f25712850",
30+
"Path": "refs/heads/bradrydzewski-patch-1",
31+
"Name": "bradrydzewski-patch-1"
32+
},
33+
"Head": {
34+
"Sha": "d2b75aa7797ec26b088fa2dd527e9d2c052fcedd",
35+
"Path": "refs/heads/master",
36+
"Name": "master"
37+
},
2838
"Author": {
2939
"Login": "bradrydzewski",
3040
"Name": "",

scm/driver/github/testdata/webhooks/pr_edited.json.golden

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@
2525
"Link": "https://github.com/bradrydzewski/drone-test-go/pull/1.diff",
2626
"Closed": false,
2727
"Merged": false,
28+
"Base": {
29+
"Sha": "86378926c25f4b8310d3cc37f215eb6f25712850",
30+
"Path": "refs/heads/bradrydzewski-patch-1",
31+
"Name": "bradrydzewski-patch-1"
32+
},
33+
"Head": {
34+
"Sha": "d2b75aa7797ec26b088fa2dd527e9d2c052fcedd",
35+
"Path": "refs/heads/master",
36+
"Name": "master"
37+
},
2838
"Author": {
2939
"Login": "bradrydzewski",
3040
"Name": "",

0 commit comments

Comments
 (0)