| 356 | } |
| 357 | |
| 358 | func 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 | |
| 411 | func RepoDefaultBranch(client *Client, repo ghrepo.Interface) (string, error) { |
| 412 | if r, ok := repo.(*Repository); ok && r.DefaultBranchRef.Name != "" { |