Last active
November 13, 2023 04:07
-
-
Save CT-1326/52b153deec908ea3070aea548ea76825 to your computer and use it in GitHub Desktop.
slack 전용 git commit 알림
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 | |
URL="slack 채널URL" | |
USER=$(git config --get user.name) | |
while read oldrev newrev refname | |
do | |
# 마스터 브랜치인 경우에만 처리 | |
if [ "$refname" == "refs/heads/master" ]; then | |
# 현재 커밋 메시지를 가져오기 | |
LOG=$(git log -1 --pretty=%B) | |
# 커밋 메시지에 "Merge branch"이며 "master"가 아닌 내용인지 확인 | |
if [[ "$LOG" == *"Merge branch"* && "$LOG" != *"master"* ]]; then | |
LOG=$(git log -1) | |
else | |
if [ $(git rev-parse --verify HEAD^2) ]; then | |
PARENT_COMMIT=$(git log -1 --pretty=%P | awk '{print $1}') | |
LOG=$(git log $PARENT_COMMIT -1) | |
else | |
LOG=$(git log -1) | |
fi | |
fi | |
curl -X POST --data-urlencode "payload={\"username\": \"$USER\", \"icon_emoji\": \":bell:\", \"attachments\":[{ | |
\"fallback\":\"New Commit\", | |
\"color\": \"good\", | |
\"fields\":[{ | |
\"title\" : \"New Commit\", | |
\"value\" : \"$LOG\", | |
\"short\" : false | |
}] | |
}]}" "$URL" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment