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

chore(*): slack 알림 연동 test #27

Closed
wants to merge 23 commits into from
Closed
59 changes: 25 additions & 34 deletions .github/workflows/slack-notify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,38 @@ jobs:
id: determine_event
run: echo "event_type=${{ github.event_name }}" >> $GITHUB_ENV

- name: Read user mapping
id: read_mapping
run: |
mapping=$(cat .github/user-mapping.json)
echo "mapping=$mapping" >> $GITHUB_ENV

- name: Cache Slack message timestamp
if: ${{ env.event_type == 'pull_request' }}
uses: actions/cache@v2
with:
path: slack_ts.txt
key: slack-ts-${{ github.event.pull_request.number }}
if: ${{ env.event_type == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'synchronize') }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 env.event_type이 아니라 github.event_type 아닌가요? 아닐수도..

id: cache_slack_ts
run: |
if [ -f slack_ts_${{ github.event.pull_request.number }}.txt ]; then
echo "slack_ts=$(cat slack_ts_${{ github.event.pull_request.number }}.txt)" >> $GITHUB_ENV
else
echo "slack_ts=" >> $GITHUB_ENV
fi

- name: Send notification for PR
if: ${{ env.event_type == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'synchronize') }}
id: slack_pr
run: |
response=$(curl -X POST -H 'Content-type: application/json' --data '{
"text": "🧞‍♂️ PR 드리는 지니가 왔습니다\n[sambad#${{ github.event.pull_request.number }}] [${{ github.event.pull_request.title }}](${{ github.event.pull_request.html_url }})\n${{ github.event.pull_request.user.login }}님이 생성했어요."
"text": "*🧞‍♂️ PR 드리는 지니가 왔습니다~*\n*<${{ github.event.pull_request.html_url }}|[sambad#${{ github.event.pull_request.number }}] [${{ github.event.pull_request.title }}]>*\n${{ github.event.pull_request.user.login }}님이 생성했어요."
}' ${{ secrets.SLACK_BOT_ACCESS_TOKEN }})
echo "slack_ts=$(echo $response | jq -r '.ts')" >> $GITHUB_ENV
echo $slack_ts > slack_ts.txt
slack_ts=$(echo $response | jq -r '.ts')
echo "slack_ts=$slack_ts" >> $GITHUB_ENV
echo $slack_ts > slack_ts_${{ github.event.pull_request.number }}.txt
env:
SLACK_BOT_ACCESS_TOKEN: ${{ secrets.SLACK_BOT_ACCESS_TOKEN }}

- name: Send notification for review request
if: ${{ env.event_type == 'pull_request' && github.event.action == 'review_requested' }}
run: |
reviewer=${{ github.event.requested_reviewer.login }}
slack_username=$(echo ${{ env.mapping }} | jq -r --arg reviewer "$reviewer" '.[$reviewer]')
slack_username=$(cat .github/user-mapping.json | jq -r --arg reviewer "$reviewer" '.[$reviewer]')
if [ "$slack_username" != "null" ]; then
response=$(curl -X POST -H 'Content-type: application/json' --data '{
"text": "🔔 리뷰 요청이 도착했습니다: @'$slack_username'"
}' ${{ secrets.SLACK_BOT_ACCESS_TOKEN }})
echo "slack_ts=$(echo $response | jq -r '.ts')" >> $GITHUB_ENV
echo $slack_ts > slack_ts.txt
curl -X POST -H 'Content-type: application/json' --data '{
"text": "*🔔 리뷰 요청이 도착했습니다*: @'$slack_username'"
}' ${{ secrets.SLACK_BOT_ACCESS_TOKEN }}
else
echo "Reviewer not found in mapping: $reviewer"
fi
Expand All @@ -64,26 +60,21 @@ jobs:

- name: Restore Slack message timestamp
if: ${{ env.event_type == 'issue_comment' || env.event_type == 'pull_request_review' }}
id: restore_ts
uses: actions/cache@v2
with:
path: slack_ts.txt
key: slack-ts-${{ github.event.issue.number || github.event.pull_request.number }}
restore-keys: |
slack-ts-

- name: Load Slack message timestamp
if: ${{ (env.event_type == 'issue_comment' || env.event_type == 'pull_request_review') && steps.restore_ts.outputs.cache-hit == 'true' }}
run: echo "SLACK_MESSAGE_TS=$(cat slack_ts.txt)" >> $GITHUB_ENV
run: |
if [ -f slack_ts_${{ github.event.issue.number || github.event.pull_request.number }}.txt ]; then
echo "SLACK_MESSAGE_TS=$(cat slack_ts_${{ github.event.issue.number || github.event.pull_request.number }}.txt)" >> $GITHUB_ENV
else
echo "SLACK_MESSAGE_TS=" >> $GITHUB_ENV
fi

- name: Send notification for comment
if: ${{ env.event_type == 'issue_comment' && env.SLACK_MESSAGE_TS != '' }}
run: |
commenter=${{ github.event.comment.user.login }}
slack_username=$(echo ${{ env.mapping }} | jq -r --arg commenter "$commenter" '.[$commenter]')
slack_username=$(cat .github/user-mapping.json | jq -r --arg commenter "$commenter" '.[$commenter]')
if [ "$slack_username" != "null" ]; then
curl -X POST -H 'Content-type: application/json' --data '{
"text": "@'$slack_username'님이 코멘트를 달았습니다:\n${{ github.event.comment.body }}",
"text": "@'$slack_username'님이 코멘트를 달았습니다 💌:\n${{ github.event.comment.body }}",
"thread_ts": "${{ env.SLACK_MESSAGE_TS }}"
}' ${{ secrets.SLACK_BOT_ACCESS_TOKEN }}
else
Expand All @@ -96,7 +87,7 @@ jobs:
if: ${{ env.event_type == 'pull_request_review' && github.event.review.state == 'approved' && env.SLACK_MESSAGE_TS != '' }}
run: |
reviewer=${{ github.event.review.user.login }}
slack_username=$(echo ${{ env.mapping }} | jq -r --arg reviewer "$reviewer" '.[$reviewer]')
slack_username=$(cat .github/user-mapping.json | jq -r --arg reviewer "$reviewer" '.[$reviewer]')
if [ "$slack_username" != "null" ]; then
curl -X POST -H 'Content-type: application/json' --data '{
"text": "✅ @'$slack_username'님이 승인하셨어요 🎉",
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/second/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { SecondDomainExampleScreen } from '@sambad/domains/second-domain';
import Image from 'next/image';

import styles from '../page.module.css';

export default function Second() {
return (
<main className={styles.main}>
<SecondDomainExampleScreen />
test
</main>
);
}
Loading