MCPcopy Create free account
hub / github.com/cli/cli / listTemplateRepositories

Function listTemplateRepositories

pkg/cmd/repo/create/http.go:290–355  ·  view source on GitHub ↗
(client *http.Client, hostname, owner string)

Source from the content-addressed store, hash-verified

288}
289
290func listTemplateRepositories(client *http.Client, hostname, owner string) ([]api.Repository, error) {
291 ownerConnection := "repositoryOwner(login: $owner)"
292
293 variables := map[string]interface{}{
294 "perPage": githubv4.Int(100),
295 "owner": githubv4.String(owner),
296 }
297 inputs := []string{"$perPage:Int!", "$endCursor:String", "$owner:String!"}
298
299 type result struct {
300 RepositoryOwner struct {
301 Login string
302 Repositories struct {
303 Nodes []api.Repository
304 TotalCount int
305 PageInfo struct {
306 HasNextPage bool
307 EndCursor string
308 }
309 }
310 }
311 }
312
313 query := fmt.Sprintf(`query RepositoryList(%s) {
314 %s {
315 login
316 repositories(first: $perPage, after: $endCursor, ownerAffiliations: OWNER, orderBy: { field: PUSHED_AT, direction: DESC }) {
317 nodes{
318 id
319 name
320 isTemplate
321 defaultBranchRef {
322 name
323 }
324 }
325 totalCount
326 pageInfo{hasNextPage,endCursor}
327 }
328 }
329 }`, strings.Join(inputs, ","), ownerConnection)
330
331 apiClient := api.NewClientFromHTTP(client)
332 var templateRepositories []api.Repository
333 for {
334 var res result
335 err := apiClient.GraphQL(hostname, query, variables, &res)
336 if err != nil {
337 return nil, err
338 }
339
340 owner := res.RepositoryOwner
341
342 for _, repo := range owner.Repositories.Nodes {
343 if repo.IsTemplate {
344 templateRepositories = append(templateRepositories, repo)
345 }
346 }
347

Callers 1

interactiveRepoTemplateFunction · 0.85

Calls 4

NewClientFromHTTPFunction · 0.92
JoinMethod · 0.80
GraphQLMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected