@cryptotaxi247 / netdata-1 / commits / 31f14e585

cleaner labeler code (#4933)

Paweł Krupa committed Dec 6, 2018 at 15:19 UTC 31f14e5855c133aefba4aa91a5466f19bb1be540
1 file changed +21 -11
.travis/labeler.sh
+21 -11
@@ -3,6 +3,19 @@
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() {
7 + ISSUE="$1"
8 + URL="https://api.github.com/repos/netdata/netdata/issues/$ISSUE/labels"
9 + # deduplicate array and add quotes
10 + SET=( $(for i in "${@:2}"; do echo "\"$i\""; done | sort -u) )
11 + # implode array to string
12 + LABELS="${SET[*]}"
13 + # add commas between quotes (replace spaces)
14 + LABELS="${LABELS//\" \"/\",\"}"
15 + echo "-------- Assigning labels to #${ISSUE}: ${LABELS} --------"
16 + curl -H "Authorization: token $GITHUB_TOKEN" -d "{\"labels\":[${LABELS}]}" -X POST "${URL}"
17 +}
18 +
19 if [ "$GITHUB_TOKEN" == "" ]; then
20 echo "GITHUB_TOKEN is needed"
21 exit 1
@@ -24,13 +37,12 @@ echo "===== Categorizing issues ====="
37 for STATE in "open" "closed"; do
38 for ISSUE in $(hub issue -f "%I %l%n" -s "$STATE" -d "$(date +%F -d '1 day ago')" | grep -v -f $LABELS_FILE); do
39 echo "-------- Processing $STATE issue no. $ISSUE --------"
27 - URL="https://api.github.com/repos/netdata/netdata/issues/$ISSUE"
28 - BODY="$(curl "${URL}" 2>/dev/null | jq .body)"
40 + BODY="$(curl "https://api.github.com/repos/netdata/netdata/issues/$ISSUE" 2>/dev/null | jq .body)"
41 case "${BODY}" in
30 - *"# Question summary"*) curl -H "Authorization: token $GITHUB_TOKEN" -d '{"labels":["question", "no changelog"]}' -X POST "${URL}/labels" ;;
31 - *"# Bug report summary"*) curl -H "Authorization: token $GITHUB_TOKEN" -d '{"labels":["needs triage","bug"]}' -X POST "${URL}/labels" ;;
32 - *"# Feature idea summary"*) curl -H "Authorization: token $GITHUB_TOKEN" -d '{"labels":["needs triage","feature request"]}' -X POST "${URL}/labels" ;;
33 - *) curl -H "Authorization: token $GITHUB_TOKEN" -d '{"labels":["needs triage", "no changelog"]}' -X POST "${URL}/labels" ;;
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 esac
47 done
48 done
@@ -41,7 +53,6 @@ for PR in $(hub pr list -s all -f "%I%n" -L 10); do
53 echo "----- Processing PR #$PR -----"
54 echo "" >$NEW_LABELS
55 NEW_SET=""
44 - URL="https://api.github.com/repos/netdata/netdata/issues/$PR"
56 DIFF_URL="https://github.com/netdata/netdata/pull/$PR.diff"
57 for FILE in $(curl -L "${DIFF_URL}" 2>/dev/null | grep "diff --git a/" | cut -d' ' -f3 | sort | uniq); do
58 LABEL=""
@@ -63,7 +74,7 @@ for PR in $(hub pr list -s all -f "%I%n" -L 10); do
74 *) AREA=$(echo "$FILE" | cut -d'/' -f2) ;;
75 esac
76 LABEL="area/$AREA"
66 - echo "--------- Selecting $LABEL due to $FILE --------"
77 + echo "Selecting $LABEL due to $FILE"
78 if grep "$LABEL" "$LABELS_FILE"; then
79 echo "$LABEL" >>$NEW_LABELS
80 if [[ $LABEL =~ "external" ]]; then
@@ -73,9 +84,8 @@ for PR in $(hub pr list -s all -f "%I%n" -L 10); do
84 echo "-------- Label '$LABEL' not available --------"
85 fi
86 done
76 - NEW_SET=$(sort $NEW_LABELS | uniq | grep -v "^$" | sed -e 's/^/"/g;s/$/",/g' | tr -d '\n' | sed 's/.\{1\}$//')
87 + NEW_SET=$(sort $NEW_LABELS | uniq)
88 if [ ! -z "$NEW_SET" ]; then
78 - echo "-------- Assigning labels: ${NEW_SET} --------"
79 - curl -H "Authorization: token $GITHUB_TOKEN" -d "{\"labels\":[${NEW_SET}]}" -X POST "${URL}/labels" &>/dev/null
89 + add_labels "$PR" ${NEW_SET}
90 fi
91 done