Repository navigation
Description
Describe the bug
When logged in, but without the 'project' scope, the behavior leads to confusing error messages, that do not lead to scope/permissions being the culprit.
$ gh --version
gh version 2.38.0 (2023-11-01)
https://github.com/cli/cli/releases/tag/v2.38.0
Steps to reproduce the behavior
$ gh auth status
github.com
✓ Logged in to github.com as chrishodson (GITHUB_TOKEN)
✓ Git operations for github.com configured to use https protocol.
✓ Token: ghu_************************************
If you do a list of projects, it seems to work:
$ gh project list
NUMBER TITLE STATE ID
0 open
But if you try to use that number (0):
$ gh project copy 0 --drafts --source-owner chrishodson-test-org --target-owner '@me' --title 'Test_Project'
? Which project would you like to use?
(#0)
GraphQL: Could not resolve to a node with the global id of '' (copyProjectV2)
Note also that it asked which project number to use, even though one was specified.
If you try and use it non-interactively:
$ yes | gh project copy 0 --drafts --source-owner chrishodson-test-org --target-owner '@me' --title 'Test_Project'
project number is required when not running interactively
Expected vs actual behavior
Working as expected after gh auth refresh -s project:
$ gh auth status
github.com
✓ Logged in to github.com as chrishodson (/home/codespace/.config/gh/hosts.yml)
✓ Git operations for github.com configured to use https protocol.
✓ Token: gho_************************************
✓ Token scopes: gist, project, read:org, repo, workflow
$ gh project list --owner chrishodson-test-org
NUMBER TITLE STATE ID
5 sample template open PVT_****
$ gh project copy 5 --drafts --source-owner chrishodson-test-org --target-owner '@me' --title 'Test_Project'
https://github.com/users/chrishodson/projects/3
Both the list and copy command make no mention that there is a scope missing, or even to check that. The behavior isn't wrong, but the error messages could be expanded.
In addition, showing the results of the list command, but with a project number of 0 is confusing.
Finally, the handling of 0 as the project number when trying to do a copy is a bit confusing
Logs
See inline
Activity
andyfeller commentedon Nov 23, 2023
@chrishodson : Thanks for opening this issue up! ❤
Several things that stood out to me
this is through a GitHub user-to-server token (
ghu)Rather than login through the web browser (resulting in an OAuth access token
gho) or using a classic token or using a classic or fine grain PAT, this session appears to be authenticated in a different way.I don't know if this is meaningful because I get a different behavior when using the web flow:
When I refresh my token with
read:projectscope and attempt togh project copy, I get an error message as expected that I don't haveprojectscope:none of the token scopes are listed for
ghutokensmaybe this is cut off from creating the issue or we simply do not pull that information the same way as other tokens.
project with a number of
0is weirdI'm not sure I've ever seen an issue, pull request, discussion, workflow, workflow run, or project with a number of
0before.What is going on under the covers
Let's figure out how the GitHub CLI is trying to suggest users fix permission scope issues and work backwards.
1. Handling errors and signaling missing permissions
cli/pkg/cmd/project/shared/queries/queries.go
Lines 1190 to 1211 in 06e438b
2. Handling GraphQL mutations for
gh projectscommandscli/pkg/cmd/project/shared/queries/queries.go
Lines 93 to 97 in 06e438b
3. Top-level
gh project copycommand invocationcli/pkg/cmd/project/copy/copy.go
Lines 111 to 114 in 06e438b
Theory
I think there is something about GitHub user-to-server tokens at play here that differs how we get scope information and handle these errors.