mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-26 20:01:02 +00:00
Merge pull request #1908 from patrickjahns/feature/bitbucket_email_author_fixed
Feature/bitbucket email author fixed
This commit is contained in:
commit
a913750b67
3 changed files with 19 additions and 0 deletions
|
@ -2,6 +2,7 @@ package bitbucket
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -186,5 +187,20 @@ func convertPushHook(hook *internal.PushHook, change *internal.Change) *model.Bu
|
||||||
build.Event = model.EventPush
|
build.Event = model.EventPush
|
||||||
build.Ref = fmt.Sprintf("refs/heads/%s", change.New.Name)
|
build.Ref = fmt.Sprintf("refs/heads/%s", change.New.Name)
|
||||||
}
|
}
|
||||||
|
if len(change.New.Target.Author.Raw) != 0 {
|
||||||
|
build.Email = extractEmail(change.New.Target.Author.Raw)
|
||||||
|
}
|
||||||
return build
|
return build
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// regex for git author fields ("name <name@mail.tld>")
|
||||||
|
var reGitMail = regexp.MustCompile("<(.*)>")
|
||||||
|
|
||||||
|
// extracts the email from a git commit author string
|
||||||
|
func extractEmail(gitauthor string) (author string) {
|
||||||
|
matches := reGitMail.FindAllStringSubmatch(gitauthor,-1)
|
||||||
|
if len(matches) == 1 {
|
||||||
|
author = matches[0][1]
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
|
@ -166,6 +166,7 @@ func Test_helper(t *testing.T) {
|
||||||
change.New.Target.Links.Html.Href = "https://bitbucket.org/foo/bar/commits/73f9c44d"
|
change.New.Target.Links.Html.Href = "https://bitbucket.org/foo/bar/commits/73f9c44d"
|
||||||
change.New.Target.Message = "updated README"
|
change.New.Target.Message = "updated README"
|
||||||
change.New.Target.Date = time.Now()
|
change.New.Target.Date = time.Now()
|
||||||
|
change.New.Target.Author.Raw = "Test <test@domain.tld>"
|
||||||
|
|
||||||
hook := internal.PushHook{}
|
hook := internal.PushHook{}
|
||||||
hook.Actor.Login = "octocat"
|
hook.Actor.Login = "octocat"
|
||||||
|
@ -173,6 +174,7 @@ func Test_helper(t *testing.T) {
|
||||||
|
|
||||||
build := convertPushHook(&hook, &change)
|
build := convertPushHook(&hook, &change)
|
||||||
g.Assert(build.Event).Equal(model.EventPush)
|
g.Assert(build.Event).Equal(model.EventPush)
|
||||||
|
g.Assert(build.Email).Equal("test@domain.tld")
|
||||||
g.Assert(build.Author).Equal(hook.Actor.Login)
|
g.Assert(build.Author).Equal(hook.Actor.Login)
|
||||||
g.Assert(build.Avatar).Equal(hook.Actor.Links.Avatar.Href)
|
g.Assert(build.Avatar).Equal(hook.Actor.Links.Avatar.Href)
|
||||||
g.Assert(build.Commit).Equal(change.New.Target.Hash)
|
g.Assert(build.Commit).Equal(change.New.Target.Hash)
|
||||||
|
|
|
@ -33,6 +33,7 @@ const HookPush = `
|
||||||
"type": "commit",
|
"type": "commit",
|
||||||
"hash": "709d658dc5b6d6afcd46049c2f332ee3f515a67d",
|
"hash": "709d658dc5b6d6afcd46049c2f332ee3f515a67d",
|
||||||
"author": {
|
"author": {
|
||||||
|
"raw": "emmap1 <email@domain.tld>",
|
||||||
"username": "emmap1",
|
"username": "emmap1",
|
||||||
"links": {
|
"links": {
|
||||||
"avatar": {
|
"avatar": {
|
||||||
|
|
Loading…
Reference in a new issue