Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REFACTOR] /noti 워크플로우 수정 #13

Merged
merged 10 commits into from
Dec 12, 2024
49 changes: 38 additions & 11 deletions .github/workflows/PR_Comment_Notification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,63 @@ name: Discord Notification on PR Comment
on:
issue_comment:
types: [ created, edited ]
pull_request_review:
types: [ submitted ]

jobs:
notify-discord:
if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/noti') }}
runs-on: ubuntu-latest

steps:
- name: Set Environment Variables
env:
TITLE: ${{ github.event.issue.title }}
run: |
echo "AVATAR_URL=${{ secrets.DISCORD_AVATAR_URL }}" >> $GITHUB_ENV
echo "COMMENT_BODY= 🤚백엔드 친구들 모여라~ 🔊" >> $GITHUB_ENV
echo "USERNAME=망나뇽" >> $GITHUB_ENV
echo "USERNAME=디코봇" >> $GITHUB_ENV
echo "WEB_HOOK=${{ secrets.DISCORD_WEB_HOOK }}" >> $GITHUB_ENV

- name: Set Environment Variables for PR Comments
if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/noti') }}
run: |
echo "COMMENT_AUTHOR=${{ github.event.comment.user.login }}" >> $GITHUB_ENV
echo "PR_URL=${{ github.event.issue.pull_request.html_url }}" >> $GITHUB_ENV
echo "AUTHOR_URL=${{ github.event.comment.user.avatar_url }}" >> $GITHUB_ENV
echo "CONTENT=$(echo '${{ github.event.comment.body }}' | base64 -w 0)" >> $GITHUB_ENV
echo "COMMENT_BODY=${{ github.event.issue.title }}" >> $GITHUB_ENV

- name: Set Environment Variables for PR Review Comment
if: ${{ contains(github.event.review.body, '/noti') }}
run: |
echo "COMMENT_AUTHOR=${{ github.event.review.user.login }}" >> $GITHUB_ENV
echo "PR_URL=${{ github.event.pull_request.html_url }}" >> $GITHUB_ENV
echo "AUTHOR_URL=${{ github.event.review.user.avatar_url }}" >> $GITHUB_ENV
echo "CONTENT=$(echo '${{ github.event.review.body }}' | base64 -w 0)" >> $GITHUB_ENV
echo "COMMENT_BODY=${{ github.event.pull_request.title }}" >> $GITHUB_ENV

- name: Set Environment Variables for Issue
if: ${{ !github.event.issue.pull_request && contains(github.event.comment.body, '/noti') }}
run: |
echo "COMMENT_AUTHOR=${{ github.event.comment.user.login }}" >> $GITHUB_ENV
echo "PR_URL=${{ github.event.issue.html_url }}" >> $GITHUB_ENV
echo "AUTHOR_URL=${{ github.event.comment.user.avatar_url }}" >> $GITHUB_ENV
echo "CONTENT=$(echo '${{ github.event.comment.body }}' | base64 -w 0)" >> $GITHUB_ENV
echo "COMMENT_BODY=${{ github.event.issue.title }}" >> $GITHUB_ENV

- name: Notify Discord
if: ${{ env.COMMENT_AUTHOR && env.PR_URL && env.AUTHOR_URL && env.CONTENT && env.COMMENT_BODY }}
env:
COMMENT_BODY: ${{ env.COMMENT_BODY }}
COMMENT_AUTHOR: ${{ github.event.comment.user.login }}
PR_URL: ${{ github.event.issue.pull_request.html_url }}
AUTHOR_URL: ${{ github.event.comment.user.avatar_url }}
AVATAR_URL: ${{ env.AVATAR_URL }}
CONTENT: ${{ github.event.comment.body }}
COMMENT_BODY: ${{ env.COMMENT_BODY }}
USERNAME: ${{ env.USERNAME }}
WEB_HOOK: ${{ env.WEB_HOOK }}
COMMENT_AUTHOR: ${{ env.COMMENT_AUTHOR }}
PR_URL: ${{ env.PR_URL }}
AUTHOR_URL: ${{ env.AUTHOR_URL }}
CONTENT: ${{ env.CONTENT }}
run: |
CONTENT_DECODED=$(echo "$CONTENT" | base64 --decode)
if [ -n "$WEB_HOOK" ]; then
JSON_PAYLOAD=$(jq -n \
--arg content "$CONTENT" \
--arg content "$CONTENT_DECODED" \
--arg description "$COMMENT_BODY" \
--arg username "$USERNAME" \
--arg avatar_url "$AVATAR_URL" \
Expand Down
Loading