0
0
Fork 0
mirror of https://github.com/netdata/netdata.git synced 2025-04-27 06:10:43 +00:00

cleaner labeler code ()

This commit is contained in:
Paweł Krupa 2018-12-06 15:19:19 +01:00 committed by GitHub
parent c2d3a61edc
commit 31f14e5855
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,6 +3,19 @@
# This is a simple script which should apply labels to unlabelled issues from last 3 days.
# It will soon be deprecated by GitHub Actions so no futher development on it is planned.
add_labels() {
ISSUE="$1"
URL="https://api.github.com/repos/netdata/netdata/issues/$ISSUE/labels"
# deduplicate array and add quotes
SET=( $(for i in "${@:2}"; do echo "\"$i\""; done | sort -u) )
# implode array to string
LABELS="${SET[*]}"
# add commas between quotes (replace spaces)
LABELS="${LABELS//\" \"/\",\"}"
echo "-------- Assigning labels to #${ISSUE}: ${LABELS} --------"
curl -H "Authorization: token $GITHUB_TOKEN" -d "{\"labels\":[${LABELS}]}" -X POST "${URL}"
}
if [ "$GITHUB_TOKEN" == "" ]; then
echo "GITHUB_TOKEN is needed"
exit 1
@ -24,13 +37,12 @@ echo "===== Categorizing issues ====="
for STATE in "open" "closed"; do
for ISSUE in $(hub issue -f "%I %l%n" -s "$STATE" -d "$(date +%F -d '1 day ago')" | grep -v -f $LABELS_FILE); do
echo "-------- Processing $STATE issue no. $ISSUE --------"
URL="https://api.github.com/repos/netdata/netdata/issues/$ISSUE"
BODY="$(curl "${URL}" 2>/dev/null | jq .body)"
BODY="$(curl "https://api.github.com/repos/netdata/netdata/issues/$ISSUE" 2>/dev/null | jq .body)"
case "${BODY}" in
*"# Question summary"*) curl -H "Authorization: token $GITHUB_TOKEN" -d '{"labels":["question", "no changelog"]}' -X POST "${URL}/labels" ;;
*"# Bug report summary"*) curl -H "Authorization: token $GITHUB_TOKEN" -d '{"labels":["needs triage","bug"]}' -X POST "${URL}/labels" ;;
*"# Feature idea summary"*) curl -H "Authorization: token $GITHUB_TOKEN" -d '{"labels":["needs triage","feature request"]}' -X POST "${URL}/labels" ;;
*) curl -H "Authorization: token $GITHUB_TOKEN" -d '{"labels":["needs triage", "no changelog"]}' -X POST "${URL}/labels" ;;
*"# Question summary"*) add_labels "$ISSUE" "question" "no changelog" ;;
*"# Bug report summary"*) add_labels "$ISSUE" "needs triage" "bug" ;;
*"# Feature idea summary"*) add_labels "$ISSUE" "needs triage" "feature request" ;;
*) add_labels "$ISSUE" "needs triage" "no changelog" ;;
esac
done
done
@ -41,7 +53,6 @@ for PR in $(hub pr list -s all -f "%I%n" -L 10); do
echo "----- Processing PR #$PR -----"
echo "" >$NEW_LABELS
NEW_SET=""
URL="https://api.github.com/repos/netdata/netdata/issues/$PR"
DIFF_URL="https://github.com/netdata/netdata/pull/$PR.diff"
for FILE in $(curl -L "${DIFF_URL}" 2>/dev/null | grep "diff --git a/" | cut -d' ' -f3 | sort | uniq); do
LABEL=""
@ -63,7 +74,7 @@ for PR in $(hub pr list -s all -f "%I%n" -L 10); do
*) AREA=$(echo "$FILE" | cut -d'/' -f2) ;;
esac
LABEL="area/$AREA"
echo "--------- Selecting $LABEL due to $FILE --------"
echo "Selecting $LABEL due to $FILE"
if grep "$LABEL" "$LABELS_FILE"; then
echo "$LABEL" >>$NEW_LABELS
if [[ $LABEL =~ "external" ]]; then
@ -73,9 +84,8 @@ for PR in $(hub pr list -s all -f "%I%n" -L 10); do
echo "-------- Label '$LABEL' not available --------"
fi
done
NEW_SET=$(sort $NEW_LABELS | uniq | grep -v "^$" | sed -e 's/^/"/g;s/$/",/g' | tr -d '\n' | sed 's/.\{1\}$//')
NEW_SET=$(sort $NEW_LABELS | uniq)
if [ ! -z "$NEW_SET" ]; then
echo "-------- Assigning labels: ${NEW_SET} --------"
curl -H "Authorization: token $GITHUB_TOKEN" -d "{\"labels\":[${NEW_SET}]}" -X POST "${URL}/labels" &>/dev/null
add_labels "$PR" ${NEW_SET}
fi
done