mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-04-26 21:44:44 +00:00
Merge pull request #603 from gregory90/fix-commit-author-bitbucket
Fix commit author email for bitbucket
This commit is contained in:
commit
273755d2a0
1 changed files with 15 additions and 1 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"regexp"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/drone/drone/shared/httputil"
|
"github.com/drone/drone/shared/httputil"
|
||||||
|
@ -17,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
|
||||||
|
@ -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.")
|
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{
|
return &model.Hook{
|
||||||
Owner: hook.Repo.Owner,
|
Owner: hook.Repo.Owner,
|
||||||
Repo: hook.Repo.Name,
|
Repo: hook.Repo.Name,
|
||||||
Sha: hook.Commits[len(hook.Commits)-1].Hash,
|
Sha: hook.Commits[len(hook.Commits)-1].Hash,
|
||||||
Branch: hook.Commits[len(hook.Commits)-1].Branch,
|
Branch: hook.Commits[len(hook.Commits)-1].Branch,
|
||||||
Author: hook.Commits[len(hook.Commits)-1].Author,
|
Author: email,
|
||||||
Timestamp: time.Now().UTC().String(),
|
Timestamp: time.Now().UTC().String(),
|
||||||
Message: hook.Commits[len(hook.Commits)-1].Message,
|
Message: hook.Commits[len(hook.Commits)-1].Message,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
Loading…
Reference in a new issue