-
Notifications
You must be signed in to change notification settings - Fork 0
/
sd-workflow.bash
256 lines (219 loc) · 5.81 KB
/
sd-workflow.bash
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
alias @linked="find ./node_modules -maxdepth 1 -type l -printf '%p\n'"
alias @rebase='git fetch && git fetch upstream && git rebase upstream/master'
alias @getCurrentBranchName='git branch | grep ^* | cut -c 3-'
@jira() {
# @jira "Title" "optional description" - creates a new ticket
if [ -z "$1" ]
then
echo "Specify task title"
return
fi
curl -X POST --data "{\"fields\": {\"project\":{\"key\": \"SDESK\"},\"summary\": \"$1\",\"description\": \"$2\",\"issuetype\": { \"name\": \"Bug\"},\"customfield_10580\": { \"id\": \"10742\" }}}" -H "Content-Type: application/json" -H "Cookie: crowd.token_key=$config__jira_cookie" https://dev.sourcefabric.org/rest/api/2/issue/
}
@sdRestart() {
curl\
-L\
-H "Cookie: AIOHTTP_SESSION=$config__fireq_cookie"\
https://test.superdesk.org/sd/heads/master/restart
}
@branchCreate() {
if [ -z "$1" ]
then
echo "No argument supplied"
return
fi
git checkout -b $1
}
@getTaskTitle() {
if [ -z "$1" ]
then
echo "No argument supplied"
return
fi
curl \
-s \
-X GET \
-H "Content-Type: application/json" \
-H "Cookie: crowd.token_key=$config__jira_cookie" \
"https://dev.sourcefabric.org/rest/api/2/issue/$1" \
| python3 -c "\
import sys,json,re;\
j=json.load(sys.stdin);\
sys.stdout.write(re.sub(r'[^a-zA-Z0-9]', '-', j['fields']['summary']).lower().strip('-') + '-(' + j['key'] + ')')"
}
@getTaskReporter() {
if [ -z "$1" ]
then
echo "No argument supplied"
return
fi
curl \
-s \
-X GET \
-H "Content-Type: application/json" \
-H "Cookie: crowd.token_key=$config__jira_cookie" \
"https://dev.sourcefabric.org/rest/api/2/issue/$1" \
| python3 -c "\
import sys,json,re;\
j=json.load(sys.stdin);\
sys.stdout.write(j['fields']['reporter']['name'])"
}
@transformDashDelimitedStringToSentence() {
if [ -z "$1" ]
then
echo "No argument supplied"
return
fi
echo $1 | python3 -c "\
import sys,json,re;\
name = re.sub(r'-', ' ', sys.stdin.read());\
sys.stdout.write(name[0].capitalize() + name[1:])"
}
@getCurrentSprint() {
# 57 for board "Superdesk Editorial Agile"
curl \
-s \
-X GET \
-H "Content-Type: application/json" \
-H "Cookie: crowd.token_key=$config__jira_cookie" \
"https://dev.sourcefabric.org/rest/agile/1.0/board/57/sprint?state=active"\
| python3 -c "\
import sys,json,re;\
j=json.load(sys.stdin);\
sys.stdout.write(str(j['values'][0]['id']))"
}
@getTaskIdFromString() {
if [ -z "$1" ]
then
echo "No argument supplied"
return
fi
echo $1 | grep -E --only-match "\(.+\)" | grep -E --only-match [^\(\)]+ | tr -d '\n'
}
@getTaskIdFromBranchName() {
git branch | grep ^* | grep -E --only-match "\(.+\)" | grep -E --only-match [^\(\)]+
}
@changeTaskStatus() {
if [ -z "$1" ]
then
echo "No argument supplied"
return
fi
if [ -z "$2" ]
then
echo "No argument supplied"
return
fi
curl \
-s \
-X POST \
--data "{\"transition\":{\"id\": $2}}" \
-H "Content-Type: application/json" \
-H "Cookie: crowd.token_key=$config__jira_cookie" \
"https://dev.sourcefabric.org/rest/api/2/issue/$1/transitions"
}
@jiraAssignTaskToUser() {
if [ -z "$1" ]
then
echo "No argument supplied"
return
fi
curl \
-s \
-X PUT \
--data "{\"fields\":{\"assignee\":{\"name\":\"$2\"}}}" \
-H "Content-Type: application/json" \
-H "Cookie: crowd.token_key=$config__jira_cookie" \
"https://dev.sourcefabric.org/rest/api/2/issue/$1"
}
@jiraAssignToQa(){
if [ -z "$1" ]
then
echo "No argument supplied"
return
fi
reporter="$(@getTaskReporter $1)"
if [ $reporter = 'nareg' ] || [ $reporter = 'migelek' ]
then echo "assigning to reporter:$reporter"; @jiraAssignTaskToUser $1 $reporter
elif [ $(( ( RANDOM % 2 ) )) -eq 0 ]
then echo "assigning randomly: nareg"; @jiraAssignTaskToUser $1 "nareg"
else echo "assigning randomly: migelek"; @jiraAssignTaskToUser $1 "migelek"
fi
}
@jiraPutTaskToSprint() {
if [ -z "$1" ]
then
echo "No argument supplied"
return
fi
curl \
-s \
-X POST \
--data "{\"issues\":[\"$1\"]}" \
-H "Content-Type: application/json" \
-H "Cookie: crowd.token_key=$config__jira_cookie" \
"https://dev.sourcefabric.org/rest/agile/1.0/sprint/$2/issue"
}
@moveTaskToReview() {
@changeTaskStatus $1 5
}
@taskStart() {
if [ -z "$1" ]
then
echo "No argument supplied"
return
fi
@validateThatThereAreNoUncommitedChanges \
&& git checkout master \
&& @rebase \
&& @branchCreate "$(@getTaskTitle $1)" \
&& @jiraPutTaskToSprint $1 "$(@getCurrentSprint)" \
&& @jiraAssignTaskToUser $1 "$config__jira_username" \
&& @changeTaskStatus $1 4 # 4 for in progress
}
@validateThatThereAreNoUncommitedChanges() {
if ! [ -z "$(git status -s)" ]
then
echo "There are uncommited changes"
false
else
true
fi
}
@taskFinish() {
npm run test \
&& @validateThatThereAreNoUncommitedChanges \
&& git push --set-upstream origin "$(@getCurrentBranchName)" \
&& echo $(@transformDashDelimitedStringToSentence "$(@getCurrentBranchName)")$'\n'$(@getTaskIdFromBranchName) | hub pull-request -F - \
&& @moveTaskToReview "$(@getTaskIdFromBranchName)" \
&& git checkout master
}
@checkoutpr() {
if [ -z "$1" ]
then
echo "No argument supplied"
return
fi
git fetch upstream pull/$1/head:"pr-$1"
}
@reviewpr() {
if [ -z "$1" ]
then
echo "No argument supplied"
return
fi
@checkoutpr $1 && @rebase && git merge --squash "pr-$1" && git commit --no-edit && git reset HEAD~1
}
@review-commit() {
if [ -z "$1" ]
then
echo "No argument supplied. First arg for PR id"
return
fi
if [ -z "$1" ]
then
echo "No argument supplied. Second arg for commit hash"
return
fi
@checkoutpr $1 && git checkout "pr-$1" && git reset --hard "$2" && git reset HEAD~1
}