Merge pull request #1795 from appleboy/feature/branch
Fix branch name for bitbucket server.
This commit is contained in:
commit
524fba6253
2 changed files with 33 additions and 11 deletions
|
@ -102,10 +102,13 @@ func convertRepoLite(from *internal.Repo) *model.RepoLite {
|
||||||
// convertPushHook is a helper function used to convert a Bitbucket push
|
// convertPushHook is a helper function used to convert a Bitbucket push
|
||||||
// hook to the Drone build struct holding commit information.
|
// hook to the Drone build struct holding commit information.
|
||||||
func convertPushHook(hook *internal.PostHook, baseURL string) *model.Build {
|
func convertPushHook(hook *internal.PostHook, baseURL string) *model.Build {
|
||||||
//get the ref parts to see if it's a tags or heads
|
branch := strings.TrimPrefix(
|
||||||
refParts := strings.Split(hook.RefChanges[0].RefID, "/")
|
strings.TrimPrefix(
|
||||||
name := refParts[2]
|
hook.RefChanges[0].RefID,
|
||||||
commitType := refParts[1]
|
"refs/heads/",
|
||||||
|
),
|
||||||
|
"refs/tags/",
|
||||||
|
)
|
||||||
|
|
||||||
//Ensuring the author label is not longer then 40 for the label of the commit author (default size in the db)
|
//Ensuring the author label is not longer then 40 for the label of the commit author (default size in the db)
|
||||||
authorLabel := hook.Changesets.Values[0].ToCommit.Author.Name
|
authorLabel := hook.Changesets.Values[0].ToCommit.Author.Name
|
||||||
|
@ -115,7 +118,7 @@ func convertPushHook(hook *internal.PostHook, baseURL string) *model.Build {
|
||||||
|
|
||||||
build := &model.Build{
|
build := &model.Build{
|
||||||
Commit: hook.RefChanges[0].ToHash, // TODO check for index value
|
Commit: hook.RefChanges[0].ToHash, // TODO check for index value
|
||||||
Branch: name,
|
Branch: branch,
|
||||||
Message: hook.Changesets.Values[0].ToCommit.Message, //TODO check for index Values
|
Message: hook.Changesets.Values[0].ToCommit.Message, //TODO check for index Values
|
||||||
Avatar: avatarLink(hook.Changesets.Values[0].ToCommit.Author.EmailAddress),
|
Avatar: avatarLink(hook.Changesets.Values[0].ToCommit.Author.EmailAddress),
|
||||||
Author: authorLabel,
|
Author: authorLabel,
|
||||||
|
@ -124,10 +127,9 @@ func convertPushHook(hook *internal.PostHook, baseURL string) *model.Build {
|
||||||
Ref: hook.RefChanges[0].RefID, // TODO check for index Values
|
Ref: hook.RefChanges[0].RefID, // TODO check for index Values
|
||||||
Link: fmt.Sprintf("%s/projects/%s/repos/%s/commits/%s", baseURL, hook.Repository.Project.Key, hook.Repository.Slug, hook.RefChanges[0].ToHash),
|
Link: fmt.Sprintf("%s/projects/%s/repos/%s/commits/%s", baseURL, hook.Repository.Project.Key, hook.Repository.Slug, hook.RefChanges[0].ToHash),
|
||||||
}
|
}
|
||||||
switch commitType {
|
if strings.HasPrefix(hook.RefChanges[0].RefID, "refs/tags/") {
|
||||||
case "tags":
|
|
||||||
build.Event = model.EventTag
|
build.Event = model.EventTag
|
||||||
default:
|
} else {
|
||||||
build.Event = model.EventPush
|
build.Event = model.EventPush
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,11 +69,31 @@ func Test_helper(t *testing.T) {
|
||||||
g.Assert(result.Token).Equal("foo")
|
g.Assert(result.Token).Equal("foo")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
g.It("branch should be empty", func() {
|
||||||
|
change := internal.PostHook{}
|
||||||
|
change.RefChanges = append(change.RefChanges, internal.RefChange{
|
||||||
|
RefID: "refs/heads/",
|
||||||
|
ToHash: "73f9c44d",
|
||||||
|
})
|
||||||
|
|
||||||
|
value := internal.Value{}
|
||||||
|
value.ToCommit.Author.Name = "John Doe, Appleboy, Mary, Janet E. Dawson and Ann S. Palmer"
|
||||||
|
value.ToCommit.Author.EmailAddress = "huh@huh.com"
|
||||||
|
value.ToCommit.Message = "message"
|
||||||
|
|
||||||
|
change.Changesets.Values = append(change.Changesets.Values, value)
|
||||||
|
|
||||||
|
change.Repository.Project.Key = "octocat"
|
||||||
|
change.Repository.Slug = "hello-world"
|
||||||
|
build := convertPushHook(&change, "http://base.com")
|
||||||
|
g.Assert(build.Branch).Equal("")
|
||||||
|
})
|
||||||
|
|
||||||
g.It("should convert push hook to build", func() {
|
g.It("should convert push hook to build", func() {
|
||||||
change := internal.PostHook{}
|
change := internal.PostHook{}
|
||||||
|
|
||||||
change.RefChanges = append(change.RefChanges, internal.RefChange{
|
change.RefChanges = append(change.RefChanges, internal.RefChange{
|
||||||
RefID: "refs/heads/master",
|
RefID: "refs/heads/release/some-feature",
|
||||||
ToHash: "73f9c44d",
|
ToHash: "73f9c44d",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -93,9 +113,9 @@ func Test_helper(t *testing.T) {
|
||||||
g.Assert(build.Author).Equal("John Doe, Appleboy, Mary, Janet E. Da...")
|
g.Assert(build.Author).Equal("John Doe, Appleboy, Mary, Janet E. Da...")
|
||||||
g.Assert(build.Avatar).Equal(avatarLink("huh@huh.com"))
|
g.Assert(build.Avatar).Equal(avatarLink("huh@huh.com"))
|
||||||
g.Assert(build.Commit).Equal("73f9c44d")
|
g.Assert(build.Commit).Equal("73f9c44d")
|
||||||
g.Assert(build.Branch).Equal("master")
|
g.Assert(build.Branch).Equal("release/some-feature")
|
||||||
g.Assert(build.Link).Equal("http://base.com/projects/octocat/repos/hello-world/commits/73f9c44d")
|
g.Assert(build.Link).Equal("http://base.com/projects/octocat/repos/hello-world/commits/73f9c44d")
|
||||||
g.Assert(build.Ref).Equal("refs/heads/master")
|
g.Assert(build.Ref).Equal("refs/heads/release/some-feature")
|
||||||
g.Assert(build.Message).Equal("message")
|
g.Assert(build.Message).Equal("message")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue