From 70a9b4c3776ec5d251218f60918628b3a8a12428 Mon Sep 17 00:00:00 2001 From: juno-lee Date: Sat, 7 Oct 2023 18:10:51 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=9E=9C=EB=8D=A4=20=EB=A6=AC=EB=B7=B0?= =?UTF-8?q?=EC=96=B4=20=EC=9B=8C=ED=81=AC=ED=94=8C=EB=A1=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/scripts/randomReviewer.js | 30 +++++++++++++++++++++++++++ .github/workflows/assign-reviewer.yml | 27 ++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 .github/scripts/randomReviewer.js create mode 100644 .github/workflows/assign-reviewer.yml diff --git a/.github/scripts/randomReviewer.js b/.github/scripts/randomReviewer.js new file mode 100644 index 000000000..a7adc29d6 --- /dev/null +++ b/.github/scripts/randomReviewer.js @@ -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); +} diff --git a/.github/workflows/assign-reviewer.yml b/.github/workflows/assign-reviewer.yml new file mode 100644 index 000000000..a23792cf2 --- /dev/null +++ b/.github/workflows/assign-reviewer.yml @@ -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 }}