(client *http.Client, hostname string, limit int, owner string, filter FilterOptions)
| 119 | } |
| 120 | |
| 121 | func searchRepos(client *http.Client, hostname string, limit int, owner string, filter FilterOptions) (*RepositoryList, error) { |
| 122 | type result struct { |
| 123 | Search struct { |
| 124 | RepositoryCount int |
| 125 | Nodes []api.Repository |
| 126 | PageInfo struct { |
| 127 | HasNextPage bool |
| 128 | EndCursor string |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | query := fmt.Sprintf(`query RepositoryListSearch($query:String!,$perPage:Int!,$endCursor:String) { |
| 134 | search(type: REPOSITORY, query: $query, first: $perPage, after: $endCursor) { |
| 135 | repositoryCount |
| 136 | nodes{...on Repository{%s}} |
| 137 | pageInfo{hasNextPage,endCursor} |
| 138 | } |
| 139 | }`, api.RepositoryGraphQL(filter.Fields)) |
| 140 | |
| 141 | perPage := limit |
| 142 | if perPage > 100 { |
| 143 | perPage = 100 |
| 144 | } |
| 145 | |
| 146 | variables := map[string]interface{}{ |
| 147 | "query": githubv4.String(searchQuery(owner, filter)), |
| 148 | "perPage": githubv4.Int(perPage), |
| 149 | } |
| 150 | |
| 151 | apiClient := api.NewClientFromHTTP(client) |
| 152 | listResult := RepositoryList{FromSearch: true} |
| 153 | pagination: |
| 154 | for { |
| 155 | var result result |
| 156 | err := apiClient.GraphQL(hostname, query, variables, &result) |
| 157 | if err != nil { |
| 158 | return nil, err |
| 159 | } |
| 160 | |
| 161 | listResult.TotalCount = result.Search.RepositoryCount |
| 162 | for _, repo := range result.Search.Nodes { |
| 163 | if listResult.Owner == "" && repo.NameWithOwner != "" { |
| 164 | idx := strings.IndexRune(repo.NameWithOwner, '/') |
| 165 | listResult.Owner = repo.NameWithOwner[:idx] |
| 166 | } |
| 167 | listResult.Repositories = append(listResult.Repositories, repo) |
| 168 | if len(listResult.Repositories) >= limit { |
| 169 | break pagination |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | if !result.Search.PageInfo.HasNextPage { |
| 174 | break |
| 175 | } |
| 176 | variables["endCursor"] = githubv4.String(result.Search.PageInfo.EndCursor) |
| 177 | } |
| 178 |
no test coverage detected