mirror of
https://github.com/netdata/netdata.git
synced 2025-04-30 23:50:04 +00:00
cleaner labeler code (#4933)
This commit is contained in:
parent
c2d3a61edc
commit
31f14e5855
1 changed files with 21 additions and 11 deletions
|
@ -3,6 +3,19 @@
|
||||||
# This is a simple script which should apply labels to unlabelled issues from last 3 days.
|
# 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.
|
# 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
|
if [ "$GITHUB_TOKEN" == "" ]; then
|
||||||
echo "GITHUB_TOKEN is needed"
|
echo "GITHUB_TOKEN is needed"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -24,13 +37,12 @@ echo "===== Categorizing issues ====="
|
||||||
for STATE in "open" "closed"; do
|
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
|
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 --------"
|
echo "-------- Processing $STATE issue no. $ISSUE --------"
|
||||||
URL="https://api.github.com/repos/netdata/netdata/issues/$ISSUE"
|
BODY="$(curl "https://api.github.com/repos/netdata/netdata/issues/$ISSUE" 2>/dev/null | jq .body)"
|
||||||
BODY="$(curl "${URL}" 2>/dev/null | jq .body)"
|
|
||||||
case "${BODY}" in
|
case "${BODY}" in
|
||||||
*"# Question summary"*) curl -H "Authorization: token $GITHUB_TOKEN" -d '{"labels":["question", "no changelog"]}' -X POST "${URL}/labels" ;;
|
*"# Question summary"*) add_labels "$ISSUE" "question" "no changelog" ;;
|
||||||
*"# Bug report summary"*) curl -H "Authorization: token $GITHUB_TOKEN" -d '{"labels":["needs triage","bug"]}' -X POST "${URL}/labels" ;;
|
*"# Bug report summary"*) add_labels "$ISSUE" "needs triage" "bug" ;;
|
||||||
*"# Feature idea summary"*) curl -H "Authorization: token $GITHUB_TOKEN" -d '{"labels":["needs triage","feature request"]}' -X POST "${URL}/labels" ;;
|
*"# Feature idea summary"*) add_labels "$ISSUE" "needs triage" "feature request" ;;
|
||||||
*) curl -H "Authorization: token $GITHUB_TOKEN" -d '{"labels":["needs triage", "no changelog"]}' -X POST "${URL}/labels" ;;
|
*) add_labels "$ISSUE" "needs triage" "no changelog" ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
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 "----- Processing PR #$PR -----"
|
||||||
echo "" >$NEW_LABELS
|
echo "" >$NEW_LABELS
|
||||||
NEW_SET=""
|
NEW_SET=""
|
||||||
URL="https://api.github.com/repos/netdata/netdata/issues/$PR"
|
|
||||||
DIFF_URL="https://github.com/netdata/netdata/pull/$PR.diff"
|
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
|
for FILE in $(curl -L "${DIFF_URL}" 2>/dev/null | grep "diff --git a/" | cut -d' ' -f3 | sort | uniq); do
|
||||||
LABEL=""
|
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) ;;
|
*) AREA=$(echo "$FILE" | cut -d'/' -f2) ;;
|
||||||
esac
|
esac
|
||||||
LABEL="area/$AREA"
|
LABEL="area/$AREA"
|
||||||
echo "--------- Selecting $LABEL due to $FILE --------"
|
echo "Selecting $LABEL due to $FILE"
|
||||||
if grep "$LABEL" "$LABELS_FILE"; then
|
if grep "$LABEL" "$LABELS_FILE"; then
|
||||||
echo "$LABEL" >>$NEW_LABELS
|
echo "$LABEL" >>$NEW_LABELS
|
||||||
if [[ $LABEL =~ "external" ]]; then
|
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 --------"
|
echo "-------- Label '$LABEL' not available --------"
|
||||||
fi
|
fi
|
||||||
done
|
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
|
if [ ! -z "$NEW_SET" ]; then
|
||||||
echo "-------- Assigning labels: ${NEW_SET} --------"
|
add_labels "$PR" ${NEW_SET}
|
||||||
curl -H "Authorization: token $GITHUB_TOKEN" -d "{\"labels\":[${NEW_SET}]}" -X POST "${URL}/labels" &>/dev/null
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue