(client *http.Client, hostname string, limit int, filter *regexp.Regexp, includeContent bool, visibility string)
| 101 | const maxPerPage = 100 |
| 102 | |
| 103 | func 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 := min(limit, maxPerPage) |
| 126 | |
| 127 | variables := map[string]any{ |
| 128 | "per_page": githubv4.Int(perPage), |
| 129 | "endCursor": (*githubv4.String)(nil), |
| 130 | "visibility": githubv4.GistPrivacy(strings.ToUpper(visibility)), |
| 131 | "includeContent": githubv4.Boolean(includeContent), |
| 132 | } |
| 133 | |
| 134 | filterFunc := func(gist *Gist) bool { |
| 135 | if filter.MatchString(gist.Description) { |
| 136 | return true |
| 137 | } |
| 138 | |
| 139 | for _, file := range gist.Files { |
| 140 | if filter.MatchString(file.Filename) { |
| 141 | return true |
| 142 | } |
| 143 | |
| 144 | if includeContent && filter.MatchString(file.Content) { |
| 145 | return true |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | return false |
| 150 | } |
| 151 | |
| 152 | gql := api.NewClientFromHTTP(client) |
| 153 | |
| 154 | gists := []Gist{} |
| 155 | pagination: |
| 156 | for { |
| 157 | var result response |
| 158 | err := gql.Query(hostname, "GistList", &result, variables) |
| 159 | if err != nil { |
| 160 | return nil, err |
no test coverage detected