cli / go-gh

A Go module for interacting with gh and the GitHub API from the command line.
https://pkg.go.dev/github.com/cli/go-gh/v2
MIT License
322 stars 45 forks source link

CurrentRepository() fails when executed inside a GH Workflow #34

Closed chelnak closed 2 years ago

chelnak commented 2 years ago

Hey - just discovered something that might be interesting.

When a consuming application calls CurrentRepository() from inside a GH workflow I'm seeing the following error:

unable to determine current repository, none of the git remotes configured for this repository point to a known GitHub host

I think this is because ~/.config/gh/hosts.yml does not exist on a runner because of the TOKEN based auth (vs oauth).

This would cause FilterByHosts to return an error.

I have worked around this by. exporting the GH_HOST environment variable.. however it was not immediately obvious what to do.

If this is expected behaviour we could update the README with a note on compatibility with GH Actions.

Cheers!

samcoe commented 2 years ago

@chelnak This is unexpected behavior so I am going to classify it as a bug. You also correctly diagnosed what is happening here. The issue is that CurrentRepository() does not consider github.com as a valid host as it is not defined by GH_HOST or in the ~/.config/gh/hosts.yml file. I think adding in additional logic to config.Hosts() to include github.com in the return slice when there is an environment token defined is the correct solution here.