Skip to content

Commit b7e6fdf

Browse files
committed
Add github actions
- 랜덤 리뷰어 2명 등록 - 자동 코멘트 추가 - slack 메시지 전송
1 parent 86bba8b commit b7e6fdf

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

‎.github/workflows/slack-noti.yml‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: "Random reviwer"
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- reopened
8+
branches: ['master', 'protectHeo','DGJSKIM', 'anjungin', 'unie11', 'GGWANGBIN']
9+
10+
permissions:
11+
pull-requests: write
12+
13+
jobs:
14+
random-reviwer:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- id: random_reviewer
18+
uses: actions/[email protected]
19+
with:
20+
github-token: ${{ secrets.PAT }}
21+
script: |
22+
const me = '${{ github.event.pull_request.user.login }}';
23+
const response = await github.rest.orgs.listMembers({
24+
org: context.repo.owner, // 조직 이름
25+
});
26+
27+
const candidate = response.data.map(member => member.login);
28+
const candidateWithoutMe = candidate.filter(id => id !== me);
29+
30+
function getRandomTwo(array) {
31+
if (array.length < 2) {
32+
throw new Error("Array must have at least two elements.");
33+
}
34+
35+
const index1 = Math.floor(Math.random() * array.length);
36+
let index2;
37+
38+
// 첫 번째 인덱스와 다른 값을 찾을 때까지 반복
39+
do {
40+
index2 = Math.floor(Math.random() * array.length);
41+
} while (index1 === index2);
42+
43+
return [array[index1], array[index2]];
44+
}
45+
46+
const electedReviewers = getRandomTwo(candidateWithoutMe);
47+
const comment = `@${electedReviewers[0]} 님, @${electedReviewers[1]} 님 숭고한 랜덤 리뷰어로 당첨되셨습니다! 리뷰를 부탁드립니다. 🙏`
48+
core.setOutput('reviewer_1', electedReviewers[0]);
49+
core.setOutput('reviewer_2', electedReviewers[1]);
50+
core.setOutput('comment', comment);
51+
52+
// Request review
53+
await github.rest.pulls.requestReviewers({
54+
owner: context.repo.owner,
55+
repo: context.repo.repo,
56+
pull_number: context.payload.pull_request.number,
57+
reviewers: electedReviewers
58+
});
59+
60+
- name: Create Pull Request Comment
61+
uses: actions/[email protected]
62+
with:
63+
github-token: ${{ secrets.GITHUB_TOKEN }}
64+
script: |
65+
const comment = "${{ steps.random_reviewer.outputs.comment }}";
66+
// Create comment
67+
await github.rest.issues.createComment({
68+
owner: context.repo.owner,
69+
repo: context.repo.repo,
70+
issue_number: context.payload.pull_request.number,
71+
body : comment
72+
});
73+
74+
- name: Slack Notification
75+
uses: rtCamp/action-slack-notify@v2
76+
env:
77+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
78+
79+
- name: Post to a Slack channel
80+
run: |
81+
curl -X POST -H 'Content-type: application/json' \
82+
--data '{
83+
"text": "🎉 축하합니다! \n\n *${{ github.event.pull_request.title }}* 의 리뷰어로 \n\n<@${{ steps.random_reviewer.outputs.reviewer_1 }}> 님과 <@${{ steps.random_reviewer.outputs.reviewer_2 }}> 님이 당선되었습니다! 🎉"
84+
}' \
85+
${{ secrets.SLACK_WEBHOOK }}

0 commit comments

Comments
 (0)