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

[레벨 3 글쓰기 미션] 리버(최재희) 미션 제출합니다. #356

Closed
wants to merge 1 commit into from
Closed
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
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;
}
Loading