From 5c67821af48c307d4b3da9b0cc50b4d447e8eae2 Mon Sep 17 00:00:00 2001 From: Chris Purta Date: Wed, 14 Nov 2018 15:05:20 -0800 Subject: Script that directly comments errors to the github pull request. --- scripts/check_style.sh | 10 ++++++---- scripts/report_errors.sh | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 4 deletions(-) create mode 100755 scripts/report_errors.sh (limited to 'scripts') diff --git a/scripts/check_style.sh b/scripts/check_style.sh index 4f716d66..171867f9 100755 --- a/scripts/check_style.sh +++ b/scripts/check_style.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +. scripts/report_errors.sh + ( REPO_ROOT="$(dirname "$0")"/.. cd $REPO_ROOT @@ -8,8 +10,8 @@ WHITESPACE=$(git grep -n -I -E "^.*[[:space:]]+$" | grep -v "test/libsolidity/AS if [[ "$WHITESPACE" != "" ]] then - echo "Error: Trailing whitespace found:" >&2 - echo "$WHITESPACE" >&2 + echo "Error: Trailing whitespace found:" | tee -a $ERROR_LOG + echo "$WHITESPACE" | tee -a $ERROR_LOG exit 1 fi @@ -22,8 +24,8 @@ git grep -nIE "\\s*\(.*\)\s*\{\s*$" -- '*.h' '*.cpp' if [[ "$FORMATERROR" != "" ]] then - echo "Error: Format error for if/for:" >&2 - echo "$FORMATERROR" >&2 + echo "Error: Format error for if/for:" | tee -a $ERROR_LOG + echo "$FORMATERROR" | tee -a $ERROR_LOG exit 1 fi ) diff --git a/scripts/report_errors.sh b/scripts/report_errors.sh new file mode 100755 index 00000000..55fc2e8c --- /dev/null +++ b/scripts/report_errors.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +export ERROR_LOG="/tmp/error.log" + +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]/}" + fi + + ERROR_MSG=$(cat $ERROR_LOG) + + echo $ERROR_MSG + + if [ ! -z $CI ] + then + echo "posting error message to github" + post_error_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') + + FORMATTED_ERROR_MSG=$(echo $ESCAPED_ERROR_MSG | sed 's/\$/\\n/g' | tr -d '\n') + + curl --request POST \ + --url $GITHUB_API_URL \ + --header 'accept: application/vnd.github.v3+json' \ + --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.\"}" +} + +trap report_error_to_github EXIT -- cgit