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

Function GitHubRepo

api/queries_repo.go:360–412  ·  view source on GitHub ↗
(client *Client, repo ghrepo.Interface)

Source from the content-addressed store, hash-verified

358}
359
360func GitHubRepo(client *Client, repo ghrepo.Interface) (*Repository, error) {
361 query := `
362 fragment repo on Repository {
363 id
364 databaseId
365 name
366 owner { login }
367 hasIssuesEnabled
368 description
369 hasWikiEnabled
370 viewerPermission
371 defaultBranchRef {
372 name
373 }
374 }
375
376 query RepositoryInfo($owner: String!, $name: String!) {
377 repository(owner: $owner, name: $name) {
378 ...repo
379 parent {
380 ...repo
381 }
382 mergeCommitAllowed
383 rebaseMergeAllowed
384 squashMergeAllowed
385 }
386 }`
387 variables := map[string]any{
388 "owner": repo.RepoOwner(),
389 "name": repo.RepoName(),
390 }
391
392 var result struct {
393 Repository *Repository
394 }
395 if err := client.GraphQL(repo.RepoHost(), query, variables, &result); err != nil {
396 return nil, err
397 }
398 // The GraphQL API should have returned an error in case of a missing repository, but this isn't
399 // guaranteed to happen when an authentication token with insufficient permissions is being used.
400 if result.Repository == nil {
401 return nil, GraphQLError{
402 GraphQLError: &ghAPI.GraphQLError{
403 Errors: []ghAPI.GraphQLErrorItem{{
404 Type: "NOT_FOUND",
405 Message: fmt.Sprintf("Could not resolve to a Repository with the name '%s/%s'.", repo.RepoOwner(), repo.RepoName()),
406 }},
407 },
408 }
409 }
410
411 return InitRepoHostname(result.Repository, repo.RepoHost()), nil
412}
413
414func RepoDefaultBranch(client *Client, repo ghrepo.Interface) (string, error) {
415 if r, ok := repo.(*Repository); ok && r.DefaultBranchRef.Name != "" {

Callers 13

checkRunFunction · 0.92
linkRepoFunction · 0.92
unlinkRepoFunction · 0.92
cloneRunFunction · 0.92
createFromScratchFunction · 0.92
mergeMethod · 0.92
NewCreateContextFunction · 0.92
TestGitHubRepo_notFoundFunction · 0.85
TestGitHubRepo_successFunction · 0.85
RepoDefaultBranchFunction · 0.85

Calls 5

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

Tested by 4

TestGitHubRepo_notFoundFunction · 0.68
TestGitHubRepo_successFunction · 0.68