mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-27 12:21:03 +00:00
move regexp to package level variable, add check for email array
This commit is contained in:
parent
25b887c059
commit
79e0c7a84f
1 changed files with 12 additions and 3 deletions
|
@ -18,6 +18,11 @@ const (
|
||||||
DefaultURL = "https://bitbucket.org"
|
DefaultURL = "https://bitbucket.org"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// bitbucket returns commit author email only in format "John Doe <john.doe@example.com>"
|
||||||
|
emailRegexp = regexp.MustCompile("<(.*)>")
|
||||||
|
)
|
||||||
|
|
||||||
type Bitbucket struct {
|
type Bitbucket struct {
|
||||||
URL string
|
URL string
|
||||||
API 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.")
|
return nil, fmt.Errorf("Invalid Bitbucket post-commit Hook. Missing Repo or Commit data.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// bitbucket returns commit author email only in format "John Doe <john.doe@example.com>"
|
rawAuthor := hook.Commits[len(hook.Commits)-1].RawAuthor
|
||||||
regexp, _ := regexp.Compile("<(.*)>")
|
email := rawAuthor
|
||||||
email := regexp.FindStringSubmatch(hook.Commits[len(hook.Commits)-1].RawAuthor)[1]
|
match := emailRegexp.FindStringSubmatch(rawAuthor)
|
||||||
|
|
||||||
|
if len(match) > 0 {
|
||||||
|
email = match[1]
|
||||||
|
}
|
||||||
|
|
||||||
return &model.Hook{
|
return &model.Hook{
|
||||||
Owner: hook.Repo.Owner,
|
Owner: hook.Repo.Owner,
|
||||||
|
|
Loading…
Reference in a new issue