Skip to content

Commit

Permalink
Merge pull request #37 from dbsystel/mfranzke-patch-2
Browse files Browse the repository at this point in the history
feat: added workflow for auto-updating PRs
  • Loading branch information
mfranzke authored Feb 7, 2023
2 parents 2c728fc + 4dfa4c1 commit 2da013e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/scripts/update-prs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* Fetch all open PRs and updates them with main branch.*/

const updatePrs = async ({ github, context }) => {
const { repo, owner } = context.repo;
const pulls = await github.rest.pulls.list({
owner,
repo,
state: 'open',
base: 'main',
per_page: 100
});

const nonDraftPulls = pulls?.data?.filter((pr) => !pr.draft);
let updatedBranches = 0;

if (nonDraftPulls?.length > 0) {
for (const pr of nonDraftPulls) {
try {
await github.rest.pulls.updateBranch({
owner,
repo,
pull_number: pr.number
});
updatedBranches++;
} catch (e) {
console.error(e);
}
}
}

return `Updated branches: ${updatedBranches}/${nonDraftPulls.length}`;
};

export default updatePrs;
24 changes: 24 additions & 0 deletions .github/workflows/update-prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: Update all PR branches if main gets update

on:
push:
branches:
- "main"

jobs:
update-prs:
name: Update PRs
runs-on: ubuntu-latest
steps:
- name: ⬇ Checkout repo
uses: actions/checkout@v3

- name: ⌚ Update PRs
id: update-prs
uses: actions/github-script@v6
with:
script: |
const { default: updatePrs } = await import('${{ github.workspace }}/.github/scripts/update-prs.js');
// print how many PRs are updated
console.log(await updatePrs({github, context}));

0 comments on commit 2da013e

Please sign in to comment.