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

Function FetchRepository

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

Source from the content-addressed store, hash-verified

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