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

Failed to run external command: git, args: [branch --merged origin/] #79

Closed tnorthcutt closed 2 years ago

tnorthcutt commented 2 years ago

Describe the bug When I install this extension and try to run it with gh poi --dry-run, I receive the following output:

» gh poi --dry-run
== DRY RUN ==
✕ Fetching pull requests...
failed to run external command: git, args: [branch --merged origin/]
exit status 128

Your Environment

This seems to be the case regardless of which repo I run it in.

If I run git branch --merged origin or git branch --merged origin/, I get this output:

fatal: malformed object name origin

I'm not sure how to further debug this, but I'm happy to help however I can!

seachicken commented 2 years ago

Thanks for reporting😃 Looks like you are not getting the default branch name. What does the following return on the target repository?

gh repo view --json defaultBranchRef
tnorthcutt commented 2 years ago

@seachicken thanks for the reply! Here's what I get:

» gh repo view --json defaultBranchRef
{
  "defaultBranchRef": {
    "name": "staging"
  }
}
seachicken commented 2 years ago

Perhaps something is wrong with getting hostname or repoName. https://github.com/seachicken/gh-poi/blob/84e6f907c5801f68df15be9907f77078dd511e91/conn/command.go#L45

  1. run git remote -v to display origin address
    # for example:
    origin  git@github.com:seachicken/gh-poi.git (fetch)
    origin  git@github.com:seachicken/gh-poi.git (push)
  2. run ssh -T -G {hostname (e.g. github.com)} | grep hostname to see if hostname can be obtained.
  3. rerun gh repo view {hostname}/{repoName (e.g. seachicken/gh-poi)} --json defaultBranchRef
tnorthcutt commented 2 years ago

Thank you! Here's what I get – I'm not sure I did exactly what you were asking; please let me know if I've messed up anywhere 😊

» git remote -v                       
origin  git@github.com:apiabroad/portal-student.git (fetch)
origin  git@github.com:apiabroad/portal-student.git (push)

» ssh -T -G github.com | grep hostname
hostname ssh.github.com
canonicalizehostname false

» gh repo view ssh.github.com/apiabroad/portal-student --json defaultBranchRef
{
  "defaultBranchRef": {
    "name": "staging"
  }
}
seachicken commented 2 years ago

It may have something to do with being able to get ssh.github.com. (I can get github.com in my environment.)

  1. Does the following command not result in an error?
gh api --hostname ssh.github.com repos/apiabroad/portal-student --silent

related code: https://github.com/seachicken/gh-poi/blob/84e6f907c5801f68df15be9907f77078dd511e91/conn/command.go#L17

  1. Also, does ~/.ssh/config have this setting in your environment? https://docs.github.com/ja/enterprise-cloud@latest/authentication/troubleshooting-ssh/using-ssh-over-the-https-port#enabling-ssh-connections-over-https
tnorthcutt commented 2 years ago

Hmm, that does result in an error:

» gh api --hostname ssh.github.com repos/apiabroad/portal-student --silent
Get "https://api.ssh.github.com/repos/apiabroad/portal-student": x509: “*.github.com” certificate name does not match input

I do have this in my ~/.ssh/config:

Host github.com
    Hostname ssh.github.com
    Port 443
    ForwardAgent yes
seachicken commented 2 years ago

ssh.github.com is now supported. https://github.com/seachicken/gh-poi/releases/tag/v0.6.4 Can you try it? gh ext upgrade poi

tnorthcutt commented 2 years ago

Unfortunately I still get this output after upgrading:

» gh poi --dry-run
== DRY RUN ==
✕ Fetching pull requests...
failed to run external command: git, args: [branch --merged origin/]
exit status 128
seachicken commented 2 years ago

Thanks for checking 🙂 Added error handling when GitHub API response cannot be parsed. You may get a different error message after updating. gh ext upgrade poi https://github.com/seachicken/gh-poi/releases/tag/v0.6.6

Maybe the response with all the options set can't be parsed. gh repo view github.com/apiabroad/portal-student --json owner --json name --json parent --json defaultBranchRef

tnorthcutt commented 2 years ago

Interesting, a new error!

Does this provide more/better information?

» gh ext upgrade poi
✓ Successfully upgraded extension poi

» gh poi --dry-run
== DRY RUN ==
✕ Fetching pull requests...
error unmarshaling response: invalid character '\x1b' looking for beginning of value

» gh repo view github.com/apiabroad/portal-student --json owner --json name --json parent --json defaultBranchRef
{
  "defaultBranchRef": {
    "name": "staging"
  },
  "name": "portal-student",
  "owner": {
    "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "login": "apiabroad"
  },
  "parent": null
}
seachicken commented 2 years ago

I successfully parsed the JSON you taught me. Maybe another JSON is being retrieved, so if you could let me know the result, I might be able to solve the problem 🙂

gh ext upgrade poi
gh poi --debug | grep "repo view"
tnorthcutt commented 2 years ago

Thank you! Here's what I get after upgrading:

» gh poi --debug | grep "repo view"
error unmarshaling response: invalid character '\x1b' looking for beginning of value
run gh [repo view github.com/apiabroad/portal-student --json owner --json name --json parent --json defaultBranchRef] -> {

And here's the full output, in case it's helpful:

» gh poi --debug                   
run git [remote -v] -> origin   git@github.com:apiabroad/portal-student.git (fetch)
origin  git@github.com:apiabroad/portal-student.git (push)

run ssh [-T -G github.com] -> *****
run gh [repo view github.com/apiabroad/portal-student --json owner --json name --json parent --json defaultBranchRef] -> {
  "defaultBranchRef": {
    "name": "staging"
  },
  "name": "portal-student",
  "owner": {
    "id": "MDEyOk9yZ2FuaXphdGlvbjE0ODgwNDYy",
    "login": "apiabroad"
  },
  "parent": null
}

✕ Fetching pull requests...
error unmarshaling response: invalid character '\x1b' looking for beginning of value
seachicken commented 2 years ago

Perhaps your environment was not decoding the JSON because the output of the gh pr view included color char codes. I have created a version that works without including the color char code, so if possible, could you please help me confirm that it works? https://github.com/seachicken/gh-poi/pull/88

gh ext remove poi
gh ext install seachicken/gh-poi --pin v0.7.2-pre0
tnorthcutt commented 2 years ago

That works!! Magnificent 🎉

thor-yes-excited

seachicken commented 2 years ago

Yay!!! Thank you 😍 I'll release it later.

seachicken commented 2 years ago

@tnorthcutt I released v0.7.2! To remove version pinning by --pin, run gh ext upgrade poi --force.

tnorthcutt commented 2 years ago

@seachicken thank you!

Just FYI gh doesn't allow upgrading pinned extensions:

» gh ext upgrade poi --force                        
X Failed upgrading extension poi: pinned extensions can not be upgraded

So I just did gh ext remove poi and then gh ext install seachicken/gh-poi and that worked great!