Commit Notifier #57
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
name: Commit Notifier | |
on: | |
schedule: | |
- cron: '0 15 * * *' # 매일 00:00(KST) 실행 (UTC 기준 15:00) | |
workflow_dispatch: # 수동 실행 추가 | |
jobs: | |
send-discord-notification: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Get yesterday's commit count and author | |
id: commit-info | |
run: | | |
# 이름 변환 함수 | |
convert_name() { | |
case "$1" in | |
"김지윤") echo "지윤" ;; | |
"changhui-chan") echo "창희" ;; | |
"수진" | "minim1nh") echo "수진" ;; | |
"박지민" | "jiminp00") echo "지민" ;; | |
*) echo "$1" ;; # 매칭되지 않으면 원래 이름 반환 | |
esac | |
} | |
START=$(TZ="Asia/Seoul" date --date=' yesterday 00:00:00' +'%Y-%m-%d %H:%M:%S') | |
END=$(TZ="Asia/Seoul" date --date=' yesterday 23:59:00' +'%Y-%m-%d %H:%M:%S') | |
echo "자정: $START" | |
echo " 23시 59분: $END" | |
COMMIT_INFO=$(TZ="Asia/Seoul" git log --since="$START" --until="$END" --pretty=format:"%an%n") | |
if [ -z "$COMMIT_INFO" ]; then | |
echo "No commits found." | |
exit 0 | |
fi | |
# 커밋 정보 디버깅 | |
echo "커밋 내역:" | |
echo "$COMMIT_INFO" | |
declare -A AUTHOR_COUNT | |
while read -r AUTHOR; do | |
if [ -z "$AUTHOR" ]; then | |
continue | |
fi | |
AUTHOR=$(convert_name "$AUTHOR") | |
AUTHOR_COUNT["$AUTHOR"]=$((AUTHOR_COUNT["$AUTHOR"] + 1)) | |
done <<< "$COMMIT_INFO" | |
# 작업자별 커밋 수 출력 | |
MAPPED_INFO="" | |
for AUTHOR in "${!AUTHOR_COUNT[@]}"; do | |
MAPPED_INFO+="$AUTHOR: ${AUTHOR_COUNT[$AUTHOR]}" | |
done | |
echo "commit-info=$MAPPED_INFO" >> $GITHUB_ENV | |
- name: Send Discord notification | |
run: | | |
COMMIT_INFO="${{ env.commit-info }}" | |
if [ -n "$COMMIT_INFO" ]; then | |
MESSAGE="오늘의 커밋 인증! 🔥\n\n$COMMIT_INFO\n 잔디🌱를 심었습니다!" | |
curl -X POST \ | |
-H "Content-Type: application/json" \ | |
-d "{\"content\": \"$MESSAGE\"}" \ | |
"https://discord.com/api/webhooks/1337717353433268234/hGSbJTCiux5hTuMAQYR1o65jXnc-Ew3u7Y7naLrJqAgSZlwjZi0_70EhPX7Etj7eM7u-" | |
else | |
echo "No commits to notify." | |
fi |