RepoFindForks finds forks of the repo that are affiliated with the viewer
(client *Client, repo ghrepo.Interface, limit int)
| 691 | |
| 692 | // RepoFindForks finds forks of the repo that are affiliated with the viewer |
| 693 | func RepoFindForks(client *Client, repo ghrepo.Interface, limit int) ([]*Repository, error) { |
| 694 | result := struct { |
| 695 | Repository struct { |
| 696 | Forks struct { |
| 697 | Nodes []Repository |
| 698 | } |
| 699 | } |
| 700 | }{} |
| 701 | |
| 702 | variables := map[string]interface{}{ |
| 703 | "owner": repo.RepoOwner(), |
| 704 | "repo": repo.RepoName(), |
| 705 | "limit": limit, |
| 706 | } |
| 707 | |
| 708 | if err := client.GraphQL(repo.RepoHost(), ` |
| 709 | query RepositoryFindFork($owner: String!, $repo: String!, $limit: Int!) { |
| 710 | repository(owner: $owner, name: $repo) { |
| 711 | forks(first: $limit, affiliations: [OWNER, COLLABORATOR]) { |
| 712 | nodes { |
| 713 | id |
| 714 | name |
| 715 | owner { login } |
| 716 | url |
| 717 | viewerPermission |
| 718 | } |
| 719 | } |
| 720 | } |
| 721 | } |
| 722 | `, variables, &result); err != nil { |
| 723 | return nil, err |
| 724 | } |
| 725 | |
| 726 | var results []*Repository |
| 727 | for _, r := range result.Repository.Forks.Nodes { |
| 728 | // we check ViewerCanPush, even though we expect it to always be true per |
| 729 | // `affiliations` condition, to guard against versions of GitHub with a |
| 730 | // faulty `affiliations` implementation |
| 731 | if !r.ViewerCanPush() { |
| 732 | continue |
| 733 | } |
| 734 | results = append(results, InitRepoHostname(&r, repo.RepoHost())) |
| 735 | } |
| 736 | |
| 737 | return results, nil |
| 738 | } |
| 739 | |
| 740 | type RepoMetadataResult struct { |
| 741 | CurrentLogin string |
no test coverage detected