From 5af160c31d6a725520121f27375bc61c2afda954 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Thu, 26 Nov 2015 01:13:37 +0100 Subject: [PATCH] phpDocs auto deployment: Use $GITHUB_OAUTH_TOKEN to determine latest commit --- build/deploy-phpdoc.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/build/deploy-phpdoc.sh b/build/deploy-phpdoc.sh index 85dcddb..57b5c6b 100755 --- a/build/deploy-phpdoc.sh +++ b/build/deploy-phpdoc.sh @@ -77,9 +77,17 @@ git commit --message="Update phpDocumentor class docs for $SOURCE_REF" # this is no definite protection (race conditions are still possible during `git push`), # but it should give a basic protection without disabling concurrent builds completely if [ "$SOURCE_REF_TYPE" == "commit" ]; then - # get latest commit + # load branch data via GitHub APIv3 printf '\nRetrieving latest commit...\n' - LATEST_COMMIT="$(wget -O- "https://api.github.com/repos/$SOURCE_REPO_SLUG/git/refs/heads/$SOURCE_REF_BRANCH" 2> /dev/null | php -r " + LATEST_COMMIT_URL="https://api.github.com/repos/$SOURCE_REPO_SLUG/git/refs/heads/$SOURCE_REF_BRANCH" + if [ -n "$GITHUB_OAUTH_TOKEN" ]; then + LATEST_COMMIT_RESPONSE="$(wget -O- --header="Authorization: token $GITHUB_OAUTH_TOKEN" "$LATEST_COMMIT_URL" 2> /dev/null)" + else + LATEST_COMMIT_RESPONSE="$(wget -O- "$LATEST_COMMIT_URL" 2> /dev/null)" + fi + + # evaluate JSON response + LATEST_COMMIT="$(echo "$LATEST_COMMIT_RESPONSE" | php -r " \$json = json_decode(stream_get_contents(STDIN), true); if (\$json !== null) { if (isset(\$json['ref']) && (\$json['ref'] === 'refs/heads/$SOURCE_REF_BRANCH')) {