From 476dee4f0a5d36e7adfc0e1da153b74e8808efb2 Mon Sep 17 00:00:00 2001 From: Maximilian Franzke <787658+mfranzke@users.noreply.github.com> Date: Tue, 7 Feb 2023 06:49:37 +0100 Subject: [PATCH 1/3] feat: added workflow for auto-updating PRs --- .github/workflows/update-prs.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/update-prs.yml diff --git a/.github/workflows/update-prs.yml b/.github/workflows/update-prs.yml new file mode 100644 index 0000000..5641d3f --- /dev/null +++ b/.github/workflows/update-prs.yml @@ -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: cleanup + 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})); From 1fdbd32e480449c4e94713b6ded515ad9a951e7c Mon Sep 17 00:00:00 2001 From: Maximilian Franzke <787658+mfranzke@users.noreply.github.com> Date: Tue, 7 Feb 2023 06:50:56 +0100 Subject: [PATCH 2/3] Create update-prs.js --- .github/scripts/update-prs.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/scripts/update-prs.js diff --git a/.github/scripts/update-prs.js b/.github/scripts/update-prs.js new file mode 100644 index 0000000..8fcf23a --- /dev/null +++ b/.github/scripts/update-prs.js @@ -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; From db782c63649734b2fc0378119ab1fe856ab8e252 Mon Sep 17 00:00:00 2001 From: Maximilian Franzke <787658+mfranzke@users.noreply.github.com> Date: Tue, 7 Feb 2023 06:56:15 +0100 Subject: [PATCH 3/3] Update update-prs.yml --- .github/workflows/update-prs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-prs.yml b/.github/workflows/update-prs.yml index 5641d3f..389fd99 100644 --- a/.github/workflows/update-prs.yml +++ b/.github/workflows/update-prs.yml @@ -15,7 +15,7 @@ jobs: uses: actions/checkout@v3 - name: ⌚ Update PRs - id: cleanup + id: update-prs uses: actions/github-script@v6 with: script: |