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

Function ListGists

pkg/cmd/gist/shared/shared.go:103–199  ·  view source on GitHub ↗
(client *http.Client, hostname string, limit int, filter *regexp.Regexp, includeContent bool, visibility string)

Source from the content-addressed store, hash-verified

101const maxPerPage = 100
102
103func ListGists(client *http.Client, hostname string, limit int, filter *regexp.Regexp, includeContent bool, visibility string) ([]Gist, error) {
104 type response struct {
105 Viewer struct {
106 Gists struct {
107 Nodes []struct {
108 Description string
109 Files []struct {
110 Name string
111 Text string `graphql:"text @include(if: $includeContent)"`
112 }
113 IsPublic bool
114 Name string
115 UpdatedAt time.Time
116 }
117 PageInfo struct {
118 HasNextPage bool
119 EndCursor string
120 }
121 } `graphql:"gists(first: $per_page, after: $endCursor, privacy: $visibility, orderBy: {field: CREATED_AT, direction: DESC})"`
122 }
123 }
124
125 perPage := limit
126 if perPage > maxPerPage {
127 perPage = maxPerPage
128 }
129
130 variables := map[string]interface{}{
131 "per_page": githubv4.Int(perPage),
132 "endCursor": (*githubv4.String)(nil),
133 "visibility": githubv4.GistPrivacy(strings.ToUpper(visibility)),
134 "includeContent": githubv4.Boolean(includeContent),
135 }
136
137 filterFunc := func(gist *Gist) bool {
138 if filter.MatchString(gist.Description) {
139 return true
140 }
141
142 for _, file := range gist.Files {
143 if filter.MatchString(file.Filename) {
144 return true
145 }
146
147 if includeContent && filter.MatchString(file.Content) {
148 return true
149 }
150 }
151
152 return false
153 }
154
155 gql := api.NewClientFromHTTP(client)
156
157 gists := []Gist{}
158pagination:
159 for {
160 var result response

Callers 2

listRunFunction · 0.92
PromptGistsFunction · 0.85

Calls 3

NewClientFromHTTPFunction · 0.92
QueryMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected