-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy
More file actions
executable file
·177 lines (156 loc) · 3.82 KB
/
my
File metadata and controls
executable file
·177 lines (156 loc) · 3.82 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
script_name=my
command=$1
subcommand=$2
upsearch () {
slashes=${PWD//[^\/]/}
directory="$PWD"
for (( n=${#slashes}; n>0; --n ))
do
test -e "$directory/$1" && echo "$directory/$1" && return
directory="$directory/.."
done
}
git_path=`upsearch .git`
if [[ -z "$git_path" ]]; then
echo "Not in a git repository. Exiting."
exit 1
fi
github_account_name=`git ls-remote --get-url origin | sed -n "s/git@github\.com:\(.*\)\/.*.git/\1/p"`
github_repo_name=`git ls-remote --get-url origin | sed -n "s/git@github\.com:.*\/\(.*\).git/\1/p"`
git_branch=`git branch --show-current`
show_help () {
echo "Usage: $script_name <command>"
echo "Commands:"
echo "* install - installs my to your shell profile as an alias"
echo "* githooks - installs githooks to current repo"
echo "* jk - opens the Jenkins job for the current branch in web browser"
echo "* gh - opens up branch in GitHub"
echo " * pr - opens up PR (requires github cli)"
echo " * branch - opens up branch in GitHub"
echo "* jr - opens JIRA for the current branch in web browser"
echo "* help - show this"
}
init () {
mycli_path=`upsearch .mycli`
if [[ -f "$mycli_path" ]]; then
eval `grep "=" $mycli_path`
fi
}
init
open_browser () {
python3 -m webbrowser $1
}
do_install () {
echo Installing $script_name as an alias through your shell profile.
shell=$(echo $SHELL | sed -n "s/^.*\/\(.*\)$/\1/p")
alias_cmd="alias $script_name=${SCRIPT_DIR}/$script_name"
case $shell in
zsh) shell_profile=~/.zshrc;;
bash) shell_profile=~/.bashrc;;
esac
if [[ -z "$shell_profile" ]]
then
echo "Shell not identified. Please install manually by adding this line to your shell profile."
echo $alias_cmd
exit 1
else
read -p "Proceed? [y/N]" proceed
case $proceed in
[Yy]*)
echo $alias_cmd >> $shell_profile
echo
echo "Alias installed to $shell_profile."
echo
echo "You may now use tr in a new terminal session."
echo "Alternatively you may source the profile or run the alias for immediate effect."
echo
echo " $> $alias_cmd "
echo
;;
[Nn]*|*)
echo Not installing. Exiting.
exit;;
esac
fi
}
do_githooks () {
git_hooks_library="$SCRIPT_DIR/githooks"
git_hooks_path="$git_path/hooks"
echo "Git hooks to install:"
for file in $git_hooks_library/*
do
if [[ -f $file ]]; then
echo "* ${file##*/}"
fi
done
read -p "Proceed? [y/N]" proceed
case $proceed in
[Yy]*)
ln -s $SCRIPT_DIR/githooks/* $git_hooks_path
;;
[Nn]*|*)
echo Not installing. Exiting.
;;
esac
}
do_jenkins () {
case "$subcommand" in
show|*)
if [[ -z "$jenkins_base_url" ]]; then
echo "Please set jenkins_base_url in your .mycli file."
exit 1
else
jenkins_pipeline_url="$jenkins_base_url/job/${github_account_name}/job/${github_repo_name}/job/${git_branch}"
open_browser $jenkins_pipeline_url
fi
;;
esac
}
do_jira () {
if [[ "$jira_base_url" ]]; then
open_browser $jira_base_url/browse/${git_branch}
else
echo "Please set jira_base_url in your .mycli file."
exit 1
fi
}
check_gh_cli () {
if ! [ -x "$(command -v gh)" ]
then
echo "Please install github cli. Visit https://github.com/cli/cli."
exit 1
fi
}
do_github () {
case "$subcommand" in
pr)
check_gh_cli
gh pr view --web
;;
branch|*)
open_browser "https://github.com/${github_account_name}/${github_repo_name}/tree/${git_branch}"
;;
esac
}
case "$command" in
install)
do_install
;;
githooks)
do_githooks
;;
gh)
do_github
;;
jk)
do_jenkins
;;
jr)
do_jira
;;
help|*)
show_help
;;
esac