Skip to content

Commit

Permalink
Create merge-all-open-prs.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Wonmi91 authored Apr 29, 2024
1 parent 1b0e265 commit e660713
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/merge-all-open-prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: 열려있는 모든 PR 머지

on:
workflow_dispatch:

jobs:
mergePRs:
runs-on: ubuntu-latest
steps:
- name: Merge all open PRs
uses: actions/github-script@v6
with:
script: |
const OWNER = "woowacourse";
const REPO = "woowa-writing";
async function getPRs(afterCursor) {
// GraphQL query to fetch the list of open pull requests
const query = `
{
repository(owner:"${OWNER}", name:"${REPO}") {
pullRequests(states:OPEN, first: 100, after: ${afterCursor ? `"${afterCursor}"` : null}) {
nodes {
number
mergeable
}
pageInfo {
endCursor
hasNextPage
}
}
}
}`;
return await github.graphql(query);
}
let cursor;
let hasNextPage = true;
while (hasNextPage) {
const { repository: { pullRequests: { nodes: prs, pageInfo } } } = await getPRs(cursor);
const mergeablePRs = prs.filter(pr => pr.mergeable);
for (const pr of mergeablePRs) {
try {
const mergeResponse = await github.rest.pulls.merge({
owner: OWNER,
repo: REPO,
pull_number: pr.number,
merge_method: 'squash'
});
if (mergeResponse.data.merged) {
console.log(`Merged (squashed) PR #${pr.number}`);
} else {
console.log(`Could not merge PR #${pr.number}: ${mergeResponse.data.message}`);
}
} catch (error) {
console.error(`Error merging PR #${pr.number}:`, error);
}
}
cursor = pageInfo.endCursor;
hasNextPage = pageInfo.hasNextPage;
}

0 comments on commit e660713

Please sign in to comment.