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

Function RepoFindForks

api/queries_repo.go:696–741  ·  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

694
695// RepoFindForks finds forks of the repo that are affiliated with the viewer
696func 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
743type RepoMetadataResult struct {
744 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