diff --git a/remote/github/convert.go b/remote/github/convert.go index 0597b33d0..45db4078b 100644 --- a/remote/github/convert.go +++ b/remote/github/convert.go @@ -28,6 +28,7 @@ const ( const ( headRefs = "refs/pull/%d/head" // pull request unmerged mergeRefs = "refs/pull/%d/merge" // pull request merged with base + refspec = "%s:%s" ) // convertStatus is a helper function used to convert a Drone status to a @@ -229,6 +230,10 @@ func convertPullHook(from *webhook, merge bool) *model.Build { Author: from.PullRequest.User.Login, Avatar: from.PullRequest.User.Avatar, Title: from.PullRequest.Title, + Refspec: fmt.Sprintf(refspec, + from.PullRequest.Head.Ref, + from.PullRequest.Base.Ref, + ), } if merge { build.Ref = fmt.Sprintf(mergeRefs, from.PullRequest.Number) diff --git a/remote/github/convert_test.go b/remote/github/convert_test.go index 7cb1cdc0d..9c67c09c5 100644 --- a/remote/github/convert_test.go +++ b/remote/github/convert_test.go @@ -172,7 +172,8 @@ func Test_helper(t *testing.T) { g.It("should convert a pull request from webhook", func() { from := &webhook{} - from.PullRequest.Head.Ref = "master" + from.PullRequest.Base.Ref = "master" + from.PullRequest.Head.Ref = "changes" from.PullRequest.Head.SHA = "f72fc19" from.PullRequest.HTMLURL = "https://github.com/octocat/hello-world/pulls/42" from.PullRequest.Number = 42 @@ -184,6 +185,7 @@ func Test_helper(t *testing.T) { g.Assert(build.Event).Equal(model.EventPull) g.Assert(build.Branch).Equal(from.PullRequest.Head.Ref) g.Assert(build.Ref).Equal("refs/pull/42/merge") + g.Assert(build.Refspec).Equal("changes:master") g.Assert(build.Commit).Equal(from.PullRequest.Head.SHA) g.Assert(build.Message).Equal(from.PullRequest.Title) g.Assert(build.Title).Equal(from.PullRequest.Title) diff --git a/remote/github/fixtures/hooks.go b/remote/github/fixtures/hooks.go index a2929aaf7..f8dbf317e 100644 --- a/remote/github/fixtures/hooks.go +++ b/remote/github/fixtures/hooks.go @@ -70,6 +70,11 @@ const HookPullRequest = ` "login": "baxterthehacker", "avatar_url": "https://avatars.githubusercontent.com/u/6752317?v=3" }, + "base": { + "label": "baxterthehacker:master", + "ref": "master", + "sha": "9353195a19e45482665306e466c832c46560532d" + }, "head": { "label": "baxterthehacker:changes", "ref": "changes", diff --git a/remote/github/types.go b/remote/github/types.go index 485a0e31f..6285cdc41 100644 --- a/remote/github/types.go +++ b/remote/github/types.go @@ -68,9 +68,13 @@ type webhook struct { Avatar string `json:"avatar_url"` } `json:"user"` + Base struct { + Ref string `json:"ref"` + } `json:"base"` + Head struct { - SHA string - Ref string + SHA string `json:"sha"` + Ref string `json:"ref"` } `json:"head"` } `json:"pull_request"` } diff --git a/yaml/constraint.go b/yaml/constraint.go index 9c71fc2b6..acf2f0600 100644 --- a/yaml/constraint.go +++ b/yaml/constraint.go @@ -8,6 +8,9 @@ import ( // Constraints define constraints for container execution. type Constraints struct { + Repo Constraint + Ref Constraint + Refspec Constraint Platform Constraint Environment Constraint Event Constraint