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

[BE] 코드 리뷰 알림 기능 보완 #190

Merged
merged 3 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 66 additions & 46 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -1,72 +1,92 @@
name: PULL_REQUEST
name: PULL REQUEST

on:
on:
pull_request:
types: [opened]

env:
koust6u: U07D1PWSLSG
kelly6bf: U07DSB12K99
JiHyeonL: U07E3T9PMA4
yechop: U07E3TG6CHE
reddevilmidzy: U07DF0QPUKV
dle234: U07E48NCK4G
greetings1012: U07DPGSCXRA
anttiey: U07DPGSCXRA

types: [opened, reopened]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ vars.SLACK_BRANCH}}

- name: Install jq
run: sudo apt-get install jq

- name: Send HTTP request and extract GitHub IDs
id: extract_github_ids
run: |
response=$(curl -s -H "Content-Type: application/json" \
-H "Github_id: ${{ github.event.pull_request.user.login }}" \
http://43.200.237.127:8080/member)
GITHUB_IDS=$(echo "$response" | jq -r 'map(.githubId) | join(" ")')
echo "GITHUB_IDS=$GITHUB_IDS" >> $GITHUB_ENV

- name: Prepare GitHub IDs for Slack message
id: prepare_slack_message
- name: Decode base64 and parse JSON
run: |
GITHUB_IDS_ARRAY=($GITHUB_IDS)

SLACK_USER_MENTIONS=""
for GITHUB_ID in "${GITHUB_IDS_ARRAY[@]}"; do
SLACK_ID="${!GITHUB_ID}"
if [ -n "$SLACK_ID" ]; then
SLACK_USER_MENTIONS+="<@$SLACK_ID> "
fi
done
echo "SLACK_USER_MENTIONS=$SLACK_USER_MENTIONS" >> $GITHUB_ENV
echo ${{secrets.SLACK_CREW_INFO_JSON}} | base64 --decode > decoded.json
JSON_CONTENT=$(cat decoded.json | jq -c .)
echo "CREW_INFO_JSON=$JSON_CONTENT" >> $GITHUB_ENV

- name: PR opened
id: slack-pr-opened
uses: slackapi/slack-github-[email protected]
- name: Extract receiver list
id: extract_receiver_list
uses: actions/github-[email protected]
with:
channel-id: 'C07DN3TETSL'
script: |
const excludeMember = context.payload.pull_request.user.login;
const members = JSON.parse(process.env.CREW_INFO_JSON);
const requester = members.find(entry => entry.githubId === excludeMember);
let outputString = '';
for (const member of members) {
if ((member.githubId !== excludeMember) && (member.tag === requester.tag)) {
outputString += `<@${member.slackId}> `;
}
}
console.log(`::set-output name=names::${outputString.trim()}`);
console.log(`::set-output name=requester::${requester.name}`);

- name: pull_request_noifiy
id: pull_request_notify
uses: slackapi/[email protected]
with:
channel-id: ${{secrets.SLACK_BE_REVIEW_CHANNEL}}
payload: |
{
"text": "Backend PR opened: ${{ github.event.pull_request.html_url }}",
"text": "⌛PR왔다 리뷰해라⌛",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "🔔*PR 요청 왔어요. 코드 리뷰해주세요*🔔 \n<${{ github.event.pull_request.html_url }}|`${{github.event.pull_request.title}}`에 대한 코드 리뷰를 해주세요.>\n${{ env.SLACK_USER_MENTIONS }}"
"text": "*📬${{steps.extract_receiver_list.outputs.requester}}님의 PR이 도착했어요.📬*\n\n\n⚡⚡⚡⚡⚡⚡⚡⚡⚡\n*⚡<https://github.com/koust6u/coduo-review/pull/2| [프 람] 혼구멍 내러가기~>⚡* \n⚡⚡⚡⚡⚡⚡⚡⚡⚡\n\n _혼내줄 사람들: ${{steps.extract_receiver_list.outputs.names}}_ \n"
}
},
{
"type": "divider"
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}

