Skip to content

Commit

Permalink
feat: 랜덤 리뷰어 워크플로 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
juno7803 committed Oct 7, 2023
1 parent c744e72 commit 70a9b4c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/scripts/randomReviewer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const { Octokit } = require('@octokit/core');

// TODO: env로 빼기
const reviewers = ['juno7803', 'Tekiter', 'NamJwong', 'seojisoosoo'];

// 랜덤 리뷰어 선택
const selectedReviewer = reviewers[Math.floor(Math.random() * reviewers.length)];

// TODO: env로 빼기
const authToken = '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';
const owner = process.env.GITHUB_OWNER;
const repo = process.env.REPO_NAME;
const prNumber = process.env.PR_NUMBER;

const octokit = new Octokit({ auth: authToken });

try {
await octokit.request(`POST /repos/${owner}/${repo}/pulls/${prNumber}/requested_reviewers`, {
owner,
repo,
pull_number: prNumber,
reviewers: [selectedReviewer],
headers: {
'X-GitHub-Api-Version': '2022-11-28',
},
});
console.log(`${selectedReviewer}를 리뷰어로 선정했어요!`);
} catch (error) {
console.error('리뷰어 지정 과정에서 오류가 발생했어요.\n', (error.response && error.response.data) || error.message);
}
27 changes: 27 additions & 0 deletions .github/workflows/assign-reviewer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Assign Random Reviewer

on:
pull_request:
types: [opened, reopened, ready_for_review]

jobs:
assign_reviewer:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install Dependencies
run: npm install @octokit/core

- name: Assign Reviewer
run: node .github/scripts/randomReviewer.js
env:
GITHUB_OWNER: ${{ github.repository_owner }}
GITHUB_REPOSITORY: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}

0 comments on commit 70a9b4c

Please sign in to comment.