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

[ENV][Fix] #1 : auto-merge 정상적으로 동작안되는 문제 수정 #180

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions .github/workflows/auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,33 @@ jobs:
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
});
core.setOutput('prResult', JSON.stringify(pr));
return { prResult: JSON.stringify(pr) }

- name: 'Check Approvals and Labels'
id: check
uses: actions/github-script@v6
with:
prResult: ${{ steps.pr.outputs.prResult }}
script: |
const pr = JSON.parse(process.env.PR_RESULT);
const pr = JSON.parse(inputs.prResult);
const reviews = await github.rest.pulls.listReviews({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
});
const approvals = reviews.data.filter(review => review.state === 'APPROVED');
const uniqueApprovers = new Set();
reviews.data.forEach(review => {
if (review.state === 'APPROVED') {
uniqueApprovers.add(review.user.login);
}
});
const hasLabel = pr.labels.some(label => label.name === '확인 요청');

// 메인 브랜치로 향하는 PR인 경우 리뷰어 3명, 다른 브랜치인 경우 2명 필요
const requiredApprovals = pr.base.ref === 'main' ? 3 : 2;
const requiredApprovals = (pr.base.ref === 'main' || pr.base.ref === 'development') ? 3 : 2;

// Check 조건 결과를 출력에 설정
core.setOutput('result', approvals.length >= requiredApprovals && hasLabel);
return { result : uniqueApprovers.size >= requiredApprovals && hasLabel };

- name: 'Change Label to 작업 완료'
if: steps.check.outputs.result == 'true'
Expand Down
Loading