-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-open-web-ui
executable file
·104 lines (85 loc) · 2.32 KB
/
git-open-web-ui
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
set -eo pipefail
while [ $# -gt 0 ]; do
case "$1" in
--commit|-c)
open_commit=1
shift
;;
--pipeline|-p)
open_pipeline=1
shift
;;
--file|-f)
open_file=1
path="$2"
shift
shift
;;
--remote|-r)
remote="$2"
shift
shift
;;
--issue|-i)
open_issue=1
shift
;;
--help|-h)
echo "Usage: $0 [options]" 1>&2
echo 1>&2
echo "Options:" 1>&2
echo " --commit, -c" 1>&2
echo " If set, tries to open the commit HEAD is at." 1>&2
echo 1>&2
echo " --pipeline, -p" 1>&2
echo " If set, tries to open the GitLab pipelines for HEAD." 1>&2
echo 1>&2
echo " --file <path>, -f <path>" 1>&2
echo " If set, opens the given path for the current branch." 1>&2
echo " If used together with --commit, -c, the given path is opened for the" 1>&2
echo " given commit." 1>&2
echo 1>&2
echo " --remote <remote>, -r <remote>" 1>&2
echo " The remote to use, defaults to 'origin'." 1>&2
echo 1>&2
echo " --issue, -i" 1>&2
echo " Attempt to open an issue in a bugtracker by using the first word of the commit message of HEAD as an issue ID." 1>&2
echo " Requires GIT_EXTS_BT_URL to be set. Uses the URL by appending the issue ID." 1>&2
echo 1>&2
exit 1
;;
*)
echo "Error: Unknown argument '$1'"
exit 1
;;
esac
done
if [[ ! "$remote" ]]; then
remote="origin"
fi
remote_url=$(git remote get-url "$remote")
cleaned_url=$(echo "$remote_url" | sed 's/git@//; s/:/\//; s/.git$//')
url="https://$cleaned_url"
rev=$(git rev-parse HEAD)
if [[ "$open_file" ]]; then
if [[ ! "$open_commit" ]]; then
rev=$(git rev-parse --abbrev-ref HEAD)
fi
obj_type=$(git cat-file -t $rev:$path)
url="$url/$obj_type/$rev/$path"
elif [[ "$open_commit" ]]; then
rev=$(git rev-parse HEAD)
url="$url/commit/$rev"
elif [[ "$open_pipeline" ]]; then
url="$url/commit/$rev/pipelines"
elif [[ "$open_issue" ]]; then
if [[ ! "$GIT_EXTS_BT_URL" ]]; then
echo "Error: GIT_EXTS_BT_URL not set" 1>&2
exit 1
fi
commit_subject=$(git show --no-patch --format='%s' HEAD)
issue_key=$(echo "$commit_subject" | tr -s ' ' -f1)
url="$GIT_EXTS_BT_URL/$issue_key"
fi
open "$url"