seachicken / gh-poi

✨ Safely clean up your local branches
https://dev.to/seachicken/safely-clean-up-your-local-branches-9i3
MIT License
682 stars 19 forks source link

Add support for `GH_HOST` and `GH_REPO` environment variables #125

Closed rastersize closed 2 weeks ago

rastersize commented 3 weeks ago

Description gh supports setting the GitHub host and repo slug that should be used via the GH_HOST and GH_REPO environment variables. It would be great if gh-poi could add support for these.

Additional context I interact with a GitHub Enterprise installation where the Git remote use a proxy, instead of the GitHub Enterprise domain. This makes gh fail as it expects it to also be the GitHub host. To overcome this we can set the GH_HOST and GH_REPO environment variables. Which works great with gh itself.

Unfortunately gh-poi fails as it doesn’t seem to read those environment values.

Given a remote.origin.url of https://git.enterprise.com/foo/bar where GitHub Enterprise is hosted ad github.enterprise.com:

$ GH_HOST="github.enterprise.com" GH_REPO="foo/bar" gh pr list
[Shows a list of PRs]

$ GH_HOST="github.enterprise.com" GH_REPO="foo/bar" gh poi
✕ Fetching pull requests...
failed to run external command: gh, args: [repo view git.enterprise.com/foo/bar --json owner,name,parent,defaultBranchRef]
 exit status 1

Thank you!

seachicken commented 3 weeks ago

Thanks for the good point! gh-poi's policy is to get as close as possible to the gh specifications, so it would be good to support it. This code determines the host, so it looks like it will need to be overwritten with GH_HOST variable. However, gh-poi will not work correctly unless the local git information in the current directory where it is executed and the remote GitHub information are the same, so overwriting with GH_REPO may be problematic in some cases.

seachicken commented 3 weeks ago

I've tried to override the hostname with the GH_HOST environment variable. Does this work in your environment? Please try it if you like:

gh ext remove poi
gh ext install seachicken/gh-poi --pin v0.11.0-pre0
rastersize commented 2 weeks ago

@seachicken It works, thank you so much!

seachicken commented 2 weeks ago

Thanks for checking! I've just released it.

You can remove the version pinning and install the latest version:

gh ext remove poi
gh ext install seachicken/gh-poi