Skip to content

feat: apply qa issue #116

feat: apply qa issue

feat: apply qa issue #116

name: "[Pull Request] Pick Random Reviewer"
on:
issue_comment:
types:
- created
pull_request_target:
types:
- opened
jobs:
pick-random-reviewer:
if: |
github.repository_owner == 'cloudforet-io' &&
contains(github.event.pull_request.labels.*.name, 'self_approved/review')
runs-on: ubuntu-latest
env:
GROUP1: '["WANZARGEN", "sulmoJ", "skdud4659", "piggggggggy"]'
GROUP2: '["kkdy21", "seungyeoneeee", "Hansoo-mzc"]'
steps:
- uses: actions/checkout@v3
- name: Pick Random Reviewer
id: pick_random_reviewer
uses: actions/github-script@v6
with:
script: |
const group1 = JSON.parse(process.env.GROUP1).filter(user => user !== context.payload.pull_request.user.login);
const group2 = JSON.parse(process.env.GROUP2).filter(user => user !== context.payload.pull_request.user.login);
console.log('group1:', group1, 'group2:', group2);
const randomReviewer1 = group1[Math.floor(Math.random() * group1.length)];
const randomReviewer2 = group2[Math.floor(Math.random() * group2.length)];
console.log('randomReviewer1:', randomReviewer1, 'randomReviewer2:', randomReviewer2);
core.setOutput('randomReviewer1', randomReviewer1);
core.setOutput('randomReviewer2', randomReviewer2);
- name: Add Comment
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `🎉 @${{ steps.pick_random_reviewer.outputs.randomReviewer1 }} and @${{ steps.pick_random_reviewer.outputs.randomReviewer2 }} have been randomly selected as the reviewers! Please review. 🙏`
});
- name: Add Reviewers
id: add_reviewers
uses: actions/github-script@v6
with:
script: |
const addReviewersResponse = await github.rest.pulls.requestReviewers({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
reviewers: [`${{ steps.pick_random_reviewer.outputs.randomReviewer1 }}`, `${{ steps.pick_random_reviewer.outputs.randomReviewer2 }}`]
});
- name: Check if the PR author is an organization member and add as assignee
uses: actions/github-script@v6
with:
script: |
const prAuthor = context.payload.pull_request.user.login;
const org = context.repo.owner;
const prNumber = context.payload.pull_request.number;
// Check if the PR author is a member of the organization
try {
await github.rest.orgs.checkMembershipForUser({
org,
username: prAuthor
});
// If the check doesn't throw an error, the user is a member
// Add the PR author as an assignee
await github.rest.issues.addAssignees({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
assignees: [prAuthor]
});
} catch (error) {
// If the user is not a member, or any other error occurs, do nothing
console.log(`User ${prAuthor} is not a member of the org, or an error occurred: ${error.message}`);
}