Example #1
0
// Teams returns a list of all team membership for the GitHub account.
func (c *client) Teams(u *model.User) ([]*model.Team, error) {
	client := c.newClientToken(u.Token)

	opts := new(github.ListOptions)
	opts.Page = 1

	var teams []*model.Team
	for opts.Page > 0 {
		list, resp, err := client.Organizations.List("", opts)
		if err != nil {
			return nil, err
		}
		teams = append(teams, convertTeamList(list)...)
		opts.Page = resp.NextPage
	}
	return teams, nil
}
Example #2
0
// GetOrgs is a helper function that returns a list of
// all orgs that a user belongs to.
func GetOrgs(client *github.Client) ([]github.Organization, error) {
	var orgs []github.Organization
	var opts = github.ListOptions{}
	opts.Page = 1

	for opts.Page > 0 {
		list, resp, err := client.Organizations.List("", &opts)
		if err != nil {
			return nil, err
		}
		orgs = append(orgs, list...)

		// increment the next page to retrieve
		opts.Page = resp.NextPage
	}
	return orgs, nil
}
Example #3
0
func pages(inner func(*github.ListOptions) (*github.Response, error)) (*github.Response, error) {

	options := github.ListOptions{}

	for {

		response, err := inner(&options)
		if err != nil {
			return response, err
		}

		if response.NextPage == 0 {
			return response, nil
		}

		options.Page = response.NextPage
	}

	return nil, nil
}