Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH should not require git repository to exist where operation does not affect one #9072

Open
arcivanov opened this issue May 12, 2024 · 5 comments
Labels
bug Something isn't working gh-run relating to the gh run command needs-user-input

Comments

@arcivanov
Copy link

arcivanov commented May 12, 2024

Describe the bug

I've attempted to use gh run cancel <id> from a directory that was not a repository.
While the cancel operation would've proceeded normally due to having GH_TOKEN in the env, gh started balking at not being in a git repository. When I initialized the directory with git init as a workaround, gh run cancel further complained there were no remotes in the repository.

Case 1 (empty dir):
https://github.com/karellen/karellen-llvm/actions/runs/9047154513/job/24858809382#step:2:26
Case 2 (git init with no remotes):
https://github.com/karellen/karellen-llvm/actions/runs/9047223038/job/24858879136#step:2:39

Version is 2.49.0.

Steps to reproduce the behavior

The exact code is linked above in the publicly accessible workflows.

Expected vs actual behavior

Expected: GH CLI has no git repository requirements for operations not affecting git repositories.
Actual: GH CLI performs git repository validation for operations not affecting git repositories.

Logs

Linked above in the action runs.

@arcivanov arcivanov added the bug Something isn't working label May 12, 2024
@cliAutomation cliAutomation added the needs-triage needs to be reviewed label May 12, 2024
@arcivanov
Copy link
Author

arcivanov commented May 12, 2024

Doing git init followed by git init add remote <url> is a workaround for this problem.
Here are the logs of the functional workaround: https://github.com/karellen/karellen-llvm/actions/runs/9047299097/job/24859062533

@williammartin
Copy link
Member

Unfortunately the REST API does require the repo ID which is why the CLI needs to know the repo to which the run belongs. However, instead of initialising a git repo I would suggest you use gh cancel run -R [HOST/]OWNER/REPO <ID> which will be used in place of interrogating your filesystem for a git repository.

@williammartin williammartin added gh-run relating to the gh run command needs-user-input and removed needs-triage needs to be reviewed labels May 12, 2024
@arcivanov
Copy link
Author

let me try that, thanks!

@arcivanov
Copy link
Author

While I'm trying it, gh can also do what I'm going to do is use GITHUB_REPOSITORY and GITHUB_SERVER_URL env variables to determine the host/owner/repo.

arcivanov added a commit to karellen/karellen-llvm that referenced this issue May 12, 2024
@arcivanov
Copy link
Author

https://github.com/karellen/karellen-llvm/actions/runs/9049315253/job/24863292405#step:2:25

This worked, thank you!

I still think that in the presence of GITHUB_SERVER_URL and GITHUB_REPOSITORY there should be no need to query git. The order should be -R, env vars, git.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working gh-run relating to the gh run command needs-user-input
Projects
None yet
Development

No branches or pull requests

3 participants