Mention Discord on Pull Request Review #730
Workflow file for this run
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: Mention Discord on Pull Request Review | |
on: | |
pull_request_review: | |
types: [ submitted ] | |
env: | |
"31026350": "206298119661420544" | |
"64690761": "243991296060948491" | |
"69838872": "1165830186990850110" | |
"111052302": "859318944195149855" | |
"145949635": "1164111111193366580" | |
"76177848": "710749110570975243" | |
"110809927": "971312723260493834" | |
"80167893": "1162754699099906169" | |
"backend": "1263405654534525051" | |
"frontend": "1263406763382931467" | |
jobs: | |
notify-on-pr: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Find prefix for PR title | |
run: | | |
echo "Finding prefix for PR title" | |
PR_TITLE='${{ github.event.pull_request.title }}' | |
PR_PREFIX=$(echo $PR_TITLE | cut -d ' ' -f1) | |
if [ "$PR_PREFIX" = '[BE]' ]; then | |
echo Backend PR Found! | |
echo "PR_PREFIX=BE" >> $GITHUB_ENV | |
elif [ "$PR_PREFIX" = '[FE]' ]; then | |
echo Frontend PR Found! | |
echo "PR_PREFIX=FE" >> $GITHUB_ENV | |
elif [ "$PR_PREFIX" = '[All]' ]; then | |
echo All PR Found! | |
echo "PR_PREFIX=All" >> $GITHUB_ENV | |
fi | |
echo PR Prefix : $PR_PREFIX | |
echo PR Prefix on env : ${{ env.PR_PREFIX }} | |
- name: Notify on PR Review | |
if: github.event.review.state == 'approved' || github.event.review.state == 'changes_requested' | |
run: | | |
echo "Notify on Discord" | |
PR_URL='${{ github.event.pull_request.html_url }}' | |
PR_TITLE='${{ github.event.pull_request.title }}' | |
PR_AUTHOR='${{ github.event.pull_request.user.login }}' | |
REVIEWER='${{ github.event.review.user.login }}' | |
REVIEWER_DISCORD_ID='${{ env[github.event.review.user.id] }}' | |
AUTHOR_DISCORD_ID='${{ env[github.event.pull_request.user.id] }}' | |
if [ "${{ env.PR_PREFIX }}" = 'BE' ]; then | |
WEBHOOK_URL=${{ secrets.DISCORD_BE_PR_WEBHOOK_URL }} | |
elif [ "${{ env.PR_PREFIX }}" = 'FE' ]; then | |
WEBHOOK_URL=${{ secrets.DISCORD_FE_PR_WEBHOOK_URL }} | |
elif [ "${{ env.PR_PREFIX }}" = 'All' ]; then | |
WEBHOOK_URL=${{ secrets.DISCORD_ALL_PR_WEBHOOK_URL }} | |
fi | |
if [ "${{ github.event.review.state }}" = 'approved' ]; then | |
COMMENT="PR Approved 되었습니다 🚀" | |
COLOR=65305 | |
elif [ "${{ github.event.review.state }}" = 'changes_requested' ]; then | |
COMMENT="PR에 수정 요구사항이 있습니다 👀" | |
COLOR=16736293 | |
else | |
echo "Invalid review state" | |
exit 0 | |
fi | |
JSON_FILE=$(mktemp) | |
cat > $JSON_FILE <<EOF | |
{ | |
"content": "<@$AUTHOR_DISCORD_ID> $COMMENT", | |
"embeds": [ | |
{ | |
"author": { | |
"name": "$PR_AUTHOR", | |
"icon_url": "https://github.com/$PR_AUTHOR.png" | |
}, | |
"title": "$PR_TITLE", | |
"url": "$PR_URL", | |
"color": $COLOR, | |
"footer": { | |
"text": "2024-review-me" | |
}, | |
"fields": [ | |
{ | |
"name": "리뷰어", | |
"value": "<@$REVIEWER_DISCORD_ID>", | |
"inline": true | |
} | |
], | |
"timestamp": "$(date -u +'%Y-%m-%dT%H:%M:%SZ')" | |
} | |
] | |
} | |
EOF | |
cat $JSON_FILE | |
curl -X POST -H 'Content-type: application/json' \ | |
--data @$JSON_FILE \ | |
$WEBHOOK_URL | |
rm $JSON_FILE |