-
Notifications
You must be signed in to change notification settings - Fork 0
/
rr-comment.sh
executable file
·60 lines (49 loc) · 1.2 KB
/
rr-comment.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
#!/bin/bash -e
# @installable
MYSELF="$(readlink -f "$0")"
MYDIR="${MYSELF%/*}"
ME=$(basename $MYSELF)
source $MYDIR/env
[[ -f $LOCAL_ENV ]] && source $LOCAL_ENV
source $MYDIR/log.sh
source $MYDIR/db.sh
id="$(db CURR_TASK_ID)"
name="$(db CURR_TASK_NAME)"
if [[ "$RR_ENABLED" != true ]]; then
debug "run run is not enabled"
exit 0
fi
debug "adding comment..."
comment="$1"
if [[ ! -n "$comment" ]]; then
err "first arg must be comment message"
exit 1
fi
comment=$(echo $comment)
debug "$comment"
if [[ "$comment" == --local ]]; then
shift
debug "inserting as local comment instad: $@"
$MYDIR/local-comment.sh "$@"
exit 0
fi
if [[ $(nan "$id") == true ]]; then
debug "trying to refresh current task..."
$MYDIR/rr-sync-task.sh
fi
if [[ $(nan "$id") == true ]]; then
err "no tasks are running, can't comment"
exit 1
fi
json=$($MYDIR/runrun.sh POST comments "{
\"task_id\": $id,
\"text\": \"$comment\"
}")
if [[ "$json" == *'error'* ]]; then
err "error posting comment!"
exit 1
else
c_id=$(echo "$json" | $MYDIR/jprop.sh "['id']")
info "comment #$c_id posted: https://runrun.it/en-US/tasks/$(db CURR_TASK_ID)"
$MYDIR/local-comment.sh "$comment"
fi