Skip to content

Commit

Permalink
Merge pull request #149 from boostcampwm-2024/bug-shared-#148
Browse files Browse the repository at this point in the history
CI 스크립트(자동 병합, 리뷰어 지정) 실행 시점 수정
  • Loading branch information
summersummerwhy authored Nov 14, 2024
2 parents 97b8385 + 322adb4 commit 7f8faa6
Showing 1 changed file with 33 additions and 15 deletions.
48 changes: 33 additions & 15 deletions .github/workflows/auto-assign-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ name: Auto Assign, Review, and Merge
on:
pull_request:
types:
[
opened,
labeled,
unlabeled,
review_requested,
review_request_removed,
]
- opened
- labeled
- unlabeled
- review_requested
- review_request_removed
pull_request_review:
types: [submitted]
types:
- submitted

jobs:
auto-assign:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand All @@ -37,6 +37,7 @@ jobs:
});
auto-reviewers:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
needs: auto-assign
steps:
Expand All @@ -53,25 +54,31 @@ jobs:
with:
script: |
const prNumber = context.payload.pull_request.number;
const prAuthor = context.payload.pull_request.user.login;
const assignees = context.payload.pull_request.assignees.map(a => a.login);
// Define reviewers for each label
const BE_reviewers = ['summersummerwhy', 'ezcolin2', 'Tolerblanc'].filter(r => !assignees.includes(r));
const FE_reviewers = ['yewonJin', 'djk01281'].filter(r => !assignees.includes(r));
const doc_reviewers = ['summersummerwhy', 'ezcolin2', 'Tolerblanc', 'yewonJin', 'djk01281'].filter(r => !assignees.includes(r));
const BE_reviewers = ['summersummerwhy', 'ezcolin2', 'Tolerblanc'];
const FE_reviewers = ['yewonJin', 'djk01281'];
const doc_reviewers = ['summersummerwhy', 'ezcolin2', 'Tolerblanc', 'yewonJin', 'djk01281'];
// Function to filter out assignees and PR author
const filterReviewers = (reviewers) => {
return reviewers.filter(r => !assignees.includes(r) && r !== prAuthor);
};
// Check the labels on the PR and assign appropriate reviewers
const labels = context.payload.pull_request.labels.map(label => label.name);
let reviewersToAdd = [];
if (labels.includes('🐧🚀😶‍🌫️ BE')) {
reviewersToAdd.push(...BE_reviewers);
reviewersToAdd.push(...filterReviewers(BE_reviewers));
}
if (labels.includes('🐳🐣 FE')) {
reviewersToAdd.push(...FE_reviewers);
reviewersToAdd.push(...filterReviewers(FE_reviewers));
}
if (labels.includes('📚 Documentation')) {
reviewersToAdd.push(...doc_reviewers);
reviewersToAdd.push(...filterReviewers(doc_reviewers));
}
// Remove duplicates if any
Expand All @@ -88,9 +95,9 @@ jobs:
}
auto-merge:
if: github.event_name == 'pull_request_review' && github.event.action == 'submitted' && github.event.review.state == 'approved'
runs-on: ubuntu-latest
needs: [auto-assign, auto-reviewers]
if: github.event.pull_request.merged == false
steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand All @@ -106,6 +113,17 @@ jobs:
script: |
const prNumber = context.payload.pull_request.number;
// Check if PR is already merged
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber
});
if (pr.data.merged) {
return;
}
// Check if PR is approved
const reviews = await github.rest.pulls.listReviews({
owner: context.repo.owner,
Expand Down

0 comments on commit 7f8faa6

Please sign in to comment.