-
Notifications
You must be signed in to change notification settings - Fork 0
/
purr
executable file
·37 lines (29 loc) · 1.38 KB
/
purr
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
#!/usr/bin/env bash
set -euo pipefail
function open(){
if which open &>/dev/null; then
command open "${@}";
elif which xdg-open &>/dev/null; then
command xdg-open "${@}";
else
echo "open: ${@}"
fi
}
urls=$( git remote |grep -v new-origin | xargs -I{} git remote get-url {} )
if url=$( echo "$urls" | grep dev.azure.com | head -n 1 ); then
# example: [email protected]:v3/bushelpowered/terraform/unified-iac
read org project repo < <( echo "$url" | rev | cut -d/ -f1-3 | rev | tr '/' ' ' );
open "https://dev.azure.com/$org/$project/_git/$repo/pullrequestcreate?sourceRef=$( git branch --show-current )"
elif url=$( echo "$urls" | grep '[email protected]' | head -n 1 ); then
# example: [email protected]:myriadmobile/systems-utils.git
urlPath=$( echo "$url" | cut -d: -f2 | sed 's/\.git.*$//' )
open "https://bitbucket.org/${urlPath}/pull-requests/new?source=$( git branch --show-current )&t=1"
elif url=$( echo "$urls" | grep '[email protected]' | head -n 1 ); then
# src: [email protected]:oliverisaac/go-azuredevops.git
# goal: https://github.com/oliverisaac/go-azuredevops/pull/new/fix-azdo-changecounts-api-differences
urlPath=$( echo "$url" | cut -d: -f2 | sed 's/\.git.*$//' )
open "https://github.com/$urlPath/pull/new/$( git branch --show-current )"
else
>&2 echo "Not in an azdo backed repo: $urls"
exit 1
fi