asdasd
Last active
December 4, 2020 14:08
-
-
Save valorkin/47bd9bc891885efb43004d7670bbb8dd 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
#!/usr/bin/env bash | |
DEPLOY_TO_PREVIEW_CHANNEL_RESULT=$(firebase hosting:channel:deploy pr-$TRAVIS_PULL_REQUEST --expires 30d --token $FIREBASE_TOKEN --json) | |
RESULT=`echo ${DEPLOY_TO_PREVIEW_CHANNEL_RESULT} | jq -r '.result'` | |
NGX_BOOTSTRAP_DEMO=`echo ${RESULT} | jq -r '."ngx-bootstrap-demo"'` | |
SITE=`echo ${NGX_BOOTSTRAP_DEMO} | jq -r .site` | |
URL=`echo ${NGX_BOOTSTRAP_DEMO} | jq -r .url` | |
EXPIRE_TIME_UTC=`echo ${NGX_BOOTSTRAP_DEMO} | jq -r .expireTime` | |
EXPIRE_TIME=$(TZ='GMT' date -d $EXPIRE_TIME_UTC +%c) | |
NEW_COMMENT="Project: $SITE \n Url: $URL \n This link will expire at $EXPIRE_TIME" | |
COMMENTS=$(curl -H "Authorization: token $GITHUB_TOKEN" -X GET "https://api.github.com/repos/$TRAVIS_REPO_SLUG/issues/$TRAVIS_PULL_REQUEST/comments") | |
SUBSTRING="Project: ngx-bootstrap-demo" | |
COMMENT_ID=-1 | |
for row in $(echo "${COMMENTS}" | jq -r '.[] | @base64'); do | |
echo ${row} | |
_jq() { | |
echo ${row} | base64 --decode | jq -r ${1} | |
} | |
BODY=$(_jq '.body') | |
if [[ ${BODY} == *"$SUBSTRING"* ]]; then | |
COMMENT_ID=$(_jq '.id') | |
fi | |
Done | |
if [[ ${COMMENT_ID} -ge 0 ]]; | |
then | |
curl -H "Authorization: token $GITHUB_TOKEN" -X PATCH -d "{\"body\": \"$NEW_COMMENT\"}" "https://api.github.com/repos/${TRAVIS_REPO_SLUG}/issues/comments/${COMMENT_ID}" | |
else | |
curl -H "Authorization: token $GITHUB_TOKEN" -X POST -d "{\"body\": \"$NEW_COMMENT\"}" "https://api.github.com/repos/${TRAVIS_REPO_SLUG}/issues/${TRAVIS_PULL_REQUEST}/comments" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment