issue create: avoid querying default branch when checking issue availability#12873
issue create: avoid querying default branch when checking issue availability#12873SergioChan wants to merge 1 commit intocli:trunkfrom
Conversation
|
Thanks for your pull request! Unfortunately, it doesn't meet the minimum requirements for review:
Please update your PR to address the above. Requirements:
This PR will be automatically closed in 7 days if these requirements are not met. |
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #12798 where gh issue create fails with fine-grained PATs that have Issues: Write but not Contents: Read permissions. The root cause was that the GitHubRepo function fetches defaultBranchRef, which requires Contents: Read. The fix switches to FetchRepository to request only the minimal fields needed.
Changes:
- Replaces
api.GitHubRepo(...)withapi.FetchRepository(..., []string{"hasIssuesEnabled"})to avoid fetchingdefaultBranchRefand reduce the required PAT permissions.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| repo, err := api.GitHubRepo(apiClient, baseRepo) | ||
| repo, err := api.FetchRepository(apiClient, baseRepo, []string{"hasIssuesEnabled"}) |
There was a problem hiding this comment.
The call to FetchRepository requests only "hasIssuesEnabled", but the returned repo object is used in two additional places that depend on fields not included in the query:
-
Line 378 –
api.IssueCreate(apiClient, repo, params)readsrepo.IDas therepositoryIdmutation input (seeapi/queries_issue.go:286). Since"id"is not in the requested fields,repo.IDwill be an empty string, causing thecreateIssuemutation to fail with an invalid/missing repository ID. -
Line 303 –
repo.ViewerCanTriage()checksrepo.ViewerPermission(seeapi/queries_repo.go:276-282). Since"viewerPermission"is not requested, it will always be empty, soViewerCanTriage()will always returnfalsein interactive mode, silently removing the "Add metadata" option from the prompt.
The fields list should be updated to []string{"hasIssuesEnabled", "id", "viewerPermission"} to include both required fields while still avoiding the defaultBranchRef fetch that requires Contents: Read.
Note: the existing tests pass because the mock HTTP responses happen to include an "id" field in their JSON payload, but the real GitHub API will only return fields that were explicitly requested in the GraphQL query.
| repo, err := api.FetchRepository(apiClient, baseRepo, []string{"hasIssuesEnabled"}) | |
| repo, err := api.FetchRepository(apiClient, baseRepo, []string{"hasIssuesEnabled", "id", "viewerPermission"}) |
|
Thanks for the flag. I’ll retarget this work to an issue that is explicitly labeled |
|
Thanks for the PR, @SergioChan! 🙏 The issue is not labeled as
help wanted
That said, I'd appreciate it if you follow our contribution guideline. Please do not open PRs for issues that are not labeled as
help wanted
|
|
Closing this in favour of #12884. Please check out the other PR description for the reasons on why we're rejecting this, @SergioChan. |
Summary
gh issue createto fetch onlyhasIssuesEnabledinstead of the fullGitHubRepopayloaddefaultBranchRefGraphQL field access from the issue-create pathTesting
Related