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

Issue with `gh.CurrentRepository`: `unable to determine current repository, none of the git remotes configured for this repository point to a known GitHub host` #27

Closed nicokosi closed 2 years ago

nicokosi commented 2 years ago

Hello! :wave:

I have recently created a GitHub CLI extension, gh-collab-scanner, that relies on gh.CurrentRepository to detect the current GitHub repository.

I don't understand why it does not work on my Ubuntu laptop: unable to determine current repository, none of the git remotes configured for this repository point to a known GitHub host error occurs, see https://github.com/nicokosi/gh-collab-scanner/issues/13 (but it works on my macOS laptop).

Thanks in advance for your help.

samcoe commented 2 years ago

@nicokosi Have you run gh auth login on your Ubuntu machine? CurrentRepository cross checks the git remotes against hosts that you are authenticated with and raises this error if there are no overlaps. It is likely that on your other machine you have authenticated using gh already which is why you are not seeing this error.

nicokosi commented 2 years ago

@nicokosi Have you run gh auth login on your Ubuntu machine? CurrentRepository cross checks the git remotes against hosts that you are authenticated with and raises this error if there are no overlaps. It is likely that on your other machine you have authenticated using gh already which is why you are not seeing this error.

Thanks @samcoe for your quick answer. :hugs:

Yes, I have run gh auth login on my Ubuntu machine, here is the authentication status:

$ gh auth status
github.com
  ✓ Logged in to github.com as nicokosi (GITHUB_TOKEN)
  ✓ Git operations for github.com configured to use https protocol.
  ✓ Token: *******************

It still fails:

$ gh collab-scanner --verbose
(current repo)
unable to determine current repository, none of the git remotes configured for this repository point to a known GitHub host%  

It may be related to my git config:

$ git config --local --list | grep "^remote."
remote.origin.url=git@github.com:nicokosi/gh-collab-scanner.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
nicokosi commented 2 years ago

And it works on my macOS laptop which has ssh config:

gh auth status
github.com
  ✓ Logged in to github.com as nicokosi (GITHUB_TOKEN)
  ✓ Git operations for github.com configured to use ssh protocol.
  ✓ Token: *******************

Closing this issue.

nicokosi commented 2 years ago

For information, I fix me issue this way:

$ gh config set git_protocol ssh --host github.com

$ gh auth status
  ✓ Logged in to github.com as nicokosi (GITHUB_TOKEN)
  ✓ Git operations for github.com configured to use ssh protocol.
  ✓ Token: *******************

$ gh collab-scanner
README ☑️, topics ☑️, 1 collaborator 👤, community profile score: 33 💯