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