72 lines
2.6 KiB
YAML
72 lines
2.6 KiB
YAML
|
|
# ======================================================================================
|
|
# Workflow: Cleanup Fix PRs
|
|
# ======================================================================================
|
|
# Usage:
|
|
# - This workflow cleans up PRs generated by Fix Failing Checks
|
|
#
|
|
# Expected Output:
|
|
# - The workflow should close all PRs created by the github-actions bot that are based on a branch with the auto-fix-ci label after it closes
|
|
#
|
|
# ======================================================================================
|
|
|
|
name: Cleanup Fix PRs
|
|
on:
|
|
pull_request:
|
|
types: [closed]
|
|
|
|
jobs:
|
|
close-fix-prs:
|
|
runs-on: ubuntu-latest
|
|
if: contains(github.event.pull_request.labels.*.name, 'auto-fix-ci')
|
|
steps:
|
|
- name: Close Dependent Fix PRs
|
|
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
|
|
with:
|
|
script: |
|
|
const { pull_request: pr, repository } = context.payload;
|
|
const { owner, repo } = context.repo;
|
|
|
|
const closedBranch = pr.head.ref;
|
|
console.log(`Original PR #${pr.number} closed. Head ref was: ${closedBranch}`);
|
|
|
|
// Find open PRs that target the closed PR's branch
|
|
const { data: openPRs } = await github.rest.pulls.list({
|
|
owner,
|
|
repo,
|
|
state: 'open',
|
|
base: closedBranch
|
|
});
|
|
|
|
if (openPRs.length === 0) {
|
|
console.log('No open fix PRs found targeting this branch.');
|
|
return;
|
|
}
|
|
|
|
console.log(`Found ${openPRs.length} open PRs targeting ${closedBranch}. Closing them...`);
|
|
|
|
for (const openPR of openPRs) {
|
|
if (openPR.user.login !== 'github-actions[bot]') {
|
|
console.log(`Skipping PR #${openPR.number} created by ${openPR.user.login} (not github-actions[bot])`);
|
|
continue;
|
|
}
|
|
|
|
console.log(`Closing PR #${openPR.number}: ${openPR.title}`);
|
|
|
|
// Comment on the fix PR
|
|
await github.rest.issues.createComment({
|
|
owner,
|
|
repo,
|
|
issue_number: openPR.number,
|
|
body: `Closing this fix PR because the parent PR #${pr.number} has been merged.`
|
|
});
|
|
|
|
// Close the fix PR
|
|
await github.rest.pulls.update({
|
|
owner,
|
|
repo,
|
|
pull_number: openPR.number,
|
|
state: 'closed'
|
|
});
|
|
}
|