From b91490e2730f3796c409a754001ce8048ada2cfb Mon Sep 17 00:00:00 2001 From: Ade Attwood Date: Mon, 29 Jan 2024 20:26:05 +0000 Subject: [PATCH] fix(shell): update prr to work with sapling so we can code review When we are in a sapling repo `gh pr checkout` will not work. If this is the case we wil need to export the PRR_NUMBER so we can skip getting the PR number. Working with prr and sapling comes with following limitation. You can only use the branch name. When git you can use the pr number, url or the branch. Unfortunately so we can checkout we will need to use the branch name. --- .../core/files/oh-my-zsh/custom/prr.zsh | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/site-modules/core/files/oh-my-zsh/custom/prr.zsh b/site-modules/core/files/oh-my-zsh/custom/prr.zsh index 08b18f7..fd10a69 100644 --- a/site-modules/core/files/oh-my-zsh/custom/prr.zsh +++ b/site-modules/core/files/oh-my-zsh/custom/prr.zsh @@ -8,6 +8,11 @@ function get_project() { # Gets the PR number from the current git repo and branch. function get_pr_number() { + if [[ ! -z $PRR_NUMBER ]]; then + echo "$PRR_NUMBER" + return + fi + gh pr view --json=number --jq='.number' } @@ -15,8 +20,21 @@ alias prr-get='prr get "$(get_project)"/"$(get_pr_number)"' alias prr-submit='prr submit "$(get_project)"/"$(get_pr_number)"' alias prr-edit='$EDITOR ~/.local/share/prr/$(get_project)/$(get_pr_number).prr' + function prr-review() { - gh pr checkout "$1" + # Check to see if we are in a git repo, if we are then we want to checkout + # the branch of the PR. + if git rev-parse --is-inside-work-tree &>/dev/null; then + gh pr checkout "$1" + fi + + # Check to see if we are in a sapling directory, if we are then not only do + # we need to checkout the PR branch but we also need to export the PPR_NUMBER + if \sl root &>/dev/null; then + export PRR_NUMBER="$(gh --repo "$(get_project)" pr view --json=number --jq='.number' $1)" + \sl goto "remote/$1" + fi + prr-get prr-edit }