MCPcopy
hub / github.com/cli/cli / FetchRepository

Function FetchRepository

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

Source from the content-addressed store, hash-verified

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