MCPcopy Index your code
hub / github.com/cli/cli / RepoFindForks

Function RepoFindForks

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

686
687// RepoFindForks finds forks of the repo that are affiliated with the viewer
688func 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
735type RepoMetadataResult struct {
736 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