From 5b05b8716a5e052d4ce2d59b4f7e29970a7704ba Mon Sep 17 00:00:00 2001 From: yandongxiao Date: Tue, 28 Nov 2023 20:20:42 +0800 Subject: [PATCH] [Chore] add more labels based on PR title (#325) Signed-off-by: yandongxiao --- scripts/add-labels-to-pr.sh | 36 ++++++++++++++++++++++++++++++ scripts/add-version-label-to-pr.sh | 17 -------------- 2 files changed, 36 insertions(+), 17 deletions(-) create mode 100644 scripts/add-labels-to-pr.sh delete mode 100644 scripts/add-version-label-to-pr.sh diff --git a/scripts/add-labels-to-pr.sh b/scripts/add-labels-to-pr.sh new file mode 100644 index 00000000..8bd47a06 --- /dev/null +++ b/scripts/add-labels-to-pr.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# input parameters: a list of PR numbers and a version tag +# e.g. v1.8.6 1 2 3 4 5 +VERSION_TAG=$1 + +# create label by gh +gh label create $VERSION_TAG + +shift +PR_NUMBERS=("$@") + +# define an array of keywords +KEYWORDS=("feature" "enhancement" "bugfix" "chore" "documentation") + +# iterate over the list of PR numbers +for PR_NUMBER in "${PR_NUMBERS[@]}"; do + # add a version label to each PR + gh pr edit $PR_NUMBER --add-label "$VERSION_TAG" + + # get the PR title + PR_TITLE=$(gh pr view $PR_NUMBER --json title -q '.title') + + # convert PR title to lowercase + PR_TITLE=$(echo "$PR_TITLE" | tr '[:upper:]' '[:lower:]') + + # check if the PR title contains any of the keywords + for KEYWORD in "${KEYWORDS[@]}"; do + if [[ $PR_TITLE == *"$KEYWORD"* ]]; then + # create the label if it doesn't exist + gh label create $KEYWORD 2>/dev/null + # add the label to the PR + gh pr edit $PR_NUMBER --add-label "$KEYWORD" + fi + done +done diff --git a/scripts/add-version-label-to-pr.sh b/scripts/add-version-label-to-pr.sh deleted file mode 100644 index 2cf585f4..00000000 --- a/scripts/add-version-label-to-pr.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -# input parameters: a list of PR numbers and a version tag -# e.g. v1.8.6 1 2 3 4 5 -VERSION_TAG=$1 - -# create label by gh -gh label create $VERSION_TAG - -shift -PR_NUMBERS=("$@") - -# iterate over the list of PR numbers -for PR_NUMBER in "${PR_NUMBERS[@]}"; do - # add a version label to each PR - gh pr edit $PR_NUMBER --add-label "$VERSION_TAG" -done