allow label modification (#4949)
Paweł Krupa committed
Dec 12, 2018 at 10:58 UTC
6ef4097dd9a5747a34a27222e2c129a3c802bb4e
1 file changed
+14
-7
.travis/labeler.sh
+14
-7
@@ -3,7 +3,8 @@
3
# This is a simple script which should apply labels to unlabelled issues from last 3 days.
4
# It will soon be deprecated by GitHub Actions so no futher development on it is planned.
5
6
-add_labels() {
6
+# Previously this was using POST to only add labels. But this method seems to be failing with larger number of requests
7
+new_labels() {
8
ISSUE="$1"
9
URL="https://api.github.com/repos/netdata/netdata/issues/$ISSUE/labels"
10
# deduplicate array and add quotes
@@ -12,8 +13,10 @@ add_labels() {
13
LABELS="${SET[*]}"
14
# add commas between quotes (replace spaces)
15
LABELS="${LABELS//\" \"/\",\"}"
16
+ # remove duplicate quotes in case parameters were already quoted
17
+ LABELS="${LABELS//\"\"/\"}"
18
echo "-------- Assigning labels to #${ISSUE}: ${LABELS} --------"
16
- curl -H "Authorization: token $GITHUB_TOKEN" -d "{\"labels\":[${LABELS}]}" -X POST "${URL}"
19
+ curl -H "Authorization: token $GITHUB_TOKEN" -d "{\"labels\":[${LABELS}]}" -X PUT "${URL}" &>/dev/null
20
}
21
22
if [ "$GITHUB_TOKEN" == "" ]; then
@@ -34,19 +37,21 @@ LABELS_FILE=/tmp/labels
37
hub issue labels >$LABELS_FILE
38
39
echo "===== Categorizing issues ====="
40
+# This won't touch issues which already have at least one label assigned
41
for STATE in "open" "closed"; do
42
for ISSUE in $(hub issue -f "%I %l%n" -s "$STATE" -d "$(date +%F -d '1 day ago')" | grep -v -f $LABELS_FILE); do
43
echo "-------- Processing $STATE issue no. $ISSUE --------"
44
BODY="$(curl "https://api.github.com/repos/netdata/netdata/issues/$ISSUE" 2>/dev/null | jq .body)"
45
case "${BODY}" in
42
- *"# Question summary"*) add_labels "$ISSUE" "question" "no changelog" ;;
43
- *"# Bug report summary"*) add_labels "$ISSUE" "needs triage" "bug" ;;
44
- *"# Feature idea summary"*) add_labels "$ISSUE" "needs triage" "feature request" ;;
45
- *) add_labels "$ISSUE" "needs triage" "no changelog" ;;
46
+ *"# Question summary"*) new_labels "$ISSUE" "question" "no changelog" ;;
47
+ *"# Bug report summary"*) new_labels "$ISSUE" "needs triage" "bug" ;;
48
+ *"# Feature idea summary"*) new_labels "$ISSUE" "needs triage" "feature request" ;;
49
+ *) new_labels "$ISSUE" "needs triage" "no changelog" ;;
50
esac
51
done
52
done
53
54
+# Change all 'area' labels assigned to PR saving non-area labels.
55
echo "===== Categorizing PRs ====="
56
NEW_LABELS=/tmp/new_labels
57
for PR in $(hub pr list -s all -f "%I%n" -L 10); do
@@ -86,6 +91,8 @@ for PR in $(hub pr list -s all -f "%I%n" -L 10); do
91
done
92
NEW_SET=$(sort $NEW_LABELS | uniq)
93
if [ ! -z "$NEW_SET" ]; then
89
- add_labels "$PR" ${NEW_SET}
94
+ PREV=$(curl "https://api.github.com/repos/netdata/netdata/issues/$PR/labels" 2>/dev/null | jq '.[].name' | grep -v "area")
95
+ new_labels "$PR" ${NEW_SET} "${PREV[*]}"
96
+ exit 0
97
fi
98
done