Open bpatram opened 5 years ago
When I remove my remotes from my local repo gh starts to report the user correctly.
$ gh user -w
ebth
$ git remote -v
origin git@github.com:ebth/some-repo-path-here.git (fetch)
origin git@github.com:ebth/some-repo-path-here.git (push)
$ git remote rm origin
$ git remote -v
$ gh user -w
bpatram
Some version info of gh I'm running (latest version).
├─┬ gh@1.17.5
│ ├── async@1.5.2
│ ├── cli-table3@0.5.1
│ ├── colors@1.3.3
│ ├── github@0.2.4
│ ├── handlebars@4.0.14
│ ├── inquirer@6.2.1
│ ├── lodash@4.17.11
│ ├── marked@0.6.2
│ ├── marked-terminal@3.2.0
│ ├── moment@2.23.0
│ ├── nopt@3.0.6
│ ├── opn@5.4.0
│ ├── request@2.88.0
│ ├── truncate@2.0.1
│ ├── update-notifier@2.5.0
│ ├── userhome@1.0.0
│ ├── which@1.3.1
│ └── wordwrap@1.0.0
Thanks for the clear guidelines on reproducing this @bpatram. So if the origin remote has a different user, gh is giving priority to the user in the remote url?
You are right that that is a bug for the user cmd.
I know we give priority to the user in the remote url if you don't pass in --user username
. Do you have thoughts on whether or not that should be the default behavior?
So if the origin remote has a different user, gh is giving priority to the user in the remote url?
yes, this seems to be what is happening. I tested on another repo:
# outside repo folder
$gh user --whoami
bpatram
# inside repo folder
$ gh user --whoami
brandonpatram
$ git remote -v
origin git@gitlab.com:brandonpatram/some-repo-path-here.git (fetch)
origin git@gitlab.com:brandonpatram/some-repo-path-here.git (push)
I know we give priority to the user in the remote url if you don't pass in --user username. Do you have thoughts on whether or not that should be the default behavior?
I don't think it should be. Although, I can't think of a use case where it would be preferred to use the repo's user/owner instead of the current user logged into gh. Maybe I am missing something.
To provide a bit more context into my specific use case; I use gh
to build a rudimentary changelog based on a list of PR#s, I use gh user --whoami
to determine if the user running the script is the author of any of those PRs.
Here is the line that shows the logic for how the user is set. I blamed it and that line goes back to the inception of this project.
The remote origin user will win every time over the logged in user. I have never noticed that being a problem because my origin is always my username.
I am open to changing it for though for v2. I am working hard on releasing it soon but am stuck on reimplementing hooks and plugins at the moment. Nonetheless I will put it on my todos before releasing :)
gh
reports my current user incorrectly when called from a folder that is a git repo (I think that's what is triggering it?).In my case, it seems to return the organization the repo is owned by (ebth). Interestingly enough my
.gh.json
does list the correct user.Deleting the
.gh.json
file and relogging has no effect.