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

Function RepoNetwork

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

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

Callers 1

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

Tested by

no test coverage detected