MCPcopy Index your code
hub / github.com/google/go-github / ExampleTeamsService_ListTeams

Function ExampleTeamsService_ListTeams

github/examples_test.go:155–191  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

153}
154
155func ExampleTeamsService_ListTeams() {
156 // This example shows how to get a team ID corresponding to a given team name.
157
158 // Note that authentication is needed here as you are performing a lookup on
159 // an organization's administrative configuration, so you will need to modify
160 // the example to to provide authentication to github.NewClient(). See the
161 // following documentation for more information on how to authenticate with
162 // the client:
163 // https://pkg.go.dev/github.com/google/go-github/v88/github#hdr-Authentication
164 client, err := github.NewClient()
165 if err != nil {
166 log.Fatalf("Error creating GitHub client: %v", err)
167 }
168
169 teamName := "Developers team"
170 ctx := context.Background()
171 opts := &github.ListOptions{}
172
173 for {
174 teams, resp, err := client.Teams.ListTeams(ctx, "myOrganization", opts)
175 if err != nil {
176 log.Fatalf("error listing teams: %v", err)
177 }
178 for _, t := range teams {
179 if t.GetName() == teamName {
180 fmt.Printf("Team %q has ID %v\n", teamName, t.GetID())
181 return
182 }
183 }
184 if resp.NextPage == 0 {
185 break
186 }
187 opts.Page = resp.NextPage
188 }
189
190 fmt.Printf("Team %q was not found\n", teamName)
191}
192
193func ExampleUsersService_ListUserSocialAccounts() {
194 client, err := github.NewClient()

Callers

nothing calls this directly

Calls 4

NewClientFunction · 0.92
ListTeamsMethod · 0.45
GetNameMethod · 0.45
GetIDMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…