-
Notifications
You must be signed in to change notification settings - Fork 0
/
rr-new-task.sh
executable file
·137 lines (120 loc) · 3.23 KB
/
rr-new-task.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
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
#!/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
if [[ "$RR_ENABLED" != true ]]; then
debug "run run is not enabled"
exit 0
fi
name="$1"
if [[ ! -n "$name" || "$name" == '-'* ]]; then
err "arg 1 must be task name"
exit 1
fi
info "creating runrun task '$name' ..."
project_id="$(db CURR_PROJECT_ID)"
type=$(db CURR_TASK_TYPE)
team=$(db CURR_TASK_TEAM)
while test $# -gt 0
do
case "$1" in
--like)
shift
lid=$1
task=$($MYDIR/runrun.sh GET "tasks/$lid")
if [[ ! -n "$task" ]]; then
err "task #$lid not found"
exit 1
fi
project_id=$(echo "$task" | $MYDIR/jprop.sh "['project_id']")
type=$(echo "$task" | $MYDIR/jprop.sh "['type_id']")
team=$(echo "$task" | $MYDIR/jprop.sh "['team_id']")
if [[ ! -n "$team" || "$team" == null || "$team" == None ]]; then
team=$(echo "$task" | $MYDIR/jprop.sh "['assignments'][0]['team_id']")
fi
;;
--everyone)
u_id=''
;;
--project|-p)
shift
project_id="$1"
;;
--description)
shift
description="$1"
;;
-*)
echo "bad option '$1'"
exit 1
;;
esac
shift
done
while [[ $(nan "$project_id") == true ]]; do
if [[ -z "$project_id" ]]; then
info "to start a new task you need to be working on a project. enter desired project name:"
read project_id
fi
project_id=$(prompt_project_id "$project_id")
done
info "project_id: $project_id"
debug "type: $type"
if [[ $(nan "$type") == true ]]; then
err "current task type is not set correctly. please run gclit-sync-task."
exit 1
fi
debug "team: $team"
if [[ $(nan "$team") == true ]]; then
err "current task team is not set correctly. please run gclit-sync-task."
exit 1
fi
debug "checking if $name already exists..."
matches="$($MYDIR/rr-find-task.sh "$name" -p "$project_id")"
if [[ -n "$matches" ]]; then
err "task already exists:"
echo "$matches"
first=$($MYDIR/get.sh 1 "$matches" | cut -d'=' -f1)
info "playing the first (#$first)..."
$MYDIR/rr-play.sh $first
exit 0
fi
debug "creating task $name ..."
json=$($MYDIR/runrun.sh POST tasks "{
\"task\": {
\"scheduled_start_time\": null,
\"desired_date_with_time\": null,
\"on_going\": false,
\"project_id\": $project_id,
\"title\": \"$name\",
\"type_id\": $type,
\"assignments\": [
{
\"assignee_id\": \"$(rr_user_id)\",
\"team_id\": $team
}
]
}
}")
if [[ "$json" == *'error'* ]]; then
err "problem creating task '$name' on project #$project_id:"
echo "$json" | $MYDIR/jprop.sh "['errors']"
info "check cached response with $MYDIR/last-response.sh"
else
debug "parsing task response id..."
t_id=$(echo "$json" | $MYDIR/jprop.sh "['id']")
info "'$name' created with ID '$t_id'. playing..."
$MYDIR/rr-play.sh $t_id
if [[ -n "$description" ]]; then
$MYDIR/runrun.sh PUT "tasks/$t_id/description" "{
\"task_description\": {
\"description\": \"${description}\"
}
}"
fi
fi