-
Notifications
You must be signed in to change notification settings - Fork 0
/
env
executable file
·215 lines (177 loc) · 4.87 KB
/
env
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/bin/bash -e
# TODO mudar as confs locais pra serem por repo
VERSION=0.0.1
INSTALL_PREFIX=gclit
if [[ $EUID -eq 0 ]]; then
echo "this script should NOT be run as root" 1>&2
exit 1
fi
# these settings can be overridden by creating $LOCAL_ENV
SETUP_DEBUG=false
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
CLIT="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
REPO_DIR=$CLIT
REPO_NAME=$(basename $REPO_DIR)
TODAY=$($CLIT/now.sh -d)
TODAY_F=/tmp/today
echo $TODAY > $TODAY_F
CHANGELOG=$REPO_DIR/README.md
CONFD=$HOME/.${REPO_NAME}
LOCAL_ENV=$CONFD/config
GITLAB_ENV=gitlab.env
LOCAL_DB=$CONFD/db
LOGF=$CONFD/${REPO_NAME}.log
RR_EMAIL=''
CACHE=/tmp/$REPO_NAME
mkdir -p $CACHE
FEATURE_PREFIX='feature'
HOTFIX_PREFIX='hotfix'
REMOTE_FEATURES=true
FEATURE_DELETE_WHEN_DELIVERED=true
DEFAULT_MR_LABEL=gclit
#RR_CACHE_TTL=5000
# rr global query params: limit=100, page=1, sort=jprop, sort_dir=desc, filter_id=all
RR_APP_KEY=''
RR_U_TOKEN=''
RR_URL='https://runrun.it'
RR_API='https://runrun.it/api/v1.0'
RR_ENABLED=''
GITLAB_TOKEN=''
GITLAB_API='https://gitlab.com/api/v4'
DB_NAME=timesheet
DB_USER=postgres
monitor_sh=monitor-lock
monitor=$(ps aux | grep $monitor_sh | grep -v grep | tr -s ' ' | cut -d' ' -f2)
if [[ ! -n "$monitor" ]]; then
>&2 echo "$monitor_sh is offline. relaunching..."
nohup $MYDIR/$monitor_sh.sh &>$LOGF&
>&2 echo "relaunched: $!; log file: $LOGF"
fi
function rr_header_app_key() {
echo "App-Key: $RR_APP_KEY"
}
function rr_header_usr_token() {
echo "User-Token: $RR_U_TOKEN"
}
function gitlab_header_token() {
echo "PRIVATE-TOKEN: $GITLAB_TOKEN"
}
function rr_user_id() {
u=$(echo $RR_EMAIL | cut -d'@' -f1 | tr '.' '-')
if [[ ! -n "$u" ]]; then
err "couldn't parse user id from '$RR_EMAIL'"
exit 1
fi
echo $u
}
function nan() {
in="$1"
regex='^[0-9.]+$'
if ! [[ "$in" =~ $regex ]] ; then
echo true
else
echo false
fi
}
function safe_name() {
# remove non ascii:
name=$(echo "$1" | iconv -f utf8 -t ascii//TRANSLIT)
# to lower case:
name=$(echo ${name,,})
# replace spaces for "-", then remove anything that's non alphanumeric
echo ${name// /-} | sed 's/[^a-z0-9-]//g'
}
##
# prompts for an rr project.
# @param project name or id, case insensitive
# @return project id
function prompt_project_id() {
name_or_id="$1"
project=$($MYDIR/rr-find-project.sh "$name_or_id")
debug "matches for $name_or_id:"
debug "$project"
n=$(echo "$project" | $MYDIR/lines.sh)
if [[ $n -gt 1 ]]; then
info "found multiple matches for '$name_or_id':"
$MYDIR/iterate.sh "$project" '$line [$n]'
info -n "choose one [1]:"
read one
[[ ! -n "$one" ]] && one=1
debug "selected [$one]"
project=$($MYDIR/get.sh $one "$project")
debug "got '$project'"
if [[ ! -n "$project" ]]; then
project=$($MYDIR/get.sh 1 "$project")
debug "index out of bounds, falling back to $project"
fi
fi
if [[ ! -n "$project" ]]; then
err "could not find project '$project', try again"
exit 1
fi
# return project id:
echo $project | cut -d'=' -f1
}
function curr_branch() {
git branch | grep '*' | cut -d' ' -f2
}
# e.g: gitlab.com/group/repo-name
function project_url() {
repo_root=$(repo_root)
grep url "$repo_root/.git/config" | cut -d'=' -f2 | tr -d ' ' | sed -r 's/(.*)\b.git/\1/'
}
function repo_root() {
git rev-parse --show-toplevel
}
function repo_root_quiet() {
dir=$(git rev-parse --show-toplevel 2>/dev/null || true)
echo $dir
}
function check_installed() {
echo ""
echo "checking if $1 is installed..."
$@
}
function jprop() {
json="$1"
prop="$2"
value=$(echo "$json" | $MYDIR/jprop.sh "['$prop']")
if [[ $value != None ]]; then
echo "$value"
fi
}
function open_tasks() {
$MYDIR/psql-map.sh tasks \
"id,name,elapsed" \
"closed is false order by start"
}
function latest_tasks() {
$MYDIR/psql.sh "
select t.name, t.external_id, t.id,
sum(coalesce(e.elapsed, interval '0 minutes'))
from tasks t
join executions e on e.task_id=t.id
group by t.id
order by max(e.id) desc
limit 5
" --full
}
function latest_task() {
$MYDIR/psql.sh "select
t.id,t.name
from tasks t
join executions e on e.task_id=t.id
group by t.id
order by max(e.id) desc
limit 1
offset 1
"
}
function similar_task() {
$MYDIR/psql.sh "select similar_task('$1')"
}