-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·207 lines (190 loc) · 5.01 KB
/
entrypoint.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
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
#!/bin/bash
# Varun Chopra <[email protected]>
#
# This action runs every time a comment is added to a pull request.
# Accepts the following commands: shipit, needs_ci, needs_sandbox
set -e
if [[ -z "$GITHUB_TOKEN" ]]; then
echo "Set the GITHUB_TOKEN env variable."
exit 1
fi
if [[ -z "$GITHUB_REPOSITORY" ]]; then
echo "Set the GITHUB_REPOSITORY env variable."
exit 1
fi
if [[ -z "$GITHUB_EVENT_PATH" ]]; then
echo "Set the GITHUB_EVENT_PATH env variable."
exit 1
fi
add_label(){
curl -sSL \
-H "${AUTH_HEADER}" \
-H "${API_HEADER}" \
-X POST \
-H "Content-Type: application/json" \
-d "{\"labels\":[\"${1}\"]}" \
"${URI}/repos/${GITHUB_REPOSITORY}/issues/${number}/labels"
}
remove_label(){
curl -sSL \
-H "${AUTH_HEADER}" \
-H "${API_HEADER}" \
-X DELETE \
"${URI}/repos/${GITHUB_REPOSITORY}/issues/${number}/labels/${1}"
}
IFS=$'\n'
URI="https://api.github.com"
API_HEADER="Accept: application/vnd.github.v3+json"
AUTH_HEADER="Authorization: token ${GITHUB_TOKEN}"
# action
action=$(jq --raw-output .action "$GITHUB_EVENT_PATH")
comment_body=$(jq --raw-output .comment.body "$GITHUB_EVENT_PATH")
# Trim newlines, carriage returns and leading/trailing spaces
comment_body=$(echo "$comment_body" | grep -v '^[[:space:]]*$' | tr -d '\r' | tr -d '\n'| xargs)
number=$(jq --raw-output .issue.number "$GITHUB_EVENT_PATH")
labels=$(jq --raw-output .issue.labels[].name "$GITHUB_EVENT_PATH")
echo $action
echo $comment_body
echo $number
echo $labels
already_needs_ci=false
already_shipit=false
already_verified=false
already_needs_ci_lite=false
if [[ "$action" != "created" ]]; then
echo This action should only be called when a comment is created on a pull request
exit 0
fi
if [[ $comment_body == "shipit" || $comment_body == ":shipit:" || $comment_body == ":shipit: " || $comment_body == "sudo shipit"* || $comment_body == "sudo :shipit:"* ]]; then
for label in $labels; do
case $label in
ci_verified)
already_verified=true
;;
shipit)
already_shipit=true
;;
needs_ci)
already_needs_ci=true
;;
*)
echo "Unknown label $label"
;;
esac
done
if [[ "$already_verified" == false && "$already_needs_ci" == false ]]; then
add_label "needs_ci"
fi
if [[ "$already_shipit" == false ]]; then
add_label "shipit"
fi
exit 0
fi
if [[ $comment_body == "needs_ci" ]]; then
for label in $labels; do
case $label in
ci_verified)
remove_label "$label"
;;
needs_ci)
already_needs_ci=true
;;
*)
echo "Unknown label $label"
;;
esac
done
if [[ "$already_needs_ci" == false ]]; then
add_label "needs_ci"
fi
fi
if [[ $comment_body == "needs_ci:lite" ]]; then
for label in $labels; do
case $label in
ci_verified:lite)
remove_label "$label"
;;
needs_ci:lite)
already_needs_ci_lite=true
;;
*)
echo "Unknown label $label"
;;
esac
done
if [[ "$already_needs_ci_lite" == false ]]; then
add_label "needs_ci:lite"
fi
fi
# Add sandbox is needs_sandbox
# Remove stop_sandbox if sandbox is requested again
already_needs_sandbox=false
if [[ $comment_body =~ ^needs_sandbox(:(eu|gov|ca|uae|wu))?(:(dev|([0-9]+)(\.([0-9]+)?)?))?([ \t]*)?$ ]]; then
for label in $labels; do
case $label in
sandbox)
already_needs_sandbox=true
;;
"sandbox :united_arab_emirates:")
already_needs_sandbox=true
;;
"sandbox :eu:")
already_needs_sandbox=true
;;
"sandbox :maple_leaf:")
already_needs_sandbox=true
;;
"sandbox :classical_building:")
already_needs_sandbox=true
;;
"sandbox :us:")
already_needs_sandbox=true
;;
*)
echo "Unknown label $label"
;;
esac
done
if [[ "$already_needs_sandbox" == false ]]; then
if [[ $comment_body =~ needs_sandbox:eu ]]; then
add_label "sandbox :eu:"
elif [[ $comment_body =~ needs_sandbox:ca ]]; then
add_label "sandbox :maple_leaf:"
elif [[ $comment_body =~ needs_sandbox:gov ]]; then
add_label "sandbox :classical_building:"
elif [[ $comment_body =~ needs_sandbox:uae ]]; then
add_label "sandbox :united_arab_emirates:"
elif [[ $comment_body =~ needs_sandbox:wu ]]; then
add_label "sandbox :us:"
else
add_label "sandbox"
fi
fi
fi
if [[ $comment_body == "stop_sandbox" ]]; then
for label in $labels; do
case $label in
sandbox)
remove_label "sandbox"
;;
"sandbox :eu:")
remove_label "sandbox%20:eu:"
;;
"sandbox :maple_leaf:")
remove_label "sandbox%20:maple_leaf:"
;;
"sandbox :classical_building:")
remove_label "sandbox%20:classical_building:"
;;
"sandbox :united_arab_emirates:")
remove_label "sandbox%20:united_arab_emirates:"
;;
"sandbox :us:")
remove_label "sandbox%20:us:"
;;
*)
echo "Unknown label $label"
;;
esac
done
fi