- name: Append Thread info to JSON
run: |
NEW_THREAD_JSON=$(jq -n \
--arg url "${{ github.event.pull_request.html_url }}" \
--arg author "${{ github.event.pull_request.user.login }}" \
--arg thread_ts "${{ steps.pull_request_notify.outputs.ts }}" \
'{pr_url: $url, author: $author, thread_ts: $thread_ts}')

- name: thread store api request
mkdir -p .github/logs
cd .github/logs

if [ -f thread_be.json ]; then
jq --argjson new "$NEW_THREAD_JSON" '. += [$new]' thread_be.json > thread_be.tmp.json
mv thread_be.tmp.json thread_be.json
else
echo "[$NEW_THREAD_JSON]" > thread_be.json
fi

- name: Commit updated thread_be.json
run: |
curl -X POST http://43.200.237.127:8080/github/thread \
-H "Content-Type: application/json" \
-d '{"ts": "${{steps.slack-pr-opened.outputs.ts}}", "url": "${{github.event.pull_request.html_url}}"}'
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git add .github/logs/thread_be.json
git commit -m "Update thread_be.json with new thread data"
git push origin ${{ vars.SLACK_BRANCH }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51 changes: 0 additions & 51 deletions .github/workflows/reivew_submit_notification.yml

This file was deleted.

72 changes: 72 additions & 0 deletions .github/workflows/review_submit_notification.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: review submitted notification

on:
pull_request_review:
types: [submitted]

jobs:
notify:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ vars.SLACK_BRANCH }}

- name: Install jq
run: sudo apt-get install jq

- name: Read Thead JSON and Set Env Variables
run: |
TARGET_URL=${{ github.event.pull_request.html_url }}
JSON_CONTENT=$(cat .github/logs/thread_be.json)
TARGET_OBJECT=$(echo "$JSON_CONTENT" | jq --arg url "$TARGET_URL" '.[] | select(.pr_url == $url)')

PR_URL=$(echo "$TARGET_OBJECT" | jq -r '.pr_url')
AUTHOR=$(echo "$TARGET_OBJECT" | jq -r '.author')
THREAD_TS=$(echo "$TARGET_OBJECT" | jq -r '.thread_ts')

echo "PR_URL=${PR_URL}" >> $GITHUB_ENV
echo "PR_AUTHOR=${AUTHOR}" >> $GITHUB_ENV
echo "REVIEW_AUTHOR=${{ github.event.review.user.login }}" >> $GITHUB_ENV
echo "THREAD_TS=${THREAD_TS}" >> $GITHUB_ENV


- name: Decode base64 and parse CREW JSON
run: |
echo ${{secrets.SLACK_CREW_INFO_JSON}} | base64 --decode > decoded.json
JSON_CONTENT=$(cat decoded.json | jq -c .)
echo "CREW_INFO_JSON=$JSON_CONTENT" >> $GITHUB_ENV

- name: Extract member
id: extract_member
uses: actions/[email protected]
with:
script: |
const members = JSON.parse(process.env.CREW_INFO_JSON);
const reviewee = members.find(entry => entry.githubId === process.env.PR_AUTHOR);
const reviewer = members.find(entry => entry.githubId === process.env.REVIEW_AUTHOR);
console.log(`::set-output name=reviewee_slack_id::${reviewee.slackId}`);
console.log(`::set-output name=reviewer_slack_name::${reviewer.name}`);


- name: Send Slack notification
uses: slackapi/[email protected]
with:
channel-id: ${{secrets.SLACK_BE_REVIEW_CHANNEL}}
payload: |
{
"text": "리뷰가 도착했어요✉️",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "📫<@${{ steps.extract_member.outputs.reviewee_slack_id }}>님 PR에 대한 `${{steps.extract_member.outputs.reviewer_slack_name}}`님의 리뷰가 도착했어요.📫"
}
}
],
"thread_ts": "${{ env.THREAD_TS }}"
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
Loading