github: better debug output for org/team validation
This commit is contained in:
parent
1e48d89e00
commit
c1bf1ad167
@ -66,7 +66,7 @@ func (p *GitHubProvider) hasOrg(accessToken string) (bool, error) {
|
||||
|
||||
endpoint := "https://api.github.com/user/orgs?" + params.Encode()
|
||||
req, _ := http.NewRequest("GET", endpoint, nil)
|
||||
req.Header.Set("Accept", "application/vnd.github.moondragon+json")
|
||||
req.Header.Set("Accept", "application/vnd.github.v3+json")
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
@ -85,11 +85,16 @@ func (p *GitHubProvider) hasOrg(accessToken string) (bool, error) {
|
||||
return false, err
|
||||
}
|
||||
|
||||
var presentOrgs []string
|
||||
for _, org := range orgs {
|
||||
if p.Org == org.Login {
|
||||
log.Printf("Found Github Organization: %q", org.Login)
|
||||
return true, nil
|
||||
}
|
||||
presentOrgs = append(presentOrgs, org.Login)
|
||||
}
|
||||
|
||||
log.Printf("Missing Organization:%q in %v", p.Org, presentOrgs)
|
||||
return false, nil
|
||||
}
|
||||
|
||||
@ -111,7 +116,7 @@ func (p *GitHubProvider) hasOrgAndTeam(accessToken string) (bool, error) {
|
||||
|
||||
endpoint := "https://api.github.com/user/teams?" + params.Encode()
|
||||
req, _ := http.NewRequest("GET", endpoint, nil)
|
||||
req.Header.Set("Accept", "application/vnd.github.moondragon+json")
|
||||
req.Header.Set("Accept", "application/vnd.github.v3+json")
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
@ -130,13 +135,29 @@ func (p *GitHubProvider) hasOrgAndTeam(accessToken string) (bool, error) {
|
||||
return false, fmt.Errorf("%s unmarshaling %s", err, body)
|
||||
}
|
||||
|
||||
var hasOrg bool
|
||||
presentOrgs := make(map[string]bool)
|
||||
var presentTeams []string
|
||||
for _, team := range teams {
|
||||
presentOrgs[team.Org.Login] = true
|
||||
if p.Org == team.Org.Login {
|
||||
if p.Team == "" || p.Team == team.Slug {
|
||||
hasOrg = true
|
||||
if p.Team == team.Slug {
|
||||
log.Printf("Found Github Organization:%q Team:%q (Name:%q)", team.Org.Login, team.Slug, team.Name)
|
||||
return true, nil
|
||||
}
|
||||
presentTeams = append(presentTeams, team.Slug)
|
||||
}
|
||||
}
|
||||
if hasOrg {
|
||||
log.Printf("Missing Team:%q from Org:%q in teams: %v", p.Team, p.Org, presentTeams)
|
||||
} else {
|
||||
var allOrgs []string
|
||||
for org, _ := range presentOrgs {
|
||||
allOrgs = append(allOrgs, org)
|
||||
}
|
||||
log.Printf("Missing Organization:%q in %#v", p.Org, allOrgs)
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user