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

Function listRepos

pkg/cmd/repo/list/http.go:32–116  ·  view source on GitHub ↗
(client *http.Client, hostname string, limit int, owner string, filter FilterOptions)

Source from the content-addressed store, hash-verified

30}
31
32func listRepos(client *http.Client, hostname string, limit int, owner string, filter FilterOptions) (*RepositoryList, error) {
33 if filter.Language != "" || filter.Archived || filter.NonArchived || len(filter.Topic) > 0 || filter.Visibility == "internal" {
34 return searchRepos(client, hostname, limit, owner, filter)
35 }
36
37 perPage := min(limit, 100)
38
39 variables := map[string]any{
40 "perPage": githubv4.Int(perPage),
41 }
42
43 if filter.Visibility != "" {
44 variables["privacy"] = githubv4.RepositoryPrivacy(strings.ToUpper(filter.Visibility))
45 }
46
47 if filter.Fork {
48 variables["fork"] = githubv4.Boolean(true)
49 } else if filter.Source {
50 variables["fork"] = githubv4.Boolean(false)
51 }
52
53 inputs := []string{"$perPage:Int!", "$endCursor:String", "$privacy:RepositoryPrivacy", "$fork:Boolean"}
54 var ownerConnection string
55 if owner == "" {
56 ownerConnection = "repositoryOwner: viewer"
57 } else {
58 ownerConnection = "repositoryOwner(login: $owner)"
59 variables["owner"] = githubv4.String(owner)
60 inputs = append(inputs, "$owner:String!")
61 }
62
63 type result struct {
64 RepositoryOwner struct {
65 Login string
66 Repositories struct {
67 Nodes []api.Repository
68 TotalCount int
69 PageInfo struct {
70 HasNextPage bool
71 EndCursor string
72 }
73 }
74 }
75 }
76
77 query := fmt.Sprintf(`query RepositoryList(%s) {
78 %s {
79 login
80 repositories(first: $perPage, after: $endCursor, privacy: $privacy, isFork: $fork, ownerAffiliations: OWNER, orderBy: { field: PUSHED_AT, direction: DESC }) {
81 nodes{%s}
82 totalCount
83 pageInfo{hasNextPage,endCursor}
84 }
85 }
86 }`, strings.Join(inputs, ","), ownerConnection, api.RepositoryGraphQL(filter.Fields))
87
88 apiClient := api.NewClientFromHTTP(client)
89 listResult := RepositoryList{}

Callers 2

listRunFunction · 0.85

Calls 6

RepositoryGraphQLFunction · 0.92
NewClientFromHTTPFunction · 0.92
searchReposFunction · 0.85
JoinMethod · 0.80
GraphQLMethod · 0.80
StringMethod · 0.65

Tested by 1