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

Function GitHubRepo

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

Source from the content-addressed store, hash-verified

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