add pagination support for /user/teams
This commit is contained in:
		
							parent
							
								
									056089bbcc
								
							
						
					
					
						commit
						3c19c364bd
					
				| 
						 | 
				
			
			@ -137,8 +137,19 @@ func (p *GitHubProvider) hasOrgAndTeam(accessToken string) (bool, error) {
 | 
			
		|||
		} `json:"organization"`
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	type teamsPage []struct {
 | 
			
		||||
		Name string `json:"name"`
 | 
			
		||||
		Slug string `json:"slug"`
 | 
			
		||||
		Org  struct {
 | 
			
		||||
			Login string `json:"login"`
 | 
			
		||||
		} `json:"organization"`
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	pn := 1
 | 
			
		||||
	for {
 | 
			
		||||
		params := url.Values{
 | 
			
		||||
			"limit": {"200"},
 | 
			
		||||
			"page":  {strconv.Itoa(pn)},
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		endpoint := &url.URL{
 | 
			
		||||
| 
						 | 
				
			
			@ -147,6 +158,7 @@ func (p *GitHubProvider) hasOrgAndTeam(accessToken string) (bool, error) {
 | 
			
		|||
			Path:     path.Join(p.ValidateURL.Path, "/user/teams"),
 | 
			
		||||
			RawQuery: params.Encode(),
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		req, _ := http.NewRequest("GET", endpoint.String(), nil)
 | 
			
		||||
		req.Header.Set("Accept", "application/vnd.github.v3+json")
 | 
			
		||||
		req.Header.Set("Authorization", fmt.Sprintf("token %s", accessToken))
 | 
			
		||||
| 
						 | 
				
			
			@ -165,9 +177,17 @@ func (p *GitHubProvider) hasOrgAndTeam(accessToken string) (bool, error) {
 | 
			
		|||
				"got %d from %q %s", resp.StatusCode, endpoint.String(), body)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	if err := json.Unmarshal(body, &teams); err != nil {
 | 
			
		||||
		var tp teamsPage
 | 
			
		||||
		if err := json.Unmarshal(body, &tp); err != nil {
 | 
			
		||||
			return false, fmt.Errorf("%s unmarshaling %s", err, body)
 | 
			
		||||
		}
 | 
			
		||||
		if len(tp) == 0 {
 | 
			
		||||
			break
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		teams = append(teams, tp...)
 | 
			
		||||
		pn++
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var hasOrg bool
 | 
			
		||||
	presentOrgs := make(map[string]bool)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue