From 54641591ab8b5929ec34d9391879f3c01339e230 Mon Sep 17 00:00:00 2001 From: hana Date: Fri, 22 Mar 2024 19:43:53 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20reviewer=20=EC=84=A0=EC=A0=95=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=88=98=EC=A0=95,=20=EB=AA=A8=EB=93=88=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/PICK_REVIEWER.yml | 31 ++++++++++++++++++----------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/.github/workflows/PICK_REVIEWER.yml b/.github/workflows/PICK_REVIEWER.yml index fd9c6df6..d3937713 100644 --- a/.github/workflows/PICK_REVIEWER.yml +++ b/.github/workflows/PICK_REVIEWER.yml @@ -27,22 +27,29 @@ jobs: //PrCreator가 reviewer에 등록되지 않은 사람인 경우 if (!prCreatorJson) { const reviewerArr = developers.reviewers; - const randomReviewer1 = reviewerArr[Math.floor(Math.random() * reviewerArr.length)]; - const randomReviewer2 = reviewerArr[Math.floor(Math.random() * reviewerArr.length)]; - core.setOutput('writer', JSON.stringify(prCreator)); + const randomReviewer1 = getRandomReviewer(reviewerArr); + const randomReviewer2 = getRandomReviewer(reviewerArr.filter(reviewer => reviewer.name !== randomReviewer1.name)); + setOutput(prCreator, prUrl, randomReviewer1, randomReviewer2); } else { const candidateInternalReviewers = developers.reviewers.filter(person => person.team === prCreatorJson.team && person.githubName !== prCreator); const candidateExternalReviewers = developers.reviewers.filter(person => person.team !== prCreatorJson.team); - const randomReviewer1 = candidateInternalReviewers[Math.floor(Math.random() * candidateInternalReviewers.length)]; - const randomReviewer2 = candidateExternalReviewers[Math.floor(Math.random() * candidateExternalReviewers.length)]; - core.setOutput('writer', JSON.stringify(prCreatorJson.name)); + const randomReviewer1 = getRandomReviewer(candidateInternalReviewers); + const randomReviewer2 = getRandomReviewer(candidateExternalReviewers); + setOutput(prCreatorJson.name, prUrl, randomReviewer1, randomReviewer2); + } + + function getRandomReviewer(reviewers) { + return reviewers[Math.floor(Math.random() * reviewers.length)]; + } + + function setOutput(prCreator, prUrl, reviewer1, reviewer2) { + core.setOutput('writer', JSON.stringify(prCreator)); + core.setOutput('pullRequestLink', JSON.stringify(prUrl)); + core.setOutput('reviewer1Name', JSON.stringify(reviewer1.name)); + core.setOutput('reviewer2Name', JSON.stringify(reviewer2.name)); + core.setOutput('reviewer1GithubName', reviewer1.githubName); + core.setOutput('reviewer2GithubName', reviewer2.githubName); } - - core.setOutput('pullRequestLink', JSON.stringify(prUrl)); - core.setOutput('reviewer1Name', JSON.stringify(randomReviewer1.name)); - core.setOutput('reviewer2Name', JSON.stringify(randomReviewer2.name)); - core.setOutput('reviewer1GithubName', randomReviewer1.githubName); - core.setOutput('reviewer2GithubName', randomReviewer2.githubName); - name: test valiable uses: actions/github-script@v7