-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitbucketCreatePullRequest
executable file
·34 lines (26 loc) · 1.13 KB
/
bitbucketCreatePullRequest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
########################################
# Calculates and opens the correct #
# bitBucket link to start a PR #
########################################
# Based off this dead script with some tweaks: https://www.npmjs.com/package/bitbucket-pr?activeTab=code
source ~/bash-helpers/_colours
source ~/bash-helpers/_functions
# First parameter must contain the root directory, otherwise exit
rootDir=$1
# Alternatively, set a default rootDir here, e.g. arg1=$1; rootDir="${arg1:-your-repo-name}"
if [ -z "$rootDir" ]; then
echo "${RED}You must provide the root directory as the first parameter.${RESTORE}"
exit 1
fi
# Navigate to root to get the project name from which we get the org name
. cdRoot "$rootDir"
project=${PWD##*/}
org=$(git config --get remote.origin.url | grep -Eo "(\w*)/$project.git\/?$" | cut -d/ -f1)
# Get the current branch name and encode it
branch=$(git rev-parse --abbrev-ref HEAD)
branchEncoded=$(rawurlencode "$branch")
# Create and open the link
link="https://bitbucket.org/${org}/${project}/pull-requests/new?source=${branchEncoded}"
echo "${GREEN}Opening pull request link... ${link}"
open "${link}"