Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

How to get the PR for a branch from the command line

Edited
Ari Sweedler
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
Sep 20, 2023

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?

1 answer

0 votes
Ari Sweedler
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
Sep 20, 2023 • edited

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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events