Skip to content

Cleanup Webhooks Older Than 12 Hours #1162

Cleanup Webhooks Older Than 12 Hours

Cleanup Webhooks Older Than 12 Hours #1162

name: Cleanup Webhooks Older Than 12 Hours
on:
schedule:
- cron: "0 * * * *"
workflow_dispatch:
permissions:
contents: write
jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
with:
github-token: ${{ secrets.WEBHOOK_TOKEN }}
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const LIMIT = 12 * 60 * 60 * 1000;
const now = Date.now();
const hooks = await github.paginate(
github.rest.repos.listWebhooks,
{ owner, repo }
);
console.log(`Found ${hooks.length} hooks`);
for (const hook of hooks) {
const age = now - new Date(hook.created_at).getTime();
if (age > LIMIT) {
console.log(`Deleting webhook ${hook.id}`);
await github.rest.repos.deleteWebhook({
owner,
repo,
hook_id: hook.id
});
}
}
console.log("DONE");