summaryrefslogtreecommitdiffstats
path: root/.travis
diff options
context:
space:
mode:
authorPaweł Krupa <pawel@krupa.net.pl>2018-11-30 11:01:56 +0200
committerGitHub <noreply@github.com>2018-11-30 11:01:56 +0200
commit0cb72d21e879c96a02bcd450c5b61e9cc3a611d9 (patch)
treecf8406f710b9dcf56fe5bb28c14182bd133ce55a /.travis
parentbe04429f074c7da838227b20ca87d103465152e8 (diff)
auto-label PRs and minor cleanup (#4795)
Diffstat (limited to '.travis')
-rwxr-xr-x.travis/labeler.sh84
1 files changed, 65 insertions, 19 deletions
diff --git a/.travis/labeler.sh b/.travis/labeler.sh
index 770b2f747c..50c77cc500 100755
--- a/.travis/labeler.sh
+++ b/.travis/labeler.sh
@@ -4,30 +4,76 @@
# It will soon be deprecated by GitHub Actions so no futher development on it is planned.
if [ "$GITHUB_TOKEN" == "" ]; then
- echo "GITHUB_TOKEN is needed"
- exit 1
+ echo "GITHUB_TOKEN is needed"
+ exit 1
fi
# Download hub
-HUB_VERSION=${HUB_VERSION:-"2.5.1"}
-wget "https://github.com/github/hub/releases/download/v${HUB_VERSION}/hub-linux-amd64-${HUB_VERSION}.tgz" -O "/tmp/hub-linux-amd64-${HUB_VERSION}.tgz"
-tar -C /tmp -xvf "/tmp/hub-linux-amd64-${HUB_VERSION}.tgz" &>/dev/null
-export PATH=$PATH:"/tmp/hub-linux-amd64-${HUB_VERSION}/bin"
+if ! [ -x "$(command -v hub)" ]; then
+ HUB_VERSION=${HUB_VERSION:-"2.5.1"}
+ wget "https://github.com/github/hub/releases/download/v${HUB_VERSION}/hub-linux-amd64-${HUB_VERSION}.tgz" -O "/tmp/hub-linux-amd64-${HUB_VERSION}.tgz"
+ tar -C /tmp -xvf "/tmp/hub-linux-amd64-${HUB_VERSION}.tgz" &>/dev/null
+ export PATH=$PATH:"/tmp/hub-linux-amd64-${HUB_VERSION}/bin"
+fi
echo "Looking up available labels"
-LABELS_FILE=/tmp/exclude_labels
-hub issue labels > $LABELS_FILE
+LABELS_FILE=/tmp/labels
+hub issue labels >$LABELS_FILE
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}" | jq .body 2>/dev/null)"
- case "${BODY}" in
- *"# Question summary"* ) curl -H "Authorization: token $GITHUB_TOKEN" -d '{"labels":["question"]}' -X PATCH "${URL}" ;;
- *"# Bug report summary"* ) curl -H "Authorization: token $GITHUB_TOKEN" -d '{"labels":["needs triage","bug"]}' -X PATCH "${URL}" ;;
- *"# Feature idea summary"* ) curl -H "Authorization: token $GITHUB_TOKEN" -d '{"labels":["needs triage","feature request"]}' -X PATCH "${URL}" ;;
- * ) curl -H "Authorization: token $GITHUB_TOKEN" -d '{"labels":["needs triage"]}' -X PATCH "${URL}" ;;
- esac
- done
+ 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)"
+ case "${BODY}" in
+ *"# Question summary"*) curl -H "Authorization: token $GITHUB_TOKEN" -d '{"labels":["question"]}' -X PATCH "${URL}" ;;
+ *"# Bug report summary"*) curl -H "Authorization: token $GITHUB_TOKEN" -d '{"labels":["needs triage","bug"]}' -X PATCH "${URL}" ;;
+ *"# Feature idea summary"*) curl -H "Authorization: token $GITHUB_TOKEN" -d '{"labels":["needs triage","feature request"]}' -X PATCH "${URL}" ;;
+ *) curl -H "Authorization: token $GITHUB_TOKEN" -d '{"labels":["needs triage"]}' -X PATCH "${URL}" ;;
+ esac
+ done
+done
+
+NEW_LABELS=/tmp/new_labels
+for PR in $(hub pr list -s all -f "%I %l%n" -L 10); do
+ echo "-------------------------------------------------------"
+ 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=""
+ case "${FILE}" in
+ *".md") AREA="docs" ;;
+ *"/collectors/python.d.plugin/"*) AREA="external/python" ;;
+ *"/collectors/charts.d.plugin/"*) AREA="external" ;;
+ *"/collectors/node.d.plugin/"*) AREA="external" ;;
+ *"/.travis"*) AREA="ci" ;;
+ *"/.github/"*) AREA="ci" ;;
+ *"/build/"*) AREA="packaging" ;;
+ *"/contrib/"*) AREA="packaging" ;;
+ *"/diagrams/"*) AREA="docs" ;;
+ *"/installer/"*) AREA="packaging" ;;
+ *"/makeself/"*) AREA="packaging" ;;
+ *"/system/"*) AREA="packaging" ;;
+ *"/netdata-installer.sh"*) AREA="packaging" ;;
+ *) AREA=$(echo "$FILE" | cut -d'/' -f2) ;;
+ esac
+ LABEL="area/$AREA"
+ echo "Selecting $LABEL due to $FILE"
+ if grep "$LABEL" "$LABELS_FILE"; then
+ echo "$LABEL" >>$NEW_LABELS
+ if [[ $LABEL =~ "external" ]]; then
+ echo "area/collectors" >>$NEW_LABELS
+ fi
+ else
+ 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\}$//')
+ if [ ! -z "$NEW_SET" ]; then
+ echo "Assigning labels: ${NEW_SET}"
+ curl -H "Authorization: token $GITHUB_TOKEN" -d "{\"labels\":[${NEW_SET}]}" -X PATCH "${URL}" &>/dev/null
+ fi
done