Quick overview
This workflow runs on a schedule to maintain a GitHub organization by labeling inactive pull requests as stale and closing them later, deleting old non-default branches, and archiving repositories that have been inactive for 90+ days.
How it works
- Runs on a scheduled trigger.
- Fetches all repositories in a specified GitHub organization and continues only for repositories that are not already archived.
- For each repository, retrieves open pull requests and labels PRs that have not been updated for more than 5 days with a "stale" label, then posts a comment warning they will be closed in 5 days.
- For PRs already labeled "stale", fetches the PR issue events, finds when the stale label was applied, and closes the PR if the label is older than 5 days.
- Retrieves the repository’s branches, filters out the default branch, and deletes branches whose latest commit is older than 30 days.
- Checks how long the repository has been inactive based on its last update time and archives the repository if it has not been updated for more than 90 days.
Setup
- Create or select a GitHub App credential in n8n with permissions to read repositories/PRs and to comment, label, close PRs, delete refs (branches), and archive repositories.
- Set the GitHub organization name in the organization lookup so it matches the org you want to maintain.
- Configure the schedule interval to control how often cleanup runs.
- Ensure the target repositories allow branch deletion and that your GitHub App has access to all repositories you want this workflow to manage.