populate github refspec
This commit is contained in:
parent
eee4fd1fd2
commit
dc0fdbc221
5 changed files with 22 additions and 3 deletions
|
@ -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,10 @@ 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,
|
||||||
|
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)
|
||||||
|
|
|
@ -172,7 +172,8 @@ 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.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
|
||||||
|
@ -184,6 +185,7 @@ 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.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)
|
||||||
|
|
|
@ -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",
|
||||||
|
|
|
@ -68,9 +68,13 @@ 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"`
|
||||||
} `json:"head"`
|
} `json:"head"`
|
||||||
} `json:"pull_request"`
|
} `json:"pull_request"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue