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

코드리뷰 봇 구현 #18

Merged
merged 10 commits into from
Apr 2, 2024
10 changes: 10 additions & 0 deletions .github/actions/request_review/action.yml
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"
100 changes: 100 additions & 0 deletions .github/actions/request_review/request_review.js
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();
Comment on lines +96 to +97
Copy link
Collaborator

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 예시

} catch (error) {
core.setFailed(error.message);
}
27 changes: 27 additions & 0 deletions .github/workflows/pull_request.yml
Copy link
Collaborator

Choose a reason for hiding this comment

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

image
image
윈도우에서 확인해보니 invaild 한 문자가 들어가 있어, 혹시 변경 가능하실까요?

\b 문자가 들어가 있는걸로 보이네욥

image

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 }}
Loading