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