MCPcopy
hub / github.com/cli/cli / GitHubRepo

Function GitHubRepo

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

Source from the content-addressed store, hash-verified

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