Fix project scope errors during issue creation - #14035
Draft
maxbeizer wants to merge 8 commits into
Draft
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Improves project-scope error reporting during issue and pull request creation while preserving optional metadata behavior.
Changes:
- Parses structured GraphQL missing-scope errors.
- Propagates deferred ProjectV2 scope failures during project resolution.
- Adds API and command regression tests.
Show a summary per file
| File | Description |
|---|---|
api/client.go |
Adds missing-scope parsing and error formatting. |
api/client_test.go |
Tests scope extraction and formatting. |
api/queries_projects_v2.go |
Recognizes structured ProjectV2 scope errors. |
api/queries_projects_v2_test.go |
Tests ignorable missing-scope errors. |
api/queries_repo.go |
Carries scope failures through project resolution. |
api/queries_repo_test.go |
Tests classic and inaccessible project resolution. |
pkg/cmd/issue/create/create_test.go |
Covers issue creation without project scope. |
pkg/cmd/pr/create/create_test.go |
Covers pull request creation without project scope. |
pkg/cmd/pr/shared/params.go |
Surfaces missing-scope errors during metadata resolution. |
Review details
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Suppressed comments (1)
api/client_test.go:72
- 🛑 Requirement: Use
requirefor these error assertions.AGENTS.md:110-118requires error checks to stop the test immediately, preventing later assertions from running against an invalid setup.
assert.EqualError(t, GraphQLMissingScopesError(err), "error: your authentication token is missing required scopes [read:discussion read:project]\nUpdate your authentication token to include: read:discussion,read:project")
assert.Empty(t, GraphQLMissingScopes(errors.New("not a GraphQL error")))
assert.NoError(t, GraphQLMissingScopesError(errors.New("not a GraphQL error")))
- Files reviewed: 9/9 changed files
- Comments generated: 4
- Review effort level: Balanced
Comment on lines
+118
to
+120
| var missingScopesErr api.MissingScopesError | ||
| if errors.As(err, &missingScopesErr) { | ||
| return missingScopesErr |
Comment on lines
+74
to
+79
| m := requiredScopesRE.FindStringSubmatch(graphQLError.Message) | ||
| if m == nil { | ||
| continue | ||
| } | ||
| for _, scope := range strings.Split(m[1], ",") { | ||
| missing[strings.Trim(scope, "' ")] = struct{}{} |
Comment on lines
+49
to
+50
| reg := &httpmock.Registry{} | ||
| client := newTestClient(reg) |
Comment on lines
+346
to
+347
| reg := &httpmock.Registry{} | ||
| client := newTestClient(reg) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8798
Surface missing ProjectV2
read:projectauthorization failures when an issue or pull request is explicitly created with--project. Previously, an inaccessible requested ProjectV2 was reported as not found.gh issue viewandgh pr viewread:projectgh projectmissing-scope output unchangedLocal demonstration
Fixture-backed checks
From this PR branch, run the focused tests without changing credentials or creating GitHub content:
These exercise an
INSUFFICIENT_SCOPESresponse requiringread:project. They show that explicit issue/PR creation returns actionable scope guidance, while optional ProjectV2 lookup remains ignorable and classic-project resolution still succeeds.Live comparison with
trunkUse a disposable repository and a token that can access that repository but deliberately lacks
read:project. Choose the title of a ProjectV2 that is attached to the repository. Both commands stop during metadata resolution, before creating an issue.Captured locally against
cli/cliwith a token that lacksread:project:The same comparison applies to
gh pr create --project, but the fixture-backed PR test above is preferred because it cannot create a pull request.