Last active
February 2, 2023 00:01
-
-
Save ans-4175/c3d63f22bf3d3bfb5b26551f2f1ea8a7 to your computer and use it in GitHub Desktop.
Share Last Commit to Slack
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
#!/bin/bash | |
SLACK_TOKEN=xoxb-your-slack-token | |
SLACK_DEPLOY_CHANNEL=C0-your-slack-id | |
REPO_NAME=$(pwd | grep -o "[^/]*$") | |
LAST_HASH_COMMIT=$(git log --format='%H' HEAD -n1 | cat -) | |
LAST_AUTHOR_COMMIT=$(git log --format='%an <%ae>' HEAD -n1 | cat -) | |
LAST_MSG_COMMIT=$(git log -1 --oneline --format=%s | cat -) | |
SLACK_BLOCK="{'channel':'${SLACK_DEPLOY_CHANNEL}','blocks':[{'type':'section','text':{'type':'mrkdwn','text':'> ${REPO_NAME}'}},{'type':'section','text':{'type':'mrkdwn','text':'Commit: <https://github.com/orgs-name/${REPO_NAME}/commit/${LAST_HASH_COMMIT}|${LAST_HASH_COMMIT}>\n${LAST_MSG_COMMIT}'}},{'type':'context','elements':[{'type':'mrkdwn','text':'${LAST_AUTHOR_COMMIT}'}]}]}" | |
curl -H "Content-type: application/json" \ | |
--data "${SLACK_BLOCK}" \ | |
-H "Authorization: Bearer ${SLACK_TOKEN}" \ | |
-X POST https://slack.com/api/chat.postMessage | |
echo "#sent message to slack" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment