Replace the weird magic trap-waterfall-style flow in report_errors.sh with normal calls

This commit is contained in:
Kamil Śliwak 2021-01-15 21:09:45 +01:00
parent 5958e8d9ea
commit ca7327ec3f
2 changed files with 6 additions and 15 deletions

View File

@ -2,8 +2,6 @@
ERROR_LOG="$(mktemp -t check_style_XXXXXX.log)"
. scripts/report_errors.sh
EXCLUDE_FILES=(
"libsolutil/picosha2.h"
"test/libsolutil/UTF8.cpp"
@ -23,6 +21,7 @@ if [[ "$WHITESPACE" != "" ]]
then
echo "Error: Trailing whitespace found:" | tee -a $ERROR_LOG
echo "$WHITESPACE" | tee -a $ERROR_LOG
scripts/report_errors.sh "$ERROR_LOG"
exit 1
fi
@ -51,6 +50,7 @@ if [[ "$FORMATERROR" != "" ]]
then
echo "Coding style error:" | tee -a $ERROR_LOG
echo "$FORMATERROR" | tee -a $ERROR_LOG
scripts/report_errors.sh "$ERROR_LOG"
exit 1
fi
)

View File

@ -1,12 +1,9 @@
#!/usr/bin/env bash
ERROR_LOG="$1"
function report_error_to_github
{
if [ $? -eq 0 ]
then
exit 0
fi
if [ -z $CIRCLE_PR_NUMBER ]
then
CIRCLE_PR_NUMBER="${CIRCLE_PULL_REQUEST//[^0-9]/}"
@ -20,16 +17,12 @@ function report_error_to_github
then
echo "posting error message to github"
post_error_to_github
post_review_comment_to_github
fi
}
function post_error_to_github
{
if [ -z $CIRCLE_PR_NUMBER ]
then
CIRCLE_PR_NUMBER="${CIRCLE_PULL_REQUEST//[^0-9]/}"
fi
GITHUB_API_URL="https://api.github.com/repos/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/issues/$CIRCLE_PR_NUMBER/comments"
ESCAPED_ERROR_MSG=$(cat -e $ERROR_LOG | sed 's/\\/\\\\/g' | sed 's/"/\\\"/g')
@ -42,8 +35,6 @@ function post_error_to_github
--header 'content-type: application/json' \
-u stackenbotten:$GITHUB_ACCESS_TOKEN \
--data "{\"body\": \"There was an error when running \`$CIRCLE_JOB\` for commit \`$CIRCLE_SHA1\`:\n\`\`\`\n$FORMATTED_ERROR_MSG\n\`\`\`\nPlease check that your changes are working as intended.\"}"
post_review_comment_to_github
}
function post_review_comment_to_github
@ -66,4 +57,4 @@ function post_review_comment_to_github
done < $ERROR_LOG
}
trap report_error_to_github EXIT
report_error_to_github