github actions로 PR 랜덤 리뷰어 지정하기
IT2024. 9. 6. 17:24gibhut actions 스크립트
아래 yaml 파일은 리뷰어를 설정하는 github actions 스크립트입니다.
name: "Random reviwer"
on:
pull_request:
types:
- opened
branches:
- dev
jobs:
random-reviwer:
runs-on: ubuntu-latest
steps:
- id: random_reviwer
uses: actions/github-script@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const me = '${{ github.event.pull_request.user.login }}';
const candidate = ['username1', 'username2', 'username3', 'username4'];
const candidateWithoutMe = candidate.filter(id => id !== me);
const randomReviewer = candidateWithoutMe[Math.floor(Math.random() * candidateWithoutMe.length)];
const comment = `@${randomReviewer} 님 랜덤 리뷰어로 당첨되셨습니다! 리뷰를 부탁드립니다. 🙏`
core.setOutput('comment', comment)
core.setOutput('reviewer', randomReviewer)
- name: comment PR
uses: mshick/add-pr-comment@v1
with:
message: |
${{ steps.random_reviwer.outputs.comment }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
repo-token-user-login: 'github-actions[bot]'
- name: Add Pull Request Reviewer
uses: madrapps/add-reviewers@v1
with:
reviewers: ${{ steps.random_reviwer.outputs.reviewer }}
token: ${{ secrets.GITHUB_TOKEN }}
랜덤 리뷰어 뽑기
github-script를 사용하면, javascript 코드를 수행할 수 있습니다. javascript 코드를 작성하여 랜덤 리뷰어를 뽑는 코드를 작성합니다.
${{ github.event.pull_request.user.login }}는 현재 로그인한 사용자의 username을 반환합니다. candidate에 팀원들의 username 값을 넣어두고, filter를 하여 본인을 제거한 뒤 random()로 랜덤한 index 값으로 리뷰어를 뽑습니다.
core.setOutput('comment', comment)
core.setOutput('reviewer', randomReviewer)
core.setOutput으로 댓글 내용(comment)과 리뷰어로 뽑힌 username을 담고 있는 randomReviewer 값을 설정합니다. core.setOutput을 사용하면 다음 step에서 해당 값을 가지고 와서 사용할 수 있습니다.
코멘트 남기고, 리뷰어 설정
mshick/add-pr-comment@v1로 코멘트를 남기고, madrapps/add-reviewers@v1로 해당 PR에 리뷰어를 지정합니다.
이때 github-script에서 core.setOutput으로 설정한 comment, reviewer 값을 사용합니다.
사용할때는 아래와 같이 사용합니다.
# comment 값 가져오기
${{ steps.random_reviwer.outputs.comment }}
# reviewer 값 가져오기
${{ steps.random_reviwer.outputs.reviewer }}
Reference
GitHub - actions/github-script: Write workflows scripting the GitHub API in JavaScript
Write workflows scripting the GitHub API in JavaScript - actions/github-script
github.com

'IT' 카테고리의 다른 글
| 백준 Chrome Extension 추천, 백준 허브 적용하기 (0) | 2025.01.06 |
|---|---|
| Stable Diffusion에 VAE 개념 및 WEB UI에 설정하기 (1) | 2024.06.08 |
| Stable Diffusion WEB UI에 User Interface 설정하기 (0) | 2024.06.08 |
| "Unable to boot simulator" iOS 시뮬레이터 실행 오류 조치 (0) | 2024.05.14 |
| python과 pyupbit로 호가 주문 취소하기 (0) | 2024.05.03 |
IT 기술에 대한 글을 주로 작성하고, 일상 내용, 맛집/숙박/제품 리뷰 등 여러가지 주제를작성하는 블로그입니다. 티스토리 커스텀 스킨도 개발하고 있으니 관심있으신분은 Berry Skin을 검색바랍니다.
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!