Skip to content

Commit

Permalink
move get_all_changed to bot-pr-base
Browse files Browse the repository at this point in the history
Co-authored-by: Tobias Ribizel <ribizel@kit.edu>
  • Loading branch information
yhmtsai and upsj committed Jan 6, 2021
1 parent d9c950a commit c2c8c55
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 34 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
18 changes: 1 addition & 17 deletions .github/bot-pr-format-base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
18 changes: 1 addition & 17 deletions .github/label.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit c2c8c55

Please sign in to comment.