-
Notifications
You must be signed in to change notification settings - Fork 8
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
코드리뷰 봇 구현 #18
Merged
Merged
코드리뷰 봇 구현 #18
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
fdd7e57
env: 필요 라이브러리 설치
JUDONGHYEOK 8fa0b79
feat: 기본 yml 플로우 작성
JUDONGHYEOK 750f72b
feat: slack webhook 연동 action script 작성
JUDONGHYEOK e8080bd
feat: 슬랙 메세지 문구 수정
JUDONGHYEOK d49b737
fix: module import 방식 변경
JUDONGHYEOK f1f31af
feat: @actions/github 추가
JUDONGHYEOK 6c0ea64
feat: prettier 적용 및 타입 지정
JUDONGHYEOK 5412d68
feat: 메세지 수정
JUDONGHYEOK bc75016
chore: prettier 적용
JUDONGHYEOK c36e40d
fix: 윈도우에서 사용하지 못하는 문자 제거
2yunseong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: "request-review" | ||
description: "Request a review from a specific user on a pull request" | ||
|
||
inputs: | ||
slack_url: | ||
required: true | ||
|
||
runs: | ||
using: "node20" | ||
main: "request_review.js" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import core from "@actions/core"; | ||
import { IncomingWebhook } from "@slack/webhook"; | ||
import github from "@actions/github"; | ||
|
||
const USERS = [ | ||
{ name: "김동완", slackID: "U06MGJUV5T6", githubID: 77495584 }, | ||
{ name: "박건규", slackID: "U06MXJEGBQ8", githubID: 67491015 }, | ||
{ name: "강하은", slackID: "U06M2P73SQ6", githubID: 145974230 }, | ||
{ name: "김민준", slackID: "U06NWKZ9D8B", githubID: 129190157 }, | ||
{ name: "김기표", slackID: "U06NSRR169Y", githubID: 44811887 }, | ||
{ name: "김서영", slackID: "U06NWN9QGE8", githubID: 48192106 }, | ||
{ name: "김양하", slackID: "U06NL19ENBG", githubID: 48500209 }, | ||
{ name: "박재현", slackID: "U06NC98ND71", githubID: 5674167 }, | ||
{ name: "이윤성", slackID: "U06MZ147HBR", githubID: 56749516 }, | ||
{ name: "이규민", slackID: "U06MJJ8463Y", githubID: 102893954 }, | ||
{ name: "임채승", slackID: "U06NC9JEU2K", githubID: 45393030 }, | ||
{ name: "주동혁", slackID: "U06NDMR0EA3", githubID: 65863017 }, | ||
{ name: "최규민", slackID: "U06M9TMN89G", githubID: 127067021 }, | ||
]; | ||
|
||
try { | ||
const url = core.getInput("slack_url"); | ||
const webhook = new IncomingWebhook(url); | ||
|
||
const send = () => { | ||
webhook.send( | ||
{ | ||
text: "PR이 도착했습니다.🫡", | ||
blocks: [ | ||
{ | ||
type: "header", | ||
text: { | ||
type: "plain_text", | ||
text: "PR이 도착했습니다.🫡", | ||
emoji: true, | ||
}, | ||
}, | ||
{ | ||
type: "header", | ||
text: { | ||
type: "plain_text", | ||
text: `${github.context.payload.pull_request.title}`, | ||
}, | ||
}, | ||
{ | ||
type: "section", | ||
fields: [ | ||
{ | ||
type: "mrkdwn", | ||
text: `<@${ | ||
USERS.find( | ||
(user) => | ||
user.githubID === github.context.payload.sender.id, | ||
)?.slackID | ||
}>님이 PR을 보냈습니다!`, | ||
}, | ||
], | ||
}, | ||
{ | ||
type: "section", | ||
fields: [ | ||
{ | ||
type: "mrkdwn", | ||
text: `${github.context.payload.pull_request.requested_reviewers | ||
.map((reviewer) => { | ||
const slackID = USERS.find( | ||
(user) => user.githubID === reviewer.id, | ||
)?.slackID; | ||
return slackID ? `<@${slackID}>` : undefined; | ||
}) | ||
.filter(Boolean) | ||
.join(" ")}님 리뷰를 부탁해요!`, | ||
}, | ||
], | ||
}, | ||
{ | ||
type: "actions", | ||
elements: [ | ||
{ | ||
type: "button", | ||
url: `${github.context.payload.pull_request.html_url}`, | ||
text: { | ||
type: "plain_text", | ||
text: "PR 확인하기", | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
function (err, response) { | ||
console.log(response); | ||
}, | ||
); | ||
}; | ||
if (github.context.payload.pull_request.requested_reviewers.length > 0) | ||
send(); | ||
} catch (error) { | ||
core.setFailed(error.message); | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
on: | ||
pull_request: | ||
types: [opened, reopened] | ||
|
||
jobs: | ||
request_review: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
- name: Cache node modules | ||
uses: actions/cache@v4 | ||
id: cache | ||
with: | ||
path: node_modules | ||
key: npm-packages-${{ hashFiles('**/package-lock.json') }} | ||
- name: Install Dependencies | ||
if: steps.cache.outputs.cache-hit != 'true' | ||
run: npm ci | ||
- name: Start PR actions | ||
id: PRAction | ||
uses: ./.github/actions/request_review | ||
with: | ||
slack_url: ${{ secrets.SLACK_WEBHOOK_URL }} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요 부분에 리뷰어 분들도 리뷰 제출 시 알람 갈 수 있도록 제가 한번 기능추가 해봐도 괜찮을까요??
찾아보니 pull_request_review 웹훅 보니
pull_request_review
이벤트에서github.event.review.state
를 적절히 짬뽕하면 될 것 같은 생각이 드네용Github Action 예시