When I push to a remote branch that has a PR open, bitbucket responds with
remote:
remote: View pull request for feature => main:
remote: https://stash.my_company.io/projects/my_proj/repos/my_code/pull-requests/1234
remote:
I can parse this output and `open 'https://stash.my_company.io/projects/my_proj/repos/my_code/pull-requests/1234'` from the command line.
However, if I don't have anything to push but I still want to open up my PR from the command line, I cannot figure out how to do it.
***
I want to be able to learn what PR my current branch has open. How to ask the server this?
I have a script that helps me open up a PR from the command line.
#!/bin/bash
function browser_pr_for_current_branch_in_pwd_stash() {
local spec repo branch
if ! branch="$(git branch --show-current)"; then
echo "ERROR"
return 1
fi
# We want to extract the "spec" and "repo", then prepend 'users' or
# 'projects' to them depending on what type of repo it is (use the tilde to
# determine this)
IFS="," read -r spec repo < <(git remote -v | awk -F '[/ ]' '/fetch/ {print $4 "," $5}')
repo="${repo%.git}"
case "$spec" in
~*) spec="users/$(tr -d '~' <<< "$spec")" ;;
*) spec="projects/$(tr 'a-z' 'A-Z' <<< "$spec")" ;;
esac
# Build the URL and return the answer
echo "https://my_company.ilabs.io/${spec}/repos/$repo/compare/commits?sourceBranch=refs/heads/$branch"
}
if url="$(browser_pr_for_current_branch_in_pwd_stash "$PWD")"; then
open "$url"
fi
And I invoke it like so:
git pr
But what I'd like is that I could first query the server and see if there is already a PR open before trying to create a new one.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.