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

Function RepoNetwork

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

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

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