mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-23 18:31:00 +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"
|
||||
)
|
||||
|
||||
var (
|
||||
// bitbucket returns commit author email only in format "John Doe <john.doe@example.com>"
|
||||
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 <john.doe@example.com>"
|
||||
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,
|
||||
|
|
Loading…
Reference in a new issue