diff --git a/plugin/remote/bitbucket/bitbucket.go b/plugin/remote/bitbucket/bitbucket.go index a80a062ac..534c22f1a 100644 --- a/plugin/remote/bitbucket/bitbucket.go +++ b/plugin/remote/bitbucket/bitbucket.go @@ -4,6 +4,7 @@ import ( "fmt" "net/http" "net/url" + "regexp" "time" "github.com/drone/drone/shared/httputil" @@ -17,6 +18,11 @@ const ( DefaultURL = "https://bitbucket.org" ) +var ( + // bitbucket returns commit author email only in format "John Doe " + emailRegexp = regexp.MustCompile("<(.*)>") +) + type Bitbucket struct { URL string API string @@ -246,12 +252,20 @@ func (r *Bitbucket) ParseHook(req *http.Request) (*model.Hook, error) { return nil, fmt.Errorf("Invalid Bitbucket post-commit Hook. Missing Repo or Commit data.") } + rawAuthor := hook.Commits[len(hook.Commits)-1].RawAuthor + email := rawAuthor + match := emailRegexp.FindStringSubmatch(rawAuthor) + + if len(match) > 0 { + email = match[1] + } + return &model.Hook{ Owner: hook.Repo.Owner, Repo: hook.Repo.Name, Sha: hook.Commits[len(hook.Commits)-1].Hash, Branch: hook.Commits[len(hook.Commits)-1].Branch, - Author: hook.Commits[len(hook.Commits)-1].Author, + Author: email, Timestamp: time.Now().UTC().String(), Message: hook.Commits[len(hook.Commits)-1].Message, }, nil