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

구글 태그 및 채널톡 버튼 추가, 코드리뷰 마감시간 알림 슬랙봇 구현 #503

Merged
merged 26 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
df80245
feat: (#492) 채널톡 버튼 추가
inyeong-kang Aug 31, 2023
9c0e880
feat: (#492) 구글 태그 추가
inyeong-kang Aug 31, 2023
bab8ba0
feat: (#494) 프론트엔드 PR의 마감시간 및 코멘트 슬랙봇 구현
inyeong-kang Aug 31, 2023
9d654d4
chore: (#494) channel id 수정
inyeong-kang Aug 31, 2023
235f726
fix: (#494) workflow가 실행되지 않는 오류 해결
inyeong-kang Aug 31, 2023
315a54d
chore: (#494) 주석 삭제
inyeong-kang Aug 31, 2023
fb1c91f
refactor: (#494) 마크다운 형식으로 슬랙 메시지 구성
inyeong-kang Sep 1, 2023
249aa51
feat: (#494) 백엔드 pr에 대한 슬랙 알림 기능 추가
inyeong-kang Sep 1, 2023
27a055c
refactor: (#494) 근무시간이 아닌 경우 포함
inyeong-kang Sep 2, 2023
dbdd10b
feat: (#494) 프론트/백 슬랙 채널에 각각 메시지 전송하도록 구현
inyeong-kang Sep 2, 2023
d34a51f
chore: (#494) 불필요한 코드 삭제
inyeong-kang Sep 2, 2023
caed48f
refactor: (#494) 오늘/내일 키워드 삭제
inyeong-kang Sep 2, 2023
8f392d7
refactor: (#494) yml 파일 분리
inyeong-kang Sep 2, 2023
bd29373
refactor: (#494) working-directory 추가
inyeong-kang Sep 2, 2023
e96a4ed
refactor: (#494) pr url에서 https 제거
inyeong-kang Sep 2, 2023
5c9f54f
refactor: (#494) 공백 추가
inyeong-kang Sep 2, 2023
a5b3155
refactor: (#494) http 추가
inyeong-kang Sep 2, 2023
c04d424
refactor: (#494) yml 파일 name 구체화
inyeong-kang Sep 2, 2023
4e8e21f
refactor: (#492) 채널톡 script 분리
inyeong-kang Sep 2, 2023
85d808f
refactor: (#492) 구글 태그 id, 채널톡 key 환경변수로 분리
inyeong-kang Sep 2, 2023
656bf59
chore: (#494) 불필요한 코드 삭제
inyeong-kang Sep 2, 2023
71c5eec
chore: (#494) working-directory 추가
inyeong-kang Sep 4, 2023
2334514
chore: (#492) ChannelTalk 컴포넌트 pages에서 compoenents 폴더로 이동
inyeong-kang Sep 4, 2023
838ddec
test: (#492) 월요일, 금요일 오전에 대한 테스트 추가
inyeong-kang Sep 4, 2023
92e8916
chore: (#492) type 제거, 누락된 코드 복구
inyeong-kang Sep 4, 2023
48d1939
chore: (#494) defaults 속성 추가
inyeong-kang Sep 4, 2023
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
52 changes: 52 additions & 0 deletions .github/workflows/backend-pr-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Pull request comment (BE)
on:
issue_comment:
types: [created, edited, deleted]

jobs:
pull_request_comment:
# This job only runs for pull request comments
if: ${{ github.event.issue.pull_request }}
runs-on: ubuntu-latest
steps:
- name: Send Slack notification When Review Completed
if: contains(github.event.comment.body, 'review-complete') # check the comment if it contains the keywords
uses: slackapi/slack-github-action@v1.24.0
with:
channel-id: ${{ secrets.SLACK_BE_CHANNEL }} # Slack 채널 ID
payload: |
{
"text": "",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "리뷰 완료했습니다👍\n<${{ github.event.comment.html_url }}|리뷰어의 코멘트 확인하러 가기>"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_TOKEN }} # Slack 토큰

- name: Send Slack notification When Re-review Requested
if: contains(github.event.comment.body, 'review-request')
uses: slackapi/slack-github-action@v1.24.0
with:
channel-id: ${{ secrets.SLACK_BE_CHANNEL }}
payload: |
{
"text": "",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "리뷰 반영 최종 완료!✅ 확인 부탁드립니다😃\n<${{ github.event.comment.html_url }}|피드백 반영 확인하러 가기>"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_TOKEN }}
62 changes: 62 additions & 0 deletions .github/workflows/backend-pr-deadline-slack-bot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Notify Pull Request Deadline (BE)

on:
pull_request:
types:
- opened
branches: ['dev']
paths:
- 'backend/**'

defaults:
run:
working-directory: backend

jobs:
pull_request_open:
runs-on: ubuntu-latest
name: New pr to repo
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Remove "https://" from PR URL
id: remove_https
run: |
PR_URL="${{ github.event.pull_request.html_url }}"
PR_URL="http://${PR_URL#https://}"
echo "::set-output name=pr_url::$PR_URL"

- name: Set environment variable
run: echo "PR_CREATED_AT_UTC=${{ github.event.pull_request.created_at }}" >> $GITHUB_ENV
- name: Convert UTC to KST
run: |
UTC_TIME=$PR_CREATED_AT_UTC
KST_TIME=$(date -u -d "$UTC_TIME 9 hour" "+%Y-%m-%dT%H:%M:%SZ")
echo "PR_CREATED_AT_KST=$KST_TIME" >> $GITHUB_ENV

- name: Calculate deadline
id: deadline
run: node .github/workflows/scripts/calculatePRDeadline.js
env:
PR_CREATED_AT_KST: ${{ env.PR_CREATED_AT_KST }}

- name: Send Slack notification When BE PR
uses: slackapi/slack-github-action@v1.24.0
with:
channel-id: ${{ secrets.SLACK_BE_CHANNEL }} # Slack 채널 ID
payload: |
{
"text": "",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<${{ steps.remove_https.outputs.pr_url }}|${{ github.event.pull_request.title }}>\n코드리뷰 마감시간: ${{ steps.deadline.outputs.DEADLINE }}"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_TOKEN }} # Slack 토큰
56 changes: 56 additions & 0 deletions .github/workflows/frontend-pr-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Pull request comment (FE)
on:
issue_comment:
types: [created, edited, deleted]

defaults:
run:
working-directory: frontend

jobs:
pull_request_comment:
# This job only runs for pull request comments
if: ${{ github.event.issue.pull_request }}
runs-on: ubuntu-latest
steps:
- name: Send Slack notification When Review Completed
if: contains(github.event.comment.body, 'review-complete') # check the comment if it contains the keywords
uses: slackapi/slack-github-action@v1.24.0
with:
channel-id: ${{ secrets.SLACK_FE_CHANNEL }} # Slack 채널 ID
payload: |
{
"text": "",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "리뷰 완료했습니다👍\n<${{ github.event.comment.html_url }}|리뷰어의 코멘트 확인하러 가기>"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_TOKEN }} # Slack 토큰

- name: Send Slack notification When Re-review Requested
if: contains(github.event.comment.body, 'review-request') # check the comment if it contains the keywords
uses: slackapi/slack-github-action@v1.24.0
with:
channel-id: ${{ secrets.SLACK_FE_CHANNEL }} # Slack 채널 ID
payload: |
{
"text": "",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "리뷰 반영 최종 완료!✅ 확인 부탁드립니다😃\n<${{ github.event.comment.html_url }}|피드백 반영 확인하러 가기>"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_TOKEN }} # Slack 토큰
58 changes: 58 additions & 0 deletions .github/workflows/frontend-pr-deadline-slack-bot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Notify Pull Request Deadline (FE)

on:
pull_request:
types:
- opened
branches: ['dev']
paths:
- 'frontend/**'

jobs:
pull_request_open:
runs-on: ubuntu-latest
name: New pr to repo
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Remove "https://" from PR URL
id: remove_https
run: |
PR_URL="${{ github.event.pull_request.html_url }}"
PR_URL="http://${PR_URL#https://}"
echo "::set-output name=pr_url::$PR_URL"

- name: Set environment variable
run: echo "PR_CREATED_AT_UTC=${{ github.event.pull_request.created_at }}" >> $GITHUB_ENV
- name: Convert UTC to KST
run: |
UTC_TIME=$PR_CREATED_AT_UTC
KST_TIME=$(date -u -d "$UTC_TIME 9 hour" "+%Y-%m-%dT%H:%M:%SZ")
echo "PR_CREATED_AT_KST=$KST_TIME" >> $GITHUB_ENV

- name: Calculate deadline
id: deadline
run: node .github/workflows/scripts/calculatePRDeadline.js
env:
PR_CREATED_AT_KST: ${{ env.PR_CREATED_AT_KST }}

- name: Send Slack notification When FE PR
uses: slackapi/slack-github-action@v1.24.0
with:
channel-id: ${{ secrets.SLACK_FE_CHANNEL }} # Slack 채널 ID
payload: |
{
"text": "",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<${{ steps.remove_https.outputs.pr_url }}|${{ github.event.pull_request.title }}>\n코드리뷰 마감시간: ${{ steps.deadline.outputs.DEADLINE }}"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_TOKEN }} # Slack 토큰
2 changes: 1 addition & 1 deletion .github/workflows/frontend-storybook-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy
name: Storybook-Deploy

on:
pull_request:
Expand Down
54 changes: 54 additions & 0 deletions .github/workflows/scripts/calculatePRDeadline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
function calculatePRDeadline(prCreatedAtKST) {
const prCreatedAt = new Date(String(prCreatedAtKST));

const prCreatedMinute = prCreatedAt.getUTCMinutes();
const prCreatedHour = prCreatedAt.getUTCHours();
const prCreatedDate = prCreatedAt.getUTCDate();
const prCreatedDay = prCreatedAt.getUTCDay();
const prCreatedMonth = prCreatedAt.getUTCMonth() + 1; // getUTCMonth()는 0부터 시작하므로 1을 더해줍니다.

const isFridayAfternoon = prCreatedDay === 5 && prCreatedHour >= 22; // 금요일 오후 10시 이후 (금요일: 5, 오후 12시: 12)
const isWeekend = prCreatedDay === 6 || prCreatedDay === 0; // 주말인 경우
const isMondayMorning = prCreatedDay === 1 && prCreatedHour < 10; // 월요일 오전 10시 이전 (월요일: 1, 오전 10시: 10)

// 주어진 근무시간(월요일 오전 10시~금요일 오후 10시) 내에 올린 pr인지 판별
const isNotWorkingTime = isFridayAfternoon || isWeekend || isMondayMorning;

let nextDay = new Date(prCreatedAt);
nextDay.setUTCDate(prCreatedDate + 1); // 다음 날의 날짜를 설정합니다.

const nextDayDate = nextDay.getUTCDate();
const nextDayMonth = nextDay.getUTCMonth() + 1;

let nextWeekMonday = new Date(prCreatedAt);
const daysUntilMonday = 8 - prCreatedDay;
nextWeekMonday.setUTCDate(
prCreatedDay === 0 ? prCreatedDate + 1 : prCreatedDate + daysUntilMonday
);
const nextWeekMondayDate = nextWeekMonday.getUTCDate();
const nextWeekMondayMonth = nextWeekMonday.getUTCMonth() + 1;

const isFriday = prCreatedDay === 5;

if (isNotWorkingTime)
return `${nextWeekMondayMonth}월 ${nextWeekMondayDate}일 20시 00분`;

if (prCreatedHour < 10 && prCreatedHour > 0)
return `${prCreatedMonth}월 ${prCreatedDate}일 20시 00분`;
else if (prCreatedHour === 22 || prCreatedHour === 23)
return `${nextDayMonth}월 ${nextDayDate}일 20시 00분`;
else if (prCreatedHour >= 12)
return `${isFriday ? nextWeekMondayMonth : nextDayMonth}월 ${
isFriday ? nextWeekMondayDate : nextDayDate
}일 ${prCreatedHour - 2}시 ${prCreatedMinute}분`;
else
return `${isFriday ? nextWeekMondayMonth : prCreatedMonth}월 ${
isFriday ? nextWeekMondayDate : prCreatedDate
}일 ${prCreatedHour + 10}시 ${prCreatedMinute}분`;
}

console.log(
`::set-output name=DEADLINE::${calculatePRDeadline(
process.env.PR_CREATED_AT_KST
)}`
);
Loading