Skip to content

Commit

Permalink
Merge pull request #93 from boostcampwm-2024/Feature/#085_Github_Actiโ€ฆ
Browse files Browse the repository at this point in the history
โ€ฆons_์„ค์ •

Feature/#85 auto_merge_approved_pr.yml ์˜ค๋ฅ˜ ์ˆ˜์ •
  • Loading branch information
github-actions[bot] authored Nov 12, 2024
2 parents 9b4b32e + 65004d1 commit 98b1c78
Showing 1 changed file with 46 additions and 6 deletions.
52 changes: 46 additions & 6 deletions .github/workflows/auto_merge_approved_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,56 @@ jobs:
pull_number: pull_number,
});
const approvals = reviews.data.filter(review => review.state === 'APPROVED');
return approvals.length >= 2;
const approvalCount = approvals.length;
core.info(`PR #${pull_number} has ${approvalCount} approval(s).`);
return approvalCount >= 2;
- name: "Merge PR"
if: ${{ steps.check.outputs.result == 'true' }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pull_number = context.payload.pull_request.number;
await github.rest.pulls.merge({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pull_number,
});
// PR ์ •๋ณด ๋ฐ ๋ณ‘ํ•ฉ ๊ฐ€๋Šฅ ์ƒํƒœ ํ™•์ธ
let pr;
for (let i = 0; i < 5; i++) { // ์ตœ๋Œ€ 5ํšŒ ์žฌ์‹œ๋„
const { data } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pull_number,
});
pr = data;
if (pr.state !== 'open') {
core.info(`PR #${pull_number} is not open (state: ${pr.state}).`);
return;
}
if (pr.mergeable === true) {
break; // ๋ณ‘ํ•ฉ ๊ฐ€๋Šฅํ•˜๋ฉด ๋ฃจํ”„ ์ข…๋ฃŒ
} else if (pr.mergeable === false) {
core.info(`PR #${pull_number} cannot be merged due to conflicts or other issues.`);
return;
} else {
// mergeable์ด null์ธ ๊ฒฝ์šฐ (๊ณ„์‚ฐ ์ค‘), ์ž ์‹œ ๋Œ€๊ธฐ ํ›„ ์žฌ์‹œ๋„
await new Promise(resolve => setTimeout(resolve, 2000)); // 2์ดˆ ๋Œ€๊ธฐ
}
}
if (pr.mergeable !== true) {
core.info(`PR #${pull_number} mergeable status is unknown after retries.`);
return;
}
// PR ๋ณ‘ํ•ฉ ์‹œ๋„
try {
await github.rest.pulls.merge({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pull_number,
});
core.info(`PR #${pull_number} has been merged successfully.`);
} catch (error) {
core.info(`Failed to merge PR #${pull_number}: ${error.message}`);
}

0 comments on commit 98b1c78

Please sign in to comment.