-
Notifications
You must be signed in to change notification settings - Fork 0
/
spend.sh
executable file
·65 lines (53 loc) · 1.58 KB
/
spend.sh
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
#!/bin/bash -e
MYSELF="$(readlink -f "$0")"
MYDIR="${MYSELF%/*}"
ME=$(basename $MYSELF)
source $MYDIR/env
[[ -f $LOCAL_ENV ]] && source $LOCAL_ENV
source $MYDIR/log.sh
source $MYDIR/require.sh
task_id="$1"
gitlab_prefix=fix
task=$($MYDIR/psql.sh "
select row_to_json(tasks)
from tasks where id = '$task_id'
")
task_repo=$(jprop "$task" repo)
task_name=$(jprop "$task" name)
if [[ -z "$task_repo" ]]; then
debug "no repo defined"
exit 0
fi
if [[ -d "$task_repo" ]]; then
is_gitlab=$(grep -c gitlab "$task_repo/.git/config" || true)
if [[ $is_gitlab -lt 1 ]]; then
# TODO support github
debug "not a gitlab repo: $task_repo"
exit 0
fi
fi
if [[ -z "$GITLAB_TOKEN" ]]; then
debug "GITLAB_TOKEN undefined"
exit 0
fi
glenv="$task_repo/$GITLAB_ENV"
if [[ ! -f $glenv ]]; then
err "there must be a file '$glenv' defining gitlab env variables"
fi
source $glenv
if [[ "$task_name" != *$gitlab_prefix* ]]; then
info "'$task_name': does not contain gitlab_prefix: $gitlab_prefix"
exit 0
fi
issue_id=$(echo $task_name | cut -d'-' -f2)
if [[ $(nan $issue_id) == true ]]; then
err "couldn't determine issue id from task name: '$task_name', current time spent won't be sent."
exit 0
fi
duration=$($MYDIR/spent.sh $issue_id)
if [[ -z "$duration" ]]; then
err "couldn't determine time spent on task id '$issue_id' since last execution"
elif [[ "$duration" != '0m' ]]; then
info "marking '$duration' as spent on '$issue_id' ..."
$MYDIR/gitlab-api.sh POST "projects/$GITLAB_PID/issues/$issue_id/add_spent_time?duration=$duration"
fi