SuggestedReviewerActorsForRepo fetches potential reviewers for a repository. Unlike SuggestedReviewerActors, this doesn't require an existing PR - used for gh pr create. It combines results from two sources using a cascading quota system: - repository collaborators (base quota: 5) - organization tea
(client *Client, repo ghrepo.Interface, query string)
| 565 | // unfilled quota from the previous source. Results are deduplicated. |
| 566 | // Returns the candidates, a MoreResults count, and an error. |
| 567 | func SuggestedReviewerActorsForRepo(client *Client, repo ghrepo.Interface, query string) ([]ReviewerCandidate, int, error) { |
| 568 | type responseData struct { |
| 569 | Viewer struct { |
| 570 | Login string |
| 571 | } |
| 572 | Repository struct { |
| 573 | // HACK: There's no repo-level API to check Copilot reviewer eligibility, |
| 574 | // so we piggyback on an open PR's suggestedReviewerActors to detect |
| 575 | // whether Copilot is available as a reviewer for this repository. |
| 576 | PullRequests struct { |
| 577 | Nodes []struct { |
| 578 | SuggestedActors struct { |
| 579 | Nodes []struct { |
| 580 | Reviewer struct { |
| 581 | TypeName string `graphql:"__typename"` |
| 582 | Bot struct { |
| 583 | Login string |
| 584 | } `graphql:"... on Bot"` |
| 585 | } |
| 586 | } |
| 587 | } `graphql:"suggestedReviewerActors(first: 10)"` |
| 588 | } |
| 589 | } `graphql:"pullRequests(first: 1, states: [OPEN])"` |
| 590 | Owner struct { |
| 591 | TypeName string `graphql:"__typename"` |
| 592 | Organization struct { |
| 593 | Teams struct { |
| 594 | Nodes []struct { |
| 595 | Slug string |
| 596 | } |
| 597 | } `graphql:"teams(first: 10, query: $query)"` |
| 598 | TeamsTotalCount struct { |
| 599 | TotalCount int |
| 600 | } `graphql:"teamsTotalCount: teams(first: 0)"` |
| 601 | } `graphql:"... on Organization"` |
| 602 | } |
| 603 | Collaborators struct { |
| 604 | Nodes []struct { |
| 605 | Login string |
| 606 | Name string |
| 607 | } |
| 608 | } `graphql:"collaborators(first: 10, query: $query)"` |
| 609 | CollaboratorsTotalCount struct { |
| 610 | TotalCount int |
| 611 | } `graphql:"collaboratorsTotalCount: collaborators(first: 0)"` |
| 612 | } `graphql:"repository(owner: $owner, name: $name)"` |
| 613 | } |
| 614 | |
| 615 | variables := map[string]any{ |
| 616 | "query": githubv4.String(query), |
| 617 | "owner": githubv4.String(repo.RepoOwner()), |
| 618 | "name": githubv4.String(repo.RepoName()), |
| 619 | } |
| 620 | |
| 621 | var result responseData |
| 622 | err := client.Query(repo.RepoHost(), "SuggestedReviewerActorsForRepo", &result, variables) |
| 623 | if err != nil { |
| 624 | return nil, 0, err |