You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.