mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-24 09:20:31 +00:00
handle github enterprise not supporting verified / primary emails
This commit is contained in:
parent
2cca926a06
commit
1ff56ef51c
1 changed files with 11 additions and 0 deletions
|
@ -6,6 +6,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/drone/drone/plugin/remote/github/oauth"
|
"github.com/drone/drone/plugin/remote/github/oauth"
|
||||||
"github.com/google/go-github/github"
|
"github.com/google/go-github/github"
|
||||||
|
@ -35,6 +36,16 @@ func GetUserEmail(client *github.Client) (*github.User, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WARNING, HACK
|
||||||
|
// for out-of-date github enterprise editions the primary
|
||||||
|
// and verified fields won't exist.
|
||||||
|
if !strings.HasPrefix(*user.HTMLURL, DefaultURL) && len(emails) != 0 && emails[0].Primary == nil {
|
||||||
|
user.Email = emails[0].Email
|
||||||
|
return user, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// else we should iterate through the list
|
||||||
for _, email := range emails {
|
for _, email := range emails {
|
||||||
if *email.Primary && *email.Verified {
|
if *email.Primary && *email.Verified {
|
||||||
user.Email = email.Email
|
user.Email = email.Email
|
||||||
|
|
Loading…
Reference in a new issue