From 25b887c059ae5b145f90cb17f1f04d37b66324e6 Mon Sep 17 00:00:00 2001 From: Grzegorz Graczyk Date: Tue, 21 Oct 2014 19:09:14 +0200 Subject: [PATCH 1/2] get commit author email address from raw_author instead of author field for bitbucket --- plugin/remote/bitbucket/bitbucket.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugin/remote/bitbucket/bitbucket.go b/plugin/remote/bitbucket/bitbucket.go index a80a062a..0100b7d6 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" @@ -246,12 +247,16 @@ func (r *Bitbucket) ParseHook(req *http.Request) (*model.Hook, error) { return nil, fmt.Errorf("Invalid Bitbucket post-commit Hook. Missing Repo or Commit data.") } + // bitbucket returns commit author email only in format "John Doe " + regexp, _ := regexp.Compile("<(.*)>") + email := regexp.FindStringSubmatch(hook.Commits[len(hook.Commits)-1].RawAuthor)[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 From 79e0c7a84f0190ce389ab1c32a6982ded5d48eb3 Mon Sep 17 00:00:00 2001 From: Grzegorz Graczyk Date: Wed, 22 Oct 2014 09:37:04 +0200 Subject: [PATCH 2/2] move regexp to package level variable, add check for email array --- plugin/remote/bitbucket/bitbucket.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/plugin/remote/bitbucket/bitbucket.go b/plugin/remote/bitbucket/bitbucket.go index 0100b7d6..534c22f1 100644 --- a/plugin/remote/bitbucket/bitbucket.go +++ b/plugin/remote/bitbucket/bitbucket.go @@ -18,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 @@ -247,9 +252,13 @@ func (r *Bitbucket) ParseHook(req *http.Request) (*model.Hook, error) { return nil, fmt.Errorf("Invalid Bitbucket post-commit Hook. Missing Repo or Commit data.") } - // bitbucket returns commit author email only in format "John Doe " - regexp, _ := regexp.Compile("<(.*)>") - email := regexp.FindStringSubmatch(hook.Commits[len(hook.Commits)-1].RawAuthor)[1] + 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,