verified fix for github enterprise email issues
This commit is contained in:
parent
522310ecb8
commit
0987a9ad59
1 changed files with 10 additions and 5 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"
|
||||||
|
@ -36,17 +37,21 @@ func GetUserEmail(client *github.Client) (*github.User, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// else we should iterate through the list
|
|
||||||
for _, email := range emails {
|
for _, email := range emails {
|
||||||
if email.Primary == nil { // hack for github enterprise
|
|
||||||
user.Email = email.Email
|
|
||||||
return user, nil
|
|
||||||
}
|
|
||||||
if *email.Primary && *email.Verified {
|
if *email.Primary && *email.Verified {
|
||||||
user.Email = email.Email
|
user.Email = email.Email
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 {
|
||||||
|
user.Email = emails[0].Email
|
||||||
|
return user, nil
|
||||||
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("No verified Email address for GitHub account")
|
return nil, fmt.Errorf("No verified Email address for GitHub account")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue