-
Notifications
You must be signed in to change notification settings - Fork 0
/
open-pr
executable file
·52 lines (42 loc) · 1.52 KB
/
open-pr
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/sh
# Retrieve branch name
branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
# Retrieve destination branch
if [[ $1 ]]; then
destination_branch=$1
# Parse previous branch if “-” is specified as destination branch
if [[ $destination_branch == '-' ]]; then
destination_branch=$(git rev-parse --symbolic-full-name @{-1})
destination_branch=${destination_branch#*refs/heads/}
fi;
else
# Try to extract the destination from the current branch
destination_branch=${branch%--*}
# Fall back to the default origin branch
if [[ $branch == $destination_branch ]]; then
master_exists=$(git branch | grep 'master')
if [[ -z $master_exists ]]; then
destination_branch=develop
else
destination_branch=master
fi
fi
fi;
# Determine the default origin branch
if [[ $branch == $destination_branch ]]; then
master_exists=$(git branch | grep 'master')
if [[ -z $master_exists ]]; then
destination_branch=develop
else
destination_branch=master
fi
fi
# Retrieve repository URL
repository_url=$(git remote get-url origin | sed -e 's/git@//' -e 's/\.git//' -e 's/:/\//')
if [[ $repository_url == github* ]]; then
pr_url=https://$repository_url/compare/$destination_branch...$branch
elif [[ $repository_url == gitlab* ]]; then
pr_url="https://$repository_url/merge_requests/new?merge_request%5Bsource_branch%5D=$branch&merge_request%5Btarget_branch%5D=$destination_branch"
fi
# Open the new Pull Request URL
open $pr_url