Skip to content

Commit

Permalink
Merge Add bot_get_all_changed_files and update label regex
Browse files Browse the repository at this point in the history
This PR adds a bot_pr helper function to get all changed files and update label regex

- new helper function `bot_get_all_changed_files <pr_url>` to get all changed files from `pr_url`
- put quote if the regex uses some special characters like `\.`, `|`, or `$` and add `.github` match for `reg:ci-cd`

Related PR: #689
  • Loading branch information
yhmtsai committed Jan 7, 2021
2 parents 5259383 + 682d120 commit 81df3be
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
21 changes: 21 additions & 0 deletions .github/bot-pr-base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,27 @@ bot_error() {
exit 1
}

bot_get_all_changed_files() {
local pr_url="$1"
local pr_files=""
local page="1"
while true; do
# this api allows 100 items per page
# github action uses `bash -e`. The last empty page will leads jq error, use `|| :` to ignore the error.
local pr_page_files=$(api_get "$pr_url/files?&per_page=100&page=${page}" | jq -er '.[] | .filename' || :)
if [ "${pr_page_files}" = "" ]; then
break
fi
if [ ! "${pr_files}" = "" ]; then
# add the same new line format as jq output
pr_files="${pr_files}"$'\n'
fi
pr_files="${pr_files}${pr_page_files}"
page=$(( page + 1 ))
done
echo "${pr_files}"
}

# collect info on the user that invoked the bot
echo -n "Collecting information on triggering user"
USER_JSON=$(api_get $USER_URL)
Expand Down
5 changes: 4 additions & 1 deletion .github/bot-pr-format-base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ FORMAT_HEADER_REGEX='^(benchmark|core|cuda|hip|include/ginkgo/core|omp|reference
FORMAT_REGEX='^(common|examples|test_install)/'

echo "Retrieving PR file list"
PR_FILES="$(api_get "$PR_URL/files?&per_page=1000" | jq -er '.[] | .filename')"
PR_FILES=$(bot_get_all_changed_files ${PR_URL})
NUM=$(echo "${PR_FILES}" | wc -l)
echo "PR has ${NUM} changed files"

TO_FORMAT="$(echo "$PR_FILES" | grep -E $EXTENSION_REGEX || true)"

git remote add fork "$HEAD_URL"
Expand Down
20 changes: 11 additions & 9 deletions .github/label.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
source .github/bot-pr-base.sh

echo "Retrieving PR file list"
PR_FILES=$(api_get "$PR_URL/files?&per_page=1000" | jq -er '.[] | .filename')
PR_FILES=$(bot_get_all_changed_files ${PR_URL})
NUM=$(echo "${PR_FILES}" | wc -l)
echo "PR has ${NUM} changed files"

echo "Retrieving PR label list"
OLD_LABELS=$(api_get "$ISSUE_URL" | jq -er '[.labels | .[] | .name]')
Expand All @@ -17,18 +19,18 @@ label_match() {

LABELS="[]"
LABELS=$LABELS$(label_match mod:core '(^core/|^include/)')
LABELS=$LABELS$(label_match mod:reference ^reference/)
LABELS=$LABELS$(label_match mod:openmp ^omp/)
LABELS=$LABELS$(label_match mod:reference '^reference/')
LABELS=$LABELS$(label_match mod:openmp '^omp/')
LABELS=$LABELS$(label_match mod:cuda '(^cuda/|^common/)')
LABELS=$LABELS$(label_match mod:hip '(^hip/|^common/)')
LABELS=$LABELS$(label_match mod:dpcpp ^dpcpp/)
LABELS=$LABELS$(label_match reg:benchmarking ^benchmark/)
LABELS=$LABELS$(label_match reg:example ^examples/)
LABELS=$LABELS$(label_match mod:dpcpp '^dpcpp/')
LABELS=$LABELS$(label_match reg:benchmarking '^benchmark/')
LABELS=$LABELS$(label_match reg:example '^examples/')
LABELS=$LABELS$(label_match reg:build '(cm|CM)ake')
LABELS=$LABELS$(label_match reg:ci-cd '.yml$')
LABELS=$LABELS$(label_match reg:documentation ^doc/)
LABELS=$LABELS$(label_match reg:ci-cd '(^\.github/|\.yml$)')
LABELS=$LABELS$(label_match reg:documentation '^doc/')
LABELS=$LABELS$(label_match reg:testing /test/)
LABELS=$LABELS$(label_match reg:helper-scripts ^dev_tools/)
LABELS=$LABELS$(label_match reg:helper-scripts '^dev_tools/')
LABELS=$LABELS$(label_match type:factorization /factorization/)
LABELS=$LABELS$(label_match type:matrix-format /matrix/)
LABELS=$LABELS$(label_match type:multigrid /multigrid/)
Expand Down

0 comments on commit 81df3be

Please sign in to comment.