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

Function RepoFindForks

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

691
692// RepoFindForks finds forks of the repo that are affiliated with the viewer
693func 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
740type RepoMetadataResult struct {
741 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