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