Schedule icon
Script icon
If icon
Create icon
SlackIncomingWebhook icon
Log icon

GitHub Stale Unmerged Branch Hygiene and Governance Sentinel

Monitor GitHub repository branch sprawl and stale Git branches with Kestra. Query GitHub API, open cleanup issues, and alert teams on Slack.

Categories
CoreInfrastructure

Large engineering teams create hundreds of feature, bugfix, and experimental branches across primary repositories. Over time, abandoned branches that were never merged or deleted accumulate, creating clutter in developer Git clones, triggering unintended CI workflow runs, and complicating commit history searches. This blueprint queries the GitHub REST API weekly for unprotected branches, compares commit dates against a configurable inactivity threshold (e.g. 90 days), logs an automated GitHub cleanup audit ticket, and notifies engineering teams on Slack.

How it works

  1. weekly_branch_hygiene_check (io.kestra.plugin.core.trigger.Schedule) initiates the audit every Monday at 09:00 UTC (shipped disabled for safe verification).
  2. probe_stale_branches (io.kestra.plugin.scripts.python.Script) interrogates the GitHub REST API (GET /repos/{owner}/{repo}/branches), checks commit timestamps on unprotected branches, and filters for branches inactive beyond stale_days_threshold.
  3. branch_on_stale_branches (io.kestra.plugin.core.flow.If) evaluates whether any stale branches were discovered (has_stale == true):
    • then: Automatically files a GitHub tracking issue via create_branch_hygiene_issue (io.kestra.plugin.github.issues.Create) and alerts the Slack channel via alert_devops_slack (io.kestra.plugin.slack.notifications.SlackIncomingWebhook).
    • else: Emits an informational log entry (log_branches_clean) confirming clean branch hygiene.
  4. log_audit_complete (io.kestra.plugin.core.log.Log) records the audit outcome.
  5. The errors block alerts Slack if GitHub API limits are reached or tokens expire.

What you get

  • Automated, scheduled auditing of repository branch hygiene.
  • Zero manual terminal scripts required to locate abandoned feature branches.
  • Consolidated GitHub tracking issues listing branch names, last commit dates, and author names.
  • Real-time Slack notifications with direct ticket hyperlinks.

Who it's for

  • Platform Engineers and DevOps leads maintaining corporate GitHub repositories.
  • Engineering Managers enforcing repository cleanliness and developer productivity.
  • Open source maintainers keeping active contributor repositories tidy.

Why orchestrate this with Kestra

Kestra coordinates external API polling, date arithmetic, conditional issue creation, and chat alerting inside a single declarative workflow. It manages personal access tokens securely, provides complete execution history, and eliminates the need for separate standalone monitoring daemons.

Prerequisites

  • A GitHub repository with active development branches.
  • A GitHub Personal Access Token or GitHub App token with repo permissions.
  • A Slack incoming webhook URL for notifications.

Secrets

  • GITHUB_TOKEN: GitHub token used to query repository branches and open tracking issues.
  • SLACK_WEBHOOK: Incoming Webhook URL for alerts.

Inputs

  • repository (STRING, default my-org/primary-backend): Target GitHub repository (owner/repo) to audit.
  • stale_days_threshold (INT, default 90): Number of inactive days before a branch is classified stale.
  • target_issue_repository (STRING, default my-org/primary-backend): Repository where the governance issue will be created.

Outputs

  • outputs.probe_stale_branches.vars.total_branches: Total number of unprotected branches audited.
  • outputs.probe_stale_branches.vars.stale_count: Count of branches exceeding inactivity threshold.
  • outputs.probe_stale_branches.vars.stale_branches: List of stale branch objects (name, last_commit, author).

Quick start

  1. Configure GITHUB_TOKEN and SLACK_WEBHOOK in your Kestra namespace.
  2. Import this flow and set repository to match an active development codebase.
  3. Run the flow manually to verify branch inspection and Slack notification delivery.
  4. Enable the weekly_branch_hygiene_check trigger for continuous Git hygiene monitoring.

How to extend

  • Add an automated branch deletion step (DELETE /repos/{owner}/{repo}/git/refs/heads/{branch}) gated behind an interactive approval task.
  • Filter branches by author email or department to send direct Slack DMs to branch owners.
  • Loop over all repositories in an organization using io.kestra.plugin.core.flow.ForEach.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.