Skip to content

Commit

Permalink
fix gm gh pr checkout: user quit and no PR (#111)
Browse files Browse the repository at this point in the history
related to
- #31

## description
i found two bugs when using `gm gh pr checkout`
- in `nu-git-manager`, i pressed escape in `input list` and there was no
early `return` => the command crashed on `$res.id`
- in `nushell`, my GitHub remote repo was incorrectly set to
`amtoine/nushell` => the command crashed because the PR table was empty

this PR fixes those two bugs.
  • Loading branch information
amtoine authored Nov 24, 2023
1 parent 5463513 commit 72f2b03
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/nu-git-manager-sugar/github.nu
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,19 @@ export def "gm gh pr checkout" [] {
}

log debug $"pulling down list of pull requests for '($repo)'"
let res = gm gh query-api $"/repos/($repo)/pulls"
let prs = gm gh query-api $"/repos/($repo)/pulls"
| select number user.login title
| rename id author title
| input list --fuzzy
if ($prs | is-empty) {
log error $"repo '($repo)' does not have any PR to checkout"
log info "maybe the repo is not correct? you can try running `gh repo set-default` :)"
return
}

let res = $prs | input list --fuzzy
if $res == null {
log info "user chose to exit"
return
}

^gh pr checkout $res.id
Expand Down

0 comments on commit 72f2b03

Please sign in to comment.