Commit 2e37c78c authored by José Henrique's avatar José Henrique
Browse files

Cleanup code

parent 4e11df7b
......@@ -12,17 +12,18 @@ COMMIT_MESSAGE="$(${GIT_CMD} log -1 --pretty=%B)"
COMMIT_SMALL_HASH="$(${GIT_CMD} rev-parse --short HEAD)"
COMMIT_HASH="$(${GIT_CMD} rev-parse --verify HEAD)"
function sendAdmins() {
curl -s "https://api.telegram.org/bot${TELEGRAM_TOKEN}/sendmessage" --data "text=${*}&chat_id=-1001463677498&disable_web_page_preview=true&parse_mode=Markdown" > /dev/null
function sendTG() {
message="PixelExperience CI ([URL]($BUILD_URL)) ([$COMMIT_SMALL_HASH]($COMMIT_URL)): $1"
curl -s "https://api.telegram.org/bot$TELEGRAM_TOKEN/sendmessage" --data "text=$message&chat_id=-1001463677498&disable_web_page_preview=true&parse_mode=Markdown" > /dev/null
}
function commentPR() {
message="$1"
curl -s -X POST -d "{\"body\": \"$message\"}" -H "Authorization: token $GH_PERSONAL_TOKEN" "https://api.github.com/repos/PixelExperience/official_devices/issues/$GIT_PR_NUMBER/comments" >/dev/null
curl -s -X POST -d "{\"body\": \"$message\"}" -H "Authorization: token $GH_PERSONAL_TOKEN" "https://api.github.com/repos/PixelExperience/official_devices/issues/$GIT_PR_NUMBER/comments" > /dev/null
}
function approvePR() {
curl -s -X POST -d "{\"commit_id\": \"${COMMIT_HASH}\", \"event\": \"APPROVE\"}" -H "Authorization: token $GH_PERSONAL_TOKEN" "https://api.github.com/repos/PixelExperience/official_devices/pulls/$GIT_PR_NUMBER/reviews" >/dev/null
curl -s -X POST -d "{\"commit_id\": \"${COMMIT_HASH}\", \"event\": \"APPROVE\"}" -H "Authorization: token $GH_PERSONAL_TOKEN" "https://api.github.com/repos/PixelExperience/official_devices/pulls/$GIT_PR_NUMBER/reviews" > /dev/null
}
function checkLint() {
......@@ -55,9 +56,8 @@ function checkJsons() {
echo -e "$message"
fi
elif [ "$RESULT" -ne 0 ]; then
sendAdmins "\`Official-Devices CI%0A%0ASomeone has merged a failing file. Please look in ASAP.\`%0A%0A\`Error message: ${ERROR_MESSAGE}\`%0A%0A\`File: ${FAILED_FILE}\`%0A%0A${ADMINS}"
sendTG "Someone has merged a failing file. Please look in ASAP.\nError message: ${ERROR_MESSAGE}\nFile: ${FAILED_FILE}\n${ADMINS}"
else
sendAdmins "\`Official-Devices CI\`%0A%0A**I am building master branch job.** %0A**Commit Point:** [${COMMIT_SMALL_HASH}](https://github.com/PixelExperience/official_devices/commit/${COMMIT_HASH})"
pushToGit
fi
}
......@@ -68,8 +68,18 @@ function pushToGit() {
${GIT_CMD} commit --amend -m "[PIXEL-CI]: ${COMMIT_MESSAGE}"
${GIT_CMD} remote rm origin
${GIT_CMD} remote add origin "https://pixelexperiencebot:${GH_PERSONAL_TOKEN}@github.com/PixelExperience/official_devices.git"
${GIT_CMD} push -f origin master
sendAdmins "\`Official-Devices CI\`%0A%0AJSON Linted and Force Pushed!"
${GIT_CMD} push origin master
RESULT=$?
if [ "$RESULT" -eq 0 ]; then
message="JSON linted and pushed."
echo -e "$message"
sendTG "$message"
else
message="Failed to lint and push json."
echo -e "$message"
sendTG "$message"
exit 1
fi
fi
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment