MCPcopy Create free account
hub / github.com/cli/cli / RepoFindForks

Function RepoFindForks

api/queries_repo.go:697–742  ·  view source on GitHub ↗

RepoFindForks finds forks of the repo that are affiliated with the viewer

(client *Client, repo ghrepo.Interface, limit int)

Source from the content-addressed store, hash-verified

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

Callers 1

NewCreateContextFunction · 0.92

Calls 6

InitRepoHostnameFunction · 0.85
GraphQLMethod · 0.80
ViewerCanPushMethod · 0.80
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RepoHostMethod · 0.65

Tested by

no test coverage detected