Merge pull request #1864 from bradrydzewski/master

populate github refspec
This commit is contained in:
Brad Rydzewski 2016-11-20 00:31:09 +01:00 committed by GitHub
commit 64847e2e4a
7 changed files with 40 additions and 7 deletions

View file

@ -152,7 +152,11 @@ func convertPullHook(from *internal.PullRequestHook) *model.Build {
Event: model.EventPull, Event: model.EventPull,
Commit: from.PullRequest.Dest.Commit.Hash, Commit: from.PullRequest.Dest.Commit.Hash,
Ref: fmt.Sprintf("refs/heads/%s", from.PullRequest.Dest.Branch.Name), Ref: fmt.Sprintf("refs/heads/%s", from.PullRequest.Dest.Branch.Name),
Remote: cloneLink(&from.PullRequest.Dest.Repo), Refspec: fmt.Sprintf("%s:%s",
from.PullRequest.Source.Branch.Name,
from.PullRequest.Dest.Branch.Name,
),
Remote: fmt.Sprintf("https://bitbucket.org/%s", from.PullRequest.Source.Repo.FullName),
Link: from.PullRequest.Links.Html.Href, Link: from.PullRequest.Links.Html.Href,
Branch: from.PullRequest.Dest.Branch.Name, Branch: from.PullRequest.Dest.Branch.Name,
Message: from.PullRequest.Desc, Message: from.PullRequest.Desc,

View file

@ -139,6 +139,8 @@ func Test_helper(t *testing.T) {
hook.PullRequest.Dest.Commit.Hash = "73f9c44d" hook.PullRequest.Dest.Commit.Hash = "73f9c44d"
hook.PullRequest.Dest.Branch.Name = "master" hook.PullRequest.Dest.Branch.Name = "master"
hook.PullRequest.Dest.Repo.Links.Html.Href = "https://bitbucket.org/foo/bar" hook.PullRequest.Dest.Repo.Links.Html.Href = "https://bitbucket.org/foo/bar"
hook.PullRequest.Source.Branch.Name = "change"
hook.PullRequest.Source.Repo.FullName = "baz/bar"
hook.PullRequest.Links.Html.Href = "https://bitbucket.org/foo/bar/pulls/5" hook.PullRequest.Links.Html.Href = "https://bitbucket.org/foo/bar/pulls/5"
hook.PullRequest.Desc = "updated README" hook.PullRequest.Desc = "updated README"
hook.PullRequest.Updated = time.Now() hook.PullRequest.Updated = time.Now()
@ -151,6 +153,8 @@ func Test_helper(t *testing.T) {
g.Assert(build.Branch).Equal(hook.PullRequest.Dest.Branch.Name) g.Assert(build.Branch).Equal(hook.PullRequest.Dest.Branch.Name)
g.Assert(build.Link).Equal(hook.PullRequest.Links.Html.Href) g.Assert(build.Link).Equal(hook.PullRequest.Links.Html.Href)
g.Assert(build.Ref).Equal("refs/heads/master") g.Assert(build.Ref).Equal("refs/heads/master")
g.Assert(build.Refspec).Equal("change:master")
g.Assert(build.Remote).Equal("https://bitbucket.org/baz/bar")
g.Assert(build.Message).Equal(hook.PullRequest.Desc) g.Assert(build.Message).Equal(hook.PullRequest.Desc)
g.Assert(build.Timestamp).Equal(hook.PullRequest.Updated.Unix()) g.Assert(build.Timestamp).Equal(hook.PullRequest.Updated.Unix())
}) })

View file

@ -28,6 +28,7 @@ const (
const ( const (
headRefs = "refs/pull/%d/head" // pull request unmerged headRefs = "refs/pull/%d/head" // pull request unmerged
mergeRefs = "refs/pull/%d/merge" // pull request merged with base 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 // convertStatus is a helper function used to convert a Drone status to a
@ -229,6 +230,11 @@ func convertPullHook(from *webhook, merge bool) *model.Build {
Author: from.PullRequest.User.Login, Author: from.PullRequest.User.Login,
Avatar: from.PullRequest.User.Avatar, Avatar: from.PullRequest.User.Avatar,
Title: from.PullRequest.Title, Title: from.PullRequest.Title,
Remote: from.PullRequest.Head.Repo.CloneURL,
Refspec: fmt.Sprintf(refspec,
from.PullRequest.Head.Ref,
from.PullRequest.Base.Ref,
),
} }
if merge { if merge {
build.Ref = fmt.Sprintf(mergeRefs, from.PullRequest.Number) build.Ref = fmt.Sprintf(mergeRefs, from.PullRequest.Number)

View file

@ -172,8 +172,10 @@ func Test_helper(t *testing.T) {
g.It("should convert a pull request from webhook", func() { g.It("should convert a pull request from webhook", func() {
from := &webhook{} from := &webhook{}
from.PullRequest.Head.Ref = "master" from.PullRequest.Base.Ref = "master"
from.PullRequest.Head.Ref = "changes"
from.PullRequest.Head.SHA = "f72fc19" from.PullRequest.Head.SHA = "f72fc19"
from.PullRequest.Head.Repo.CloneURL = "https://github.com/octocat/hello-world-fork"
from.PullRequest.HTMLURL = "https://github.com/octocat/hello-world/pulls/42" from.PullRequest.HTMLURL = "https://github.com/octocat/hello-world/pulls/42"
from.PullRequest.Number = 42 from.PullRequest.Number = 42
from.PullRequest.Title = "Updated README.md" from.PullRequest.Title = "Updated README.md"
@ -184,6 +186,8 @@ func Test_helper(t *testing.T) {
g.Assert(build.Event).Equal(model.EventPull) g.Assert(build.Event).Equal(model.EventPull)
g.Assert(build.Branch).Equal(from.PullRequest.Head.Ref) g.Assert(build.Branch).Equal(from.PullRequest.Head.Ref)
g.Assert(build.Ref).Equal("refs/pull/42/merge") g.Assert(build.Ref).Equal("refs/pull/42/merge")
g.Assert(build.Refspec).Equal("changes:master")
g.Assert(build.Remote).Equal("https://github.com/octocat/hello-world-fork")
g.Assert(build.Commit).Equal(from.PullRequest.Head.SHA) g.Assert(build.Commit).Equal(from.PullRequest.Head.SHA)
g.Assert(build.Message).Equal(from.PullRequest.Title) g.Assert(build.Message).Equal(from.PullRequest.Title)
g.Assert(build.Title).Equal(from.PullRequest.Title) g.Assert(build.Title).Equal(from.PullRequest.Title)

View file

@ -70,6 +70,11 @@ const HookPullRequest = `
"login": "baxterthehacker", "login": "baxterthehacker",
"avatar_url": "https://avatars.githubusercontent.com/u/6752317?v=3" "avatar_url": "https://avatars.githubusercontent.com/u/6752317?v=3"
}, },
"base": {
"label": "baxterthehacker:master",
"ref": "master",
"sha": "9353195a19e45482665306e466c832c46560532d"
},
"head": { "head": {
"label": "baxterthehacker:changes", "label": "baxterthehacker:changes",
"ref": "changes", "ref": "changes",

View file

@ -68,9 +68,16 @@ type webhook struct {
Avatar string `json:"avatar_url"` Avatar string `json:"avatar_url"`
} `json:"user"` } `json:"user"`
Base struct {
Ref string `json:"ref"`
} `json:"base"`
Head struct { Head struct {
SHA string SHA string `json:"sha"`
Ref string Ref string `json:"ref"`
Repo struct {
CloneURL string `json:"clone_url"`
} `json:"repo"`
} `json:"head"` } `json:"head"`
} `json:"pull_request"` } `json:"pull_request"`
} }

View file

@ -8,6 +8,9 @@ import (
// Constraints define constraints for container execution. // Constraints define constraints for container execution.
type Constraints struct { type Constraints struct {
Repo Constraint
Ref Constraint
Refspec Constraint
Platform Constraint Platform Constraint
Environment Constraint Environment Constraint
Event Constraint Event Constraint