diff --git a/.github/bot-pr-base.sh b/.github/bot-pr-base.sh index cdb0787c410..b261bf74324 100644 --- a/.github/bot-pr-base.sh +++ b/.github/bot-pr-base.sh @@ -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) diff --git a/.github/bot-pr-format-base.sh b/.github/bot-pr-format-base.sh index 8d213dcfe69..298f061cc87 100644 --- a/.github/bot-pr-format-base.sh +++ b/.github/bot-pr-format-base.sh @@ -7,23 +7,7 @@ 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="" -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. - PR_PAGE_FILES=$(api_get "$PR_URL/files?&per_page=100&page=${PAGE}" | jq -er '.[] | .filename' || :) - if [ "${PR_PAGE_FILES}" = "" ]; then - break - fi - echo "Retrieving PR file list - ${PAGE} pages" - 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 +PR_FILES=$(bot_get_all_changed_files ${PR_URL}) NUM=$(echo "${PR_FILES}" | wc -l) echo "PR has ${NUM} changed files" diff --git a/.github/label.sh b/.github/label.sh index 860e520720c..8849f53d01c 100755 --- a/.github/label.sh +++ b/.github/label.sh @@ -3,23 +3,7 @@ source .github/bot-pr-base.sh echo "Retrieving PR file list" -PR_FILES="" -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. - PR_PAGE_FILES=$(api_get "$PR_URL/files?&per_page=100&page=${PAGE}" | jq -er '.[] | .filename' || :) - if [ "${PR_PAGE_FILES}" = "" ]; then - break - fi - echo "Retrieving PR file list - ${PAGE} pages" - 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 +PR_FILES=$(bot_get_all_changed_files ${PR_URL}) NUM=$(echo "${PR_FILES}" | wc -l) echo "PR has ${NUM} changed files"