Quick Overview
This workflow runs weekly (or manually) to scan GitHub repositories for merged-but-not-deleted and stale branches, then posts a cleanup report to Slack and can optionally auto-delete a capped number of branches.
How it works
- Runs on a weekly schedule or when you manually execute the workflow.
- Loads configuration for the GitHub repo owner, repository list, stale age threshold, protected branch patterns, Slack channel, and deletion limits.
- For each configured repository, fetches all branches via the GitHub GraphQL API and fetches recently merged pull requests via the GitHub REST API.
- Classifies branches as protected (skipped), merged-but-not-deleted, or stale based on last commit date and the configured stale-days threshold.
- If auto-delete is enabled, deletes up to the configured maximum number of candidate branches in GitHub and compiles a success/failure summary.
- Formats and posts the cleanup report to Slack, and if deletions ran, posts a second Slack message with the deletion results.
Setup
- Create and add GitHub credentials (fine-grained token or PAT) with access to list branches/PRs and permission to delete branches if you enable auto-delete.
- Create and add a Slack credential with permission to post messages (chat:write) and set the target channel in the configuration.
- Update the configuration values for repo owner, comma-separated repo list, staleDays, protectedBranches, reportOnly, and maxBranchesToDelete before activating the workflow.