Only fetch project data in pr edit when editing projects#13282
Open
maxbeizer wants to merge 1 commit into
Open
Only fetch project data in pr edit when editing projects#13282maxbeizer wants to merge 1 commit into
maxbeizer wants to merge 1 commit into
Conversation
When running gh pr edit with non-project flags (e.g. --body, --title), the command unconditionally fetched projectCards and projectItems fields from the GraphQL API. This caused the command to fail with "Resource not accessible by integration" when the token lacked project permissions, even though no project changes were requested. Restructure editRun to: - Prompt for which fields to edit before fetching the PR (in interactive mode), matching the pattern already used by gh issue edit - Only include projectCards and projectItems in the query when editable.Projects.Edited is true - Guard project defaults population behind the same condition Closes cli#6274 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates gh pr edit to avoid fetching GitHub Projects data from GraphQL unless the user is actually editing project associations, preventing permission failures for tokens without project scope.
Changes:
- Prompts for which fields to edit before fetching the PR in interactive mode, so project fields are only queried when selected.
- Conditionally includes
projectCards/projectItemsfinder fields only whenEditable.Projects.Editedis true. - Adds/updates tests to ensure project fields are present only when relevant, including a new test that asserts they’re skipped for non-project edits.
Show a summary per file
| File | Description |
|---|---|
| pkg/cmd/pr/edit/edit.go | Restructures editRun to prompt earlier (interactive) and to conditionally fetch/populate project-related fields only when editing projects. |
| pkg/cmd/pr/edit/edit_test.go | Updates existing project deprecation test setup and adds coverage ensuring project fields are excluded when not editing projects. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 0
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.
gh pr editunconditionally fetchesprojectCardsandprojectItemsfields from the GraphQL API, even when the user is only editing non-project fields like--bodyor--title. This causes the command to fail with permission errors when the token lacks project scope:This affects GitHub Apps,
GITHUB_TOKENin Actions, and fine-grained PATs that don't have theprojectpermission.Changes
Restructure
editRunto:Prompt before fetching — In interactive mode, ask the user which fields to edit before fetching the PR. This matches the pattern already used by
gh issue editand avoids querying project data when the user doesn't intend to edit projects.Conditionally include project fields — Only add
projectCardsandprojectItemsto the finder fields wheneditable.Projects.Editedis true (i.e., when--add-project/--remove-projectflags are used, or the user selects "Projects" in the interactive prompt).Guard project defaults — Only populate
editable.Projects.Defaultandeditable.Projects.ProjectItemswhen project data was actually fetched.Testing
TestProjectsV1Deprecationto setProjects.Editedso project fields are still tested when relevantTestEditSkipsProjectFieldsWhenNotEditingProjectsto verify project fields are excluded from the query when not editing projectsCloses #6274
Related: #8784, #13280