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

Function FetchRepository

api/queries_repo.go:286–316  ·  view source on GitHub ↗
(client *Client, repo ghrepo.Interface, fields []string)

Source from the content-addressed store, hash-verified

284}
285
286func FetchRepository(client *Client, repo ghrepo.Interface, fields []string) (*Repository, error) {
287 query := fmt.Sprintf(`query RepositoryInfo($owner: String!, $name: String!) {
288 repository(owner: $owner, name: $name) {%s}
289 }`, RepositoryGraphQL(fields))
290
291 variables := map[string]any{
292 "owner": repo.RepoOwner(),
293 "name": repo.RepoName(),
294 }
295
296 var result struct {
297 Repository *Repository
298 }
299 if err := client.GraphQL(repo.RepoHost(), query, variables, &result); err != nil {
300 return nil, err
301 }
302 // The GraphQL API should have returned an error in case of a missing repository, but this isn't
303 // guaranteed to happen when an authentication token with insufficient permissions is being used.
304 if result.Repository == nil {
305 return nil, GraphQLError{
306 GraphQLError: &ghAPI.GraphQLError{
307 Errors: []ghAPI.GraphQLErrorItem{{
308 Type: "NOT_FOUND",
309 Message: fmt.Sprintf("Could not resolve to a Repository with the name '%s/%s'.", repo.RepoOwner(), repo.RepoName()),
310 }},
311 },
312 }
313 }
314
315 return InitRepoHostname(result.Repository, repo.RepoHost()), nil
316}
317
318// IssueRepoInfo fetches only the repository fields needed for issue operations such as
319// issue creation and transfer, avoiding fields like defaultBranchRef that require additional

Callers 4

viewRunFunction · 0.92
archiveRunFunction · 0.92
unarchiveRunFunction · 0.92
editRunFunction · 0.92

Calls 6

RepositoryGraphQLFunction · 0.85
InitRepoHostnameFunction · 0.85
GraphQLMethod · 0.80
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RepoHostMethod · 0.65

Tested by

no test coverage detected