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

Function GitHubRepo

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

Source from the content-addressed store, hash-verified

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

Callers 12

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
CanPushToRepoFunction · 0.85

Calls 5

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

Tested by 3

TestGitHubRepo_notFoundFunction · 0.68
TestGitHubRepo_successFunction · 0.68