Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Action Test용 PR #9

Closed
wants to merge 11 commits into from
2 changes: 0 additions & 2 deletions .github/CODEOWNERS

This file was deleted.

39 changes: 39 additions & 0 deletions .github/actions/reviewers/action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { getInput, setFailed } from "@actions/core"
import { context, getOctokit } from "@actions/github"

try {
const candidates = getInput("reviewers").split(", ")
const reviewers = selectRandomReviewer(candidates)
const token = getInput("github_token")
const octokit = getOctokit(token)

const { owner, repo } = context.repo
const pull_number = context.issue.number

await octokit.rest.pulls.requestReviewers({
owner,
repo,
pull_number,
reviewers: reviewers,
})
} catch (error) {
setFailed(error.message)
}

function selectRandomReviewer(reviewers) {
const requiredReviewer = 2
const creator = context.payload.pull_request.user.login
const candidates = reviewers.filter((reviewer) => reviewer !== creator)

const result = []
for (let i = 0; i < requiredReviewer; i++) {
const { length } = candidates
if (length === 0) {
break
}

const randomIndex = Math.floor(Math.random() * length)
result.push(...candidates.splice(randomIndex, 1))
}
return result
}
11 changes: 11 additions & 0 deletions .github/actions/reviewers/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: "reviewers"

inputs:
reviewers:
required: true
github_token:
required: true

runs:
using: "node16"
main: "action.js"
44 changes: 44 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: deploy

on:
pull_request:
types: [opened, ready_for_review]

jobs:
deploy:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 16

- name: Cache node modules
uses: actions/cache@v3
id: npm-cache
with:
path: "**/node_modules"
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-

- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
echo 'npm cache existed'
npm ci

- name: Assign assignee
uses: hkusu/review-assign-action@v1
with:
assignees: ${{ github.actor }}

- name: Assign reviewers randomly
uses: ./.github/actions/reviewers
with:
github_token: ${{secrets.token}}
reviewers: ${{vars.reviewers}}
17 changes: 0 additions & 17 deletions .github/workflows/review.yml

This file was deleted.

203 changes: 200 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading