@@ -2,7 +2,6 @@ package providers
22
33import (
44 "encoding/json"
5− "errors"
65 "fmt"
76 "io/ioutil"
87 "log"
@@ -66,7 +65,7 @@ func (p *GitHubProvider) hasOrg(accessToken string) (bool, error) {
6665
6766 endpoint := "https://api.github.com/user/orgs?" + params.Encode()
6867 req, _ := http.NewRequest("GET", endpoint, nil)
69− req.Header.Set("Accept", "application/vnd.github.moondragon+json")
68+ req.Header.Set("Accept", "application/vnd.github.v3+json")
7069 resp, err := http.DefaultClient.Do(req)
7170 if err != nil {
7271 return false, err
@@ -85,11 +84,16 @@ func (p *GitHubProvider) hasOrg(accessToken string) (bool, error) {
8584 return false, err
8685 }
8786
87+ var presentOrgs []string
8888 for _, org := range orgs {
8989 if p.Org == org.Login {
90+ log.Printf("Found Github Organization: %q", org.Login)
9091 return true, nil
9192 }
93+ presentOrgs = append(presentOrgs, org.Login)
9294 }
95+
96+ log.Printf("Missing Organization:%q in %v", p.Org, presentOrgs)
9397 return false, nil
9498}
9599
@@ -111,7 +115,7 @@ func (p *GitHubProvider) hasOrgAndTeam(accessToken string) (bool, error) {
111115
112116 endpoint := "https://api.github.com/user/teams?" + params.Encode()
113117 req, _ := http.NewRequest("GET", endpoint, nil)
114− req.Header.Set("Accept", "application/vnd.github.moondragon+json")
118+ req.Header.Set("Accept", "application/vnd.github.v3+json")
115119 resp, err := http.DefaultClient.Do(req)
116120 if err != nil {
117121 return false, err
@@ -130,12 +134,28 @@ func (p *GitHubProvider) hasOrgAndTeam(accessToken string) (bool, error) {
130134 return false, fmt.Errorf("%s unmarshaling %s", err, body)
131135 }
132136
137+ var hasOrg bool
138+ presentOrgs := make(map[string]bool)
139+ var presentTeams []string
133140 for _, team := range teams {
141+ presentOrgs[team.Org.Login] = true
134142 if p.Org == team.Org.Login {
135− if p.Team == "" || p.Team == team.Slug {
143+ hasOrg = true
144+ if p.Team == team.Slug {
145+ log.Printf("Found Github Organization:%q Team:%q (Name:%q)", team.Org.Login, team.Slug, team.Name)
136146 return true, nil
137147 }
148+ presentTeams = append(presentTeams, team.Slug)
149+ }
150+ }
151+ if hasOrg {
152+ log.Printf("Missing Team:%q from Org:%q in teams: %v", p.Team, p.Org, presentTeams)
153+ } else {
154+ var allOrgs []string
155+ for org, _ := range presentOrgs {
156+ allOrgs = append(allOrgs, org)
138157 }
158+ log.Printf("Missing Organization:%q in %#v", p.Org, allOrgs)
139159 }
140160 return false, nil
141161}
@@ -190,5 +210,5 @@ func (p *GitHubProvider) GetEmailAddress(s *SessionState) (string, error) {
190210 }
191211 }
192212
193− return "", errors.New("no email address found")
213+ return "", nil
194214}