carapace-sh / carapace-bin

multi-shell multi-command argument completer
https://carapace.sh
MIT License
885 stars 48 forks source link

gh: Doesn't respect GH_HOST or gh auth #2333

Closed annettejanewilson closed 6 months ago

annettejanewilson commented 6 months ago

Current Behavior

I have GH_HOST set to an internal Github Enterprise instance. (E.g. github.companyname.example) I have run gh auth login to authenticate to the same internal Github Enterprise instance. I am not authenticated to Github.com. When I try to tab complete:

gh repo clone Annet

I get

ERR (gh: API rate limit exceeded for XXX.XXX.XXX.XXX. (But here's the good news: Authe...)  _

Upon inspection, I can see that Carapace is running a command starting with

gh api --hostname github.com

It appears that Carapace is querying github.com instead of my configured Github Enterprise instance, resulting in failure.

Expected Behavior

Carapace should make the request to the same host that gh would be connecting to. As I understand it, that is:

Again, as far as I can tell, simply not specifying --hostname in the invocation of gh api should to do the right thing. I see the following behaviour:

gh auth status                         GH_HOST             Command           Result

Single mycompany.example host          <empty string>      gh api /user      Connects to mycompany.example
Both github.com and mycompany.example  <empty string>      gh api /user      Connects to github.com
Both github.com and mycompany.example  mycompany.example   gh api /user      Connects to mycompany.example

Steps To Reproduce

  1. Install and configure carapace if it's not already installed.
  2. Install gh if it's not already installed.
  3. Start a bash shell.
  4. Run gh auth logout and log out of any accounts on github.com.
  5. Run gh auth login and log in to a Github Enterprise instance. (I'm sorry, I don't know how to demonstrate this without one!)
  6. Run export GH_HOST=github.mycompany.example (substitute your Github Enterprise hostname).
  7. Type gh repo clone Annet (substitute a prefix of your own account name).
  8. Press tab
  9. Observe rate limit or authentication errors for github.com.

Version

1.0.0

OS

Shell

Anything else?

No response

rsteube commented 6 months ago

I don't have access to an enterprise instance, so there's no support for that yet. It is however prepared and shouldn't be too hard to fix.

I'll request a developer license and have a look.

rsteube commented 6 months ago

I don't have a developer license yet, but the recent changes might already fix it for the most part. If you want to test it you can build a development version.

rsteube commented 6 months ago

Still can't test it in depth, but I expect this to work now. Feel free to reopen if not.