mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-07-17 10:42:07 +08:00
ci: delete closed PR branches automatically (#38280)
This commit is contained in:
@@ -3,6 +3,8 @@ name: repo maintenance
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 14 * * 1" # every Monday at 2am UTC (6am PST)
|
||||
pull_request:
|
||||
types: [closed]
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
@@ -12,7 +14,9 @@ jobs:
|
||||
package_updates:
|
||||
name: package_updates
|
||||
runs-on: ubuntu-latest
|
||||
if: github.repository == 'commaai/openpilot'
|
||||
if: >-
|
||||
github.repository == 'commaai/openpilot' &&
|
||||
(github.event_name == 'schedule' || github.event_name == 'workflow_dispatch')
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
with:
|
||||
@@ -71,3 +75,43 @@ jobs:
|
||||
${{ steps.pip_tree.outputs.PIP_TREE }}
|
||||
```
|
||||
labels: bot
|
||||
|
||||
cleanup_closed_branches:
|
||||
if: github.repository == 'commaai/openpilot'
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: read
|
||||
steps:
|
||||
- uses: actions/github-script@v9
|
||||
with:
|
||||
script: |
|
||||
const { owner, repo } = context.repo;
|
||||
const upstream = `${owner}/${repo}`;
|
||||
|
||||
for await (const response of github.paginate.iterator(github.rest.pulls.list, {
|
||||
owner,
|
||||
repo,
|
||||
state: 'closed',
|
||||
per_page: 100,
|
||||
})) {
|
||||
for (const pr of response.data) {
|
||||
if (pr.head.repo?.full_name !== upstream) continue;
|
||||
|
||||
const branch = pr.head.ref;
|
||||
try {
|
||||
await github.rest.git.deleteRef({
|
||||
owner,
|
||||
repo,
|
||||
ref: `heads/${branch}`,
|
||||
});
|
||||
console.log(`Deleted branch ${branch} (PR #${pr.number})`);
|
||||
} catch (error) {
|
||||
if (error.status === 422 || error.status === 403) {
|
||||
console.log(`Skipping branch ${branch} (PR #${pr.number}): ${error.message}`);
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user