Last active
October 13, 2019 04:14
-
-
Save hectorv/ead6d69875f4ba8487b9d921e73002bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set +x | |
set -eu | |
echo | |
# Posting pending status on PR | |
curl -s -X POST \ | |
"https://api.github.com/repos/${ghprbGhRepository}/statuses/${ghprbActualCommit}" \ | |
-H "Authorization: bearer ${GITHUB_TOKEN}" \ | |
-d @- > /dev/null << EOF | |
{ | |
"context": "duolingo/pre-commit", | |
"description": "Running \`pre-commit run --all-files\`", | |
"state": "pending", | |
"target_url": "${BUILD_URL}console" | |
} | |
EOF | |
# Downloading code at revision (faster than clone + checkout) | |
curl -sL -o code.zip \ | |
-H "Authorization: bearer ${GITHUB_TOKEN}" \ | |
"https://github.com/${ghprbGhRepository}/archive/${ghprbActualCommit}.zip" | |
unzip code.zip > /dev/null | |
cd "$(printf %s "${ghprbGhRepository}" | cut -d/ -f2-)-${ghprbActualCommit}" | |
# Create Git repo | |
git init > /dev/null | |
git add -A | |
git commit -m 'Initial commit' > /dev/null | |
# Run pre-commit on all files | |
if [[ -f '.pre-commit-config.yaml' ]]; then | |
args='run --all-files' | |
else | |
args='try-repo https://github.com/duolingo/pre-commit-hooks.git duolingo --all-files' | |
fi | |
if pre-commit $args; then | |
readonly description='All checks passed!' | |
readonly state='success' | |
else | |
readonly description='See Details link →' | |
readonly state='failure' | |
git diff | |
fi | |
# Post state to PR | |
curl -s -X POST \ | |
"https://api.github.com/repos/${ghprbGhRepository}/statuses/${ghprbActualCommit}" \ | |
-H "Authorization: bearer ${GITHUB_TOKEN}" \ | |
-d @- > /dev/null << EOF | |
{ | |
"context": "duolingo/pre-commit", | |
"description": "${description}", | |
"state": "${state}", | |
"target_url": "${BUILD_URL}console" | |
} | |
EOF | |
# Propagate exit code | |
if [[ "${state}" = 'failure' ]]; then | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment