Skip to content

Commit

Permalink
EVEREST-107 Add workflow for auto-updating PR's base branch (#1016)
Browse files Browse the repository at this point in the history
This workflow runs on every commit to main and updates the base branch
of every PR with the 'auto-update-base' label.
  • Loading branch information
recharte authored Jan 20, 2025
1 parent bda2ab6 commit 314073c
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/auto-update-base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Auto-Update PR Base

on:
push:
branches:
- main

jobs:
auto-update-base:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
with:
script: |
try {
const { data: pulls } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: "open",
});
for (const pull of pulls) {
const hasAutoUpdateLabel = pull.labels.some(label => label.name === "auto-update-base");
if (hasAutoUpdateLabel) {
try {
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pull.number,
});
if (pr.data.mergeable_state === 'dirty') {
console.log(`[INFO] PR #${pull.number}: "${pull.title}" - Skipping update due to merge conflict.`);
continue;
}
if (pr.data.mergeable_state !== 'behind') {
console.log(`[INFO] PR #${pull.number}: "${pull.title}" - Base branch is up-to-date.`);
continue;
}
console.log(`[UPDATE] PR #${pull.number}: "${pull.title}" - Updating base branch...`);
try {
await github.rest.pulls.updateBranch({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pull.number,
});
console.log(`[SUCCESS] PR #${pull.number}: "${pull.title}" - Base branch updated.`);
} catch (updateError) {
console.error(`[ERROR] PR #${pull.number}: Failed to update base branch - ${updateError.message}`);
}
} catch (diffError) {
console.error(`[ERROR] PR #${pull.number}: Failed to compare commits - ${diffError.message}`);
}
}
}
} catch (error) {
console.error(`[ERROR] Failed to list pull requests - ${error.message}`);
}

0 comments on commit 314073c

Please sign in to comment.