-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EVEREST-107 Add workflow for auto-updating PR's base branch (#1016)
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
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} |