| 359 | } |
| 360 | |
| 361 | func 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 | |
| 415 | func RepoDefaultBranch(client *Client, repo ghrepo.Interface) (string, error) { |
| 416 | if r, ok := repo.(*Repository); ok && r.DefaultBranchRef.Name != "" { |