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

Function RepoNetwork

api/queries_repo.go:476–571  ·  view source on GitHub ↗

RepoNetwork inspects the relationship between multiple GitHub repositories

(client *Client, repos []ghrepo.Interface)

Source from the content-addressed store, hash-verified

474
475// RepoNetwork inspects the relationship between multiple GitHub repositories
476func RepoNetwork(client *Client, repos []ghrepo.Interface) (RepoNetworkResult, error) {
477 var hostname string
478 if len(repos) > 0 {
479 hostname = repos[0].RepoHost()
480 }
481
482 queries := make([]string, 0, len(repos))
483 for i, repo := range repos {
484 queries = append(queries, fmt.Sprintf(`
485 repo_%03d: repository(owner: %q, name: %q) {
486 ...repo
487 parent {
488 ...repo
489 }
490 }
491 `, i, repo.RepoOwner(), repo.RepoName()))
492 }
493
494 // Since the query is constructed dynamically, we can't parse a response
495 // format using a static struct. Instead, hold the raw JSON data until we
496 // decide how to parse it manually.
497 graphqlResult := make(map[string]*json.RawMessage)
498 var result RepoNetworkResult
499
500 err := client.GraphQL(hostname, fmt.Sprintf(`
501 fragment repo on Repository {
502 id
503 databaseId
504 name
505 owner { login }
506 viewerPermission
507 defaultBranchRef {
508 name
509 }
510 isPrivate
511 }
512 query RepositoryNetwork {
513 viewer { login }
514 %s
515 }
516 `, strings.Join(queries, "")), nil, &graphqlResult)
517 var graphqlError GraphQLError
518 if errors.As(err, &graphqlError) {
519 // If the only errors are that certain repositories are not found,
520 // continue processing this response instead of returning an error
521 tolerated := true
522 for _, ge := range graphqlError.Errors {
523 if ge.Type != "NOT_FOUND" {
524 tolerated = false
525 }
526 }
527 if tolerated {
528 err = nil
529 }
530 }
531 if err != nil {
532 return result, err
533 }

Callers 3

resolveNetworkFunction · 0.92

Calls 7

RepoOwnerMethod · 0.95
RepoNameMethod · 0.95
InitRepoHostnameFunction · 0.85
GraphQLMethod · 0.80
JoinMethod · 0.80
RepoHostMethod · 0.65
ErrorfMethod · 0.65