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