Measures how long pull requests wait for review and merge from a GitHub CLI JSON export: time to first review, approval and merge with medians and p90 by size and author, reviewer load, and flags for slow first reviews, stale or unapproved PRs, oversized PRs and review bottlenecks. Stdlib Python.
---
name: pull-request-review-turnaround-analyzer
description: Measures how long pull requests wait for review and merge from a GitHub CLI JSON export: time to first review, approval and merge with medians and p90 by size and author, reviewer load, and flags for slow first reviews, stale or unapproved PRs, oversized PRs and review bottlenecks. Stdlib Python.
---
# Pull Request Review Turnaround Analyzer
You help developers, tech leads and engineering managers see where code review slows a team down: PRs waiting a day or more for a first look, large PRs that sit for a week, approvals that land on one person, and merges that skipped review. You work from a JSON export of the team's pull requests, report medians and p90 instead of averages, and turn the numbers into a few agreed team habits, not a ranking of people.
Use the numbers to improve the process, never to score individuals. Do not share per-person tables outside the team without the team's agreement, and remember that review time depends on time zones, on-call duty, holidays and PR size.
## Files in this skill
- `scripts/pr_turnaround.py` - reads `gh pr list --json ...` output, ignores self-reviews, measures time to first review, first approval and merge (optionally without weekends), size buckets (XS-XL), per-author and per-size medians and p90, reviewer load, and prints flags R01-R06 + E01; `--format text|md|json`; `--self-test` runs 14 checks (Python 3.8+ standard library only)
- `references/review-metrics.md` - what each metric means, healthy ranges for small teams, how to export data from GitHub (and GitLab via conversion), and the main pitfalls
- `references/improvement-playbook.md` - team habits and settings that fix each flag (review slots, PR size limits, CODEOWNERS rotation, draft PRs, branch protection)
- `templates/review-health-report.md` - a short retro or monthly engineering note
- `examples/prs.json` - 13 fictional PRs from a two-week sprint of a small shop team, with a huge refactor, a bot PR, an unreviewed hotfix, a stale PR and one overloaded reviewer
## Workflow
### 1. Export the data
Agree the window (a sprint, a month) and the repository. Then run, in the repository:
```
gh pr list --state all --limit 300 --search "created:>=2026-11-01" \
--json number,title,author,createdAt,mergedAt,closedAt,isDraft,additions,deletions,reviews,url > prs.json
```
For several repositories export each one and analyze them separately first (different teams, different norms). Agree the targets with the team: first review within 24 working hours (default), PRs under 400 changed lines, nothing open without review for more than 3 days.
### 2. Run the analysis
```
python3 scripts/pr_turnaround.py prs.json
python3 scripts/pr_turnaround.py prs.json --exclude-weekends --ignore-bots
python3 scripts/pr_turnaround.py prs.json --first-review-hours 8 --stale-days 2 --large-lines 300
python3 scripts/pr_turnaround.py prs.json --since 2026-11-16 --format md > review-health.md
python3 scripts/pr_turnaround.py prs.json --now 2026-11-27T17:00:00Z # reproducible ages for open PRs
python3 scripts/pr_turnaround.py --self-test
```
Exit code 0 = no flags, 1 = flags present, 2 = unreadable input.
| Code | Meaning |
|---|---|
| R01 | first review took longer than `--first-review-hours` |
| R02 | open, non-draft PR without any review for more than `--stale-days` |
| R03 | merged without an approval from someone other than the author |
| R04 | large PR (at least `--large-lines` changed lines, default 400) |
| R05 | one reviewer wrote at least half of all reviews (10+ reviews in the window) |
| R06 | changes were requested and nothing happened for more than `--stale-days` |
| E01 | PR entries that could not be parsed |
### 3. Interpret
- Look at the size table first: if L and XL PRs take days while XS and S take hours, the fix is smaller PRs, not faster reviewers.
- First review time is the main waiting cost; time to merge also includes the author's rework and CI.
- Use `--exclude-weekends` for teams that do not work weekends, otherwise Friday PRs look slow.
- Bot PRs (Renovate, Dependabot) follow other rules; analyze with and without `--ignore-bots`.
- R03 is not always wrong (an emergency hotfix), but each case should have a follow-up review.
- R05 is a bus-factor and burnout signal: one person approves most changes.
### 4. Act
Pick at most two habits from `references/improvement-playbook.md` that match the biggest flags, agree them in a retro, and re-run on the next sprint with the same options to compare.
### 5. Report
Fill `templates/review-health-report.md`: window, overall medians and p90, size table, reviewer load, flags, the agreed habits and the date of the next check.
FILE:references/review-metrics.md
# Review metrics
## Definitions (as computed by scripts/pr_turnaround.py)
- Time to first review: PR creation to the first submitted review (approve, comment or request changes) by someone other than the author. Self-reviews and pending reviews are ignored. Comments that are not part of a review are not counted.
- Time to first approval: creation to the first APPROVED review by someone else.
- Time to merge: creation to merge. Includes waiting, rework, CI and merge queues.
- Size: additions + deletions. Buckets: XS <50, S 50-199, M 200-399, L 400-999, XL 1000+.
- Median and p90: half of the PRs are faster than the median; 9 out of 10 are faster than p90. Averages hide the slow tail, so they are not used.
- Weekends: with --exclude-weekends, Saturday and Sunday in UTC do not count. Teams far from UTC should keep this in mind.
## Healthy ranges for small product teams (rules of thumb)
- First review median: a few working hours; p90 within one working day.
- Merge median: within one or two working days for S and M PRs.
- Most PRs in XS-M; L and XL should be rare and announced.
- No single reviewer above about 40% of reviews in a team of four or more.
These are starting points to discuss, not targets to enforce.
## Exporting data
GitHub CLI (in the repository folder):
gh pr list --state all --limit 300 --search "created:>=2026-11-01" \
--json number,title,author,createdAt,mergedAt,closedAt,isDraft,additions,deletions,reviews,url > prs.json
- --limit must cover the window; raise it for busy repositories.
- Reviews in the export do not include the time a reviewer was requested; the script measures from PR creation.
- PRs opened as drafts and marked ready later look slower than they were; count draft time separately or exclude them with --since.
GitLab: export merge requests with the API and map fields to the same names: iid -> number, author.username -> author.login, created_at -> createdAt, merged_at -> mergedAt, closed_at -> closedAt, draft -> isDraft, approvals -> reviews with state APPROVED and submittedAt. Line counts need the changes endpoint.
## Pitfalls
- Do not compare people: authors who take the hardest work naturally have slower PRs.
- Time zones and on-call duty change first-review times a lot.
- Small samples: with fewer than about 10 PRs per group, treat medians as anecdotes.
- Holidays and code freezes distort a window; note them in the report.
FILE:references/improvement-playbook.md
# Improvement playbook: from flag to habit
Pick at most two changes per retro. Re-run the analysis after one sprint to see if they helped.
## R01 slow first reviews
- Review slots: everyone checks open PRs twice a day (for example after stand-up and after lunch) before starting new work.
- A shared rule: first look within one working day, even if it is only "I will review this afternoon".
- Turn on review request notifications in chat for the team channel, not only email.
- Use CODEOWNERS or auto-assignment with round-robin so a PR always has a named reviewer.
## R02 stale PRs without review
- A daily or weekly "PRs waiting" list in chat (gh pr list --search "review:none draft:false").
- Authors ping a specific person after one day instead of the whole channel.
- If a PR is not needed any more, close it; open PRs cost attention.
## R03 merged without approval
- Branch protection: require at least one approval and passing checks on the main branch.
- Allow an emergency path for hotfixes, but add a follow-up review issue within one working day.
- Check whether admins bypass protection by default.
## R04 large PRs
- Agree a soft limit (for example 400 changed lines) and split by layers or behind feature flags.
- Stacked PRs or a short design note before a big refactor.
- Exclude generated files and lockfiles from the diff with .gitattributes linguist-generated, so size reflects real review work.
## R05 one reviewer does most reviews
- Rotate reviewer duty weekly; pair a newer teammate with the main reviewer to spread knowledge.
- Widen CODEOWNERS to a team instead of one person.
- Protect focus time: the main reviewer should not be the default for every PR.
## R06 changes requested, then silence
- Authors answer review comments within one working day, even if only to say when they will fix them.
- Reviewers mark comments as blocking or optional (for example a "nit:" prefix) so authors know what really must change.
- Close or convert to draft if the work is paused.
FILE:templates/review-health-report.md
# Code review health - {{team or repository}} - {{window}}
## Numbers
- PRs: {{prs}} (merged {{merged}}, open or draft {{open}})
- First review: median {{first_review_median}}, p90 {{first_review_p90}} (target {{target}})
- Merge: median {{merge_median}}, p90 {{merge_p90}}
- Options used: {{for example --exclude-weekends --ignore-bots}}
## By size
| Size | PRs | First review median | Merge median |
|---|---:|---:|---:|
| {{bucket}} | {{n}} | {{first_review}} | {{merge}} |
## Reviewer load
- {{reviewer}}: {{reviews}} reviews ({{share}})
## Flags and context
- {{code}} {{where}}: {{detail}} - context: {{holiday, incident, hotfix, on-call}}
## Habits we agreed (max 2)
1. {{habit}} - owner {{name}}
2. {{habit}} - owner {{name}}
## Next check
Re-run on {{date}} with the same options and compare the first review p90 and the size table.
FILE:examples/prs.json
[
{
"number": 412,
"title": "Add invoice PDF export",
"author": {
"login": "maya"
},
"createdAt": "2026-11-16T09:10:00Z",
"mergedAt": "2026-11-17T15:30:00Z",
"closedAt": "2026-11-17T15:30:00Z",
"isDraft": false,
"additions": 180,
"deletions": 40,
"reviews": [
{
"author": {
"login": "deniz"
},
"submittedAt": "2026-11-16T13:05:00Z",
"state": "COMMENTED"
},
{
"author": {
"login": "deniz"
},
"submittedAt": "2026-11-17T10:20:00Z",
"state": "APPROVED"
}
],
"url": "https://github.com/example-shop/storefront/pull/412"
},
{
"number": 413,
"title": "Fix timezone in reminder emails",
"author": {
"login": "ali"
},
"createdAt": "2026-11-16T11:00:00Z",
"mergedAt": "2026-11-16T16:45:00Z",
"closedAt": "2026-11-16T16:45:00Z",
"isDraft": false,
"additions": 22,
"deletions": 6,
"reviews": [
{
"author": {
"login": "maya"
},
"submittedAt": "2026-11-16T12:10:00Z",
"state": "APPROVED"
}
],
"url": "https://github.com/example-shop/storefront/pull/413"
},
{
"number": 414,
"title": "Refactor billing service into modules",
"author": {
"login": "deniz"
},
"createdAt": "2026-11-17T08:30:00Z",
"mergedAt": "2026-11-21T17:00:00Z",
"closedAt": "2026-11-21T17:00:00Z",
"isDraft": false,
"additions": 1640,
"deletions": 1210,
"reviews": [
{
"author": {
"login": "selin"
},
"submittedAt": "2026-11-19T16:00:00Z",
"state": "CHANGES_REQUESTED"
},
{
"author": {
"login": "selin"
},
"submittedAt": "2026-11-21T11:30:00Z",
"state": "APPROVED"
}
],
"url": "https://github.com/example-shop/storefront/pull/414"
},
{
"number": 415,
"title": "Bump eslint to v9",
"author": {
"login": "renovate[bot]"
},
"createdAt": "2026-11-17T06:00:00Z",
"mergedAt": "2026-11-18T09:00:00Z",
"closedAt": "2026-11-18T09:00:00Z",
"isDraft": false,
"additions": 35,
"deletions": 30,
"reviews": [
{
"author": {
"login": "deniz"
},
"submittedAt": "2026-11-18T08:40:00Z",
"state": "APPROVED"
}
],
"url": "https://github.com/example-shop/storefront/pull/415"
},
{
"number": 416,
"title": "Add rate limit to public API",
"author": {
"login": "selin"
},
"createdAt": "2026-11-18T10:00:00Z",
"mergedAt": "2026-11-19T12:00:00Z",
"closedAt": "2026-11-19T12:00:00Z",
"isDraft": false,
"additions": 260,
"deletions": 20,
"reviews": [
{
"author": {
"login": "deniz"
},
"submittedAt": "2026-11-18T14:30:00Z",
"state": "APPROVED"
}
],
"url": "https://github.com/example-shop/storefront/pull/416"
},
{
"number": 417,
"title": "Hotfix: null check in checkout",
"author": {
"login": "ali"
},
"createdAt": "2026-11-19T18:20:00Z",
"mergedAt": "2026-11-19T18:35:00Z",
"closedAt": "2026-11-19T18:35:00Z",
"isDraft": false,
"additions": 4,
"deletions": 1,
"reviews": [],
"url": "https://github.com/example-shop/storefront/pull/417"
},
{
"number": 418,
"title": "Dark mode for settings page",
"author": {
"login": "maya"
},
"createdAt": "2026-11-20T15:00:00Z",
"mergedAt": "2026-11-24T10:00:00Z",
"closedAt": "2026-11-24T10:00:00Z",
"isDraft": false,
"additions": 320,
"deletions": 90,
"reviews": [
{
"author": {
"login": "deniz"
},
"submittedAt": "2026-11-23T09:00:00Z",
"state": "APPROVED"
}
],
"url": "https://github.com/example-shop/storefront/pull/418"
},
{
"number": 419,
"title": "Migrate cron jobs to queue workers",
"author": {
"login": "ali"
},
"createdAt": "2026-11-21T16:30:00Z",
"mergedAt": null,
"closedAt": null,
"isDraft": false,
"additions": 540,
"deletions": 210,
"reviews": [
{
"author": {
"login": "deniz"
},
"submittedAt": "2026-11-24T10:15:00Z",
"state": "CHANGES_REQUESTED"
}
],
"url": "https://github.com/example-shop/storefront/pull/419"
},
{
"number": 420,
"title": "Update onboarding copy",
"author": {
"login": "selin"
},
"createdAt": "2026-11-24T09:00:00Z",
"mergedAt": "2026-11-24T11:00:00Z",
"closedAt": "2026-11-24T11:00:00Z",
"isDraft": false,
"additions": 12,
"deletions": 12,
"reviews": [
{
"author": {
"login": "deniz"
},
"submittedAt": "2026-11-24T10:30:00Z",
"state": "APPROVED"
}
],
"url": "https://github.com/example-shop/storefront/pull/420"
},
{
"number": 421,
"title": "Experiment: new search ranking",
"author": {
"login": "deniz"
},
"createdAt": "2026-11-24T13:00:00Z",
"mergedAt": null,
"closedAt": "2026-11-26T09:00:00Z",
"isDraft": false,
"additions": 410,
"deletions": 60,
"reviews": [
{
"author": {
"login": "maya"
},
"submittedAt": "2026-11-25T09:30:00Z",
"state": "COMMENTED"
}
],
"url": "https://github.com/example-shop/storefront/pull/421"
},
{
"number": 422,
"title": "Add audit log table",
"author": {
"login": "maya"
},
"createdAt": "2026-11-24T08:00:00Z",
"mergedAt": null,
"closedAt": null,
"isDraft": false,
"additions": 150,
"deletions": 10,
"reviews": [],
"url": "https://github.com/example-shop/storefront/pull/422"
},
{
"number": 423,
"title": "WIP: mobile push notifications",
"author": {
"login": "ali"
},
"createdAt": "2026-11-26T14:00:00Z",
"mergedAt": null,
"closedAt": null,
"isDraft": true,
"additions": 700,
"deletions": 40,
"reviews": [],
"url": "https://github.com/example-shop/storefront/pull/423"
},
{
"number": 424,
"title": "Cache product list responses",
"author": {
"login": "selin"
},
"createdAt": "2026-11-26T08:00:00Z",
"mergedAt": "2026-11-26T15:20:00Z",
"closedAt": "2026-11-26T15:20:00Z",
"isDraft": false,
"additions": 95,
"deletions": 15,
"reviews": [
{
"author": {
"login": "deniz"
},
"submittedAt": "2026-11-26T09:10:00Z",
"state": "APPROVED"
}
],
"url": "https://github.com/example-shop/storefront/pull/424"
}
]
FILE:scripts/pr_turnaround.py
#!/usr/bin/env python3
"""pr_turnaround.py - pull request review turnaround analyzer. Python 3.8+ standard library only.
Input: JSON from the GitHub CLI, for example
gh pr list --state all --limit 300 --json number,title,author,createdAt,mergedAt,closedAt,isDraft,additions,deletions,reviews,url > prs.json
(a list of PR objects; reviews = [{author:{login}, submittedAt, state}]). GitLab or other exports work
if converted to the same keys.
Per PR it measures: time to first review by someone other than the author, time to first approval,
time to merge, and size (additions + deletions). It summarizes medians and p90 overall, by size
bucket and by author, shows reviewer load, and flags process problems.
Usage:
pr_turnaround.py prs.json [--now 2026-11-27T17:00:00Z] [--since 2026-11-01] [--exclude-weekends]
[--first-review-hours 24] [--stale-days 3] [--large-lines 400] [--ignore-bots]
[--format text|md|json]
pr_turnaround.py --self-test
Exit: 0 no flags, 1 flags present, 2 unreadable input.
Flags:
R01 first review took longer than --first-review-hours
R02 open, non-draft PR without any review older than --stale-days
R03 merged without an approval from someone other than the author
R04 large PR (>= --large-lines changed lines): slower and riskier to review
R05 reviewer concentration: one person wrote >= 50% of all reviews (10+ reviews)
R06 open PR waiting on the author after CHANGES_REQUESTED for longer than --stale-days
E01 entries that could not be parsed
"""
import argparse, json, statistics, sys
from datetime import datetime, timedelta, timezone
BUCKETS = [(50, "XS <50"), (200, "S 50-199"), (400, "M 200-399"), (1000, "L 400-999"), (10 ** 12, "XL 1000+")]
def ts(x):
if not x:
return None
return datetime.fromisoformat(x.replace("Z", "+00:00")).astimezone(timezone.utc)
def hours(a, b, exclude_weekends=False):
"""Hours from a to b; with exclude_weekends, Saturday and Sunday (UTC) do not count."""
if a is None or b is None:
return None
if b < a:
return 0.0
if not exclude_weekends:
return (b - a).total_seconds() / 3600
total, cur = 0.0, a
while cur < b:
nxt = min(b, (cur + timedelta(days=1)).replace(hour=0, minute=0, second=0, microsecond=0))
if cur.weekday() < 5:
total += (nxt - cur).total_seconds()
cur = nxt
return total / 3600
def pct(vals, p):
vals = sorted(v for v in vals if v is not None)
if not vals:
return None
k = (len(vals) - 1) * p / 100
lo, hi = int(k), min(int(k) + 1, len(vals) - 1)
return vals[lo] + (vals[hi] - vals[lo]) * (k - lo)
def bucket(n):
for lim, name in BUCKETS:
if n < lim:
return name
def is_bot(login):
return login.endswith("[bot]") or login.endswith("-bot") or login in ("dependabot", "renovate")
def analyze(prs, now, since=None, exclude_weekends=False, first_review_hours=24.0, stale_days=3.0, large_lines=400, ignore_bots=False):
rows, flags = [], []
for i, p in enumerate(prs):
try:
author = (p.get("author") or {}).get("login") or "unknown"
created = ts(p["createdAt"])
if since and created < since:
continue
if ignore_bots and is_bot(author):
continue
merged, closed = ts(p.get("mergedAt")), ts(p.get("closedAt"))
revs = sorted([(ts(r["submittedAt"]), (r.get("author") or {}).get("login") or "unknown", (r.get("state") or "").upper())
for r in p.get("reviews") or [] if r.get("submittedAt")], key=lambda x: x[0])
revs = [r for r in revs if r[1] != author and r[2] != "PENDING"]
first = revs[0][0] if revs else None
appr = next((r[0] for r in revs if r[2] == "APPROVED"), None)
size = int(p.get("additions") or 0) + int(p.get("deletions") or 0)
state = "merged" if merged else ("closed" if closed else ("draft" if p.get("isDraft") else "open"))
rows.append(dict(number=p.get("number"), title=p.get("title", ""), author=author, state=state, size=size,
bucket=bucket(size), reviewers=sorted({r[1] for r in revs}), reviews=revs,
first_review_h=hours(created, first, exclude_weekends),
approval_h=hours(created, appr, exclude_weekends),
merge_h=hours(created, merged, exclude_weekends),
age_h=hours(created, now, exclude_weekends), created=created, url=p.get("url", "")))
except Exception as e: # noqa: BLE001
flags.append(dict(code="E01", where="entry %d" % i, detail=str(e)))
stale_h = stale_days * 24
for r in rows:
ref = "#%s %s" % (r["number"], r["title"][:48])
if r["first_review_h"] is not None and r["first_review_h"] > first_review_hours:
flags.append(dict(code="R01", where=ref, detail="first review after %.1f h (target %g h)" % (r["first_review_h"], first_review_hours)))
if r["state"] == "open" and not r["reviews"] and r["age_h"] > stale_h:
flags.append(dict(code="R02", where=ref, detail="open %.1f h without any review" % r["age_h"]))
if r["state"] == "merged" and r["approval_h"] is None:
flags.append(dict(code="R03", where=ref, detail="merged without an approval from another person"))
if r["size"] >= large_lines and r["state"] != "closed":
flags.append(dict(code="R04", where=ref, detail="%d changed lines (%s)" % (r["size"], r["bucket"])))
if r["state"] == "open" and r["reviews"] and r["reviews"][-1][2] == "CHANGES_REQUESTED":
waited = hours(r["reviews"][-1][0], now, exclude_weekends)
if waited > stale_h:
flags.append(dict(code="R06", where=ref, detail="changes requested %.1f h ago, no new review since" % waited))
load = {}
for r in rows:
for _, who, _s in r["reviews"]:
load[who] = load.get(who, 0) + 1
total_reviews = sum(load.values())
if total_reviews >= 10:
top, n = max(load.items(), key=lambda kv: kv[1])
if n / total_reviews >= 0.5:
flags.append(dict(code="R05", where=top, detail="%d of %d reviews (%.0f%%): review knowledge and load sit with one person" % (n, total_reviews, 100 * n / total_reviews)))
def stats(sel):
f = [r["first_review_h"] for r in sel]; m = [r["merge_h"] for r in sel]
return dict(prs=len(sel), first_review_median_h=pct(f, 50), first_review_p90_h=pct(f, 90),
merge_median_h=pct(m, 50), merge_p90_h=pct(m, 90),
merged=sum(r["state"] == "merged" for r in sel), open=sum(r["state"] in ("open", "draft") for r in sel))
by_size = [dict(bucket=b, **stats([r for r in rows if r["bucket"] == b])) for _, b in BUCKETS if any(r["bucket"] == b for r in rows)]
by_author = [dict(author=a, **stats([r for r in rows if r["author"] == a])) for a in sorted({r["author"] for r in rows})]
reviewers = [dict(reviewer=k, reviews=v, share=round(v / total_reviews, 3)) for k, v in sorted(load.items(), key=lambda kv: -kv[1])]
return dict(summary=stats(rows), by_size=by_size, by_author=by_author, reviewers=reviewers, flags=flags,
prs=[{k: v for k, v in r.items() if k not in ("reviews", "created")} for r in rows])
def fh(x):
return "-" if x is None else ("%.1f h" % x if x < 48 else "%.1f d" % (x / 24))
def render(res, fmt):
if fmt == "json":
return json.dumps(res, indent=1, default=str)
md, out, s = fmt == "md", [], res["summary"]
H = (lambda t, l=2: "#" * l + " " + t) if md else (lambda t, l=2: t)
out.append(H("PR review turnaround"))
out.append("- PRs %d (merged %d, open/draft %d); first review median %s, p90 %s; merge median %s, p90 %s" % (
s["prs"], s["merged"], s["open"], fh(s["first_review_median_h"]), fh(s["first_review_p90_h"]), fh(s["merge_median_h"]), fh(s["merge_p90_h"])))
for title, key, name in (("By size (changed lines)", "by_size", "bucket"), ("By author", "by_author", "author")):
out += ["", H(title, 3)]
if md:
out += ["| %s | PRs | first review median | merge median | merge p90 |" % name, "|---|---:|---:|---:|---:|"]
for g in res[key]:
c = (g[name], str(g["prs"]), fh(g["first_review_median_h"]), fh(g["merge_median_h"]), fh(g["merge_p90_h"]))
out.append("| %s |" % " | ".join(c) if md else " %-12s %3s PRs first review %8s merge %8s p90 %8s" % c)
out += ["", H("Reviewer load", 3)]
for r in res["reviewers"]:
out.append("%s%s: %d reviews (%.0f%%)" % ("- " if md else " ", r["reviewer"], r["reviews"], 100 * r["share"]))
out += ["", H("Flags (%d)" % len(res["flags"]), 3)]
for f in res["flags"]:
out.append("%s%s %s: %s" % ("- " if md else " ", f["code"], f["where"], f["detail"]))
if not res["flags"]:
out.append(" none")
return "\n".join(out)
def self_test():
ok = 0
def check(c, name):
nonlocal ok
if not c:
raise SystemExit("FAIL " + name)
ok += 1
U = lambda s: ts(s)
check(abs(hours(U("2026-11-27T12:00:00Z"), U("2026-11-30T12:00:00Z")) - 72) < 1e-9, "calendar hours")
check(abs(hours(U("2026-11-27T12:00:00Z"), U("2026-11-30T12:00:00Z"), True) - 24) < 1e-9, "weekend excluded (Fri 12:00 -> Mon 12:00 = 24 h)")
check(hours(U("2026-11-28T10:00:00Z"), U("2026-11-29T10:00:00Z"), True) == 0, "weekend only = 0")
check(pct([1, 2, 3, 4], 50) == 2.5 and pct([], 50) is None, "percentile")
check(bucket(49) == "XS <50" and bucket(400) == "L 400-999" and bucket(5000) == "XL 1000+", "buckets")
rv = lambda who, t, st: {"author": {"login": who}, "submittedAt": t, "state": st}
base = lambda n, **k: dict(dict(number=n, title="pr%d" % n, author={"login": "a"}, createdAt="2026-11-23T09:00:00Z", mergedAt=None, closedAt=None, isDraft=False, additions=10, deletions=0, reviews=[]), **k)
now = U("2026-11-27T09:00:00Z")
prs = [base(1, mergedAt="2026-11-23T15:00:00Z", reviews=[rv("b", "2026-11-23T11:00:00Z", "APPROVED")]),
base(2, mergedAt="2026-11-25T09:00:00Z", reviews=[rv("b", "2026-11-24T21:00:00Z", "APPROVED")]),
base(3, mergedAt="2026-11-23T10:00:00Z", reviews=[rv("a", "2026-11-23T09:30:00Z", "APPROVED")]),
base(4),
base(5, isDraft=True),
base(6, additions=500, reviews=[rv("b", "2026-11-23T10:00:00Z", "CHANGES_REQUESTED")])]
r = analyze(prs, now)
codes = sorted(f["code"] + str(f["where"]).split()[0] for f in r["flags"])
check(codes == ["R01#2", "R02#4", "R03#3", "R04#6", "R06#6"], "flags %s" % codes)
check(r["prs"][2]["first_review_h"] is None, "self review ignored")
check(abs(r["summary"]["first_review_median_h"] - 2.0) < 1e-9, "first review median 2 h (PRs 1, 2, 6)")
check(r["summary"]["merged"] == 3 and r["summary"]["open"] == 3, "state counts")
check(len(analyze(prs, now, since=U("2026-11-24T00:00:00Z"))["prs"]) == 0, "since filter")
bots = [base(7, author={"login": "renovate[bot]"})]
check(len(analyze(bots, now, ignore_bots=True)["prs"]) == 0 and len(analyze(bots, now)["prs"]) == 1, "ignore bots")
many = [base(10 + i, mergedAt="2026-11-23T12:00:00Z", reviews=[rv("b" if i < 8 else "c", "2026-11-23T10:00:00Z", "APPROVED")]) for i in range(10)]
check([f["code"] for f in analyze(many, now)["flags"]] == ["R05"], "reviewer concentration")
e = analyze([{"number": 1}], now)
check([f["code"] for f in e["flags"]] == ["E01"], "bad entry E01")
check("first review" in render(r, "text") and render(r, "md").startswith("## ") and json.loads(render(r, "json"))["summary"]["prs"] == 6, "renderers")
print("self-test OK: %d checks" % ok)
def main():
ap = argparse.ArgumentParser(description=__doc__.split("\n")[0])
ap.add_argument("file", nargs="?")
ap.add_argument("--now", help="ISO time used as 'now' for open PR ages (default: current UTC time)")
ap.add_argument("--since", help="only PRs created on or after this date (YYYY-MM-DD)")
ap.add_argument("--exclude-weekends", action="store_true", help="do not count Saturday and Sunday (UTC)")
ap.add_argument("--first-review-hours", type=float, default=24.0)
ap.add_argument("--stale-days", type=float, default=3.0)
ap.add_argument("--large-lines", type=int, default=400)
ap.add_argument("--ignore-bots", action="store_true")
ap.add_argument("--format", choices=["text", "md", "json"], default="text")
ap.add_argument("--self-test", action="store_true")
a = ap.parse_args()
if a.self_test:
return self_test()
if not a.file:
ap.error("give a JSON file or --self-test")
try:
with open(a.file, encoding="utf-8") as fh_:
prs = json.load(fh_)
if not isinstance(prs, list):
raise ValueError("expected a JSON list of pull requests")
except (OSError, ValueError) as e:
print("error: %s" % e, file=sys.stderr); sys.exit(2)
now = ts(a.now) if a.now else datetime.now(timezone.utc)
since = ts(a.since + "T00:00:00Z") if a.since else None
res = analyze(prs, now, since, a.exclude_weekends, a.first_review_hours, a.stale_days, a.large_lines, a.ignore_bots)
print(render(res, a.format))
sys.exit(1 if res["flags"] else 0)
if __name__ == "__main__":
main()
GitHub AI Companion is a production-ready Windows desktop application that combines an animated AI desktop character with a real GitHub development agent. It lets users control GitHub repositories, Pull Requests, issues, Actions, local projects, and code changes through natural language, chat, or voice, while connecting to OpenAI, Gemini, NVIDIA, OpenRouter, and local Ollama models.
PROJECT: GitHub AI Companion Build a production-ready Windows desktop app: an animated AI desktop character that acts as a personal GitHub development agent. The assistant understands natural-language and voice commands, connects to GitHub, manages repositories, branches, Pull Requests, issues, and GitHub Actions, and helps with local coding projects. It must support OpenAI, Gemini, NVIDIA, OpenRouter, and local Ollama models through a modular provider system. Core features Transparent, draggable, always-on-top desktop character with animations and persistent position. Chat, voice input, text-to-speech, and context-aware project assistance. Real GitHub integration: repositories, files, commits, branches, Pull Requests, issues, Actions, and notifications. Autonomous agent engine with planning, tool use, execution, verification, and progress reporting. Local project support: scan, read, edit, search, refactor, run permitted commands, and inspect test results. Windows startup, system tray, background operation, notifications, and keyboard shortcuts. SQLite for local data; secure credential storage using Windows Credential Manager or DPAPI. Security rules Use minimum GitHub permissions, never hardcode API keys, validate all inputs, and require explicit confirmation for destructive actions such as deleting repositories/files, merging PRs, or running risky terminal commands. Provide Read Only, Assisted, and Trusted permission modes, with safeguards even in Trusted Mode. Tech stack Use C# with .NET 10 and WPF or WinUI 3. Use a modular layered architecture, async operations, dependency injection, structured logging, and clean separation between UI, AI, GitHub, agent, local development, Windows integration, persistence, and security. Deliverables Deliver complete working source code, an animated desktop character, full GitHub and AI-provider integrations, local Ollama support, voice interaction, SQLite persistence, automated tests, installer/portable build, and documentation. Also create a GitHub Actions workflow that automatically builds and uploads a portable Windows .exe on every push to main or manual run. Build rules Do not create a mockup or fake functionality. Implement real integrations, handle errors, verify successful operations, avoid TODOs and dead buttons, keep code modular, and build the app phase by phase until it is complete.
This prompt asks for RivalMode, a one-click GitHub repository template that turns a repo into a gamified, self-updating scoreboard directly inside its README. It must run entirely on GitHub Actions’ free tier using only the built-in GITHUB_TOKEN, with no servers, accounts, databases, external services, or additional API keys
GOAL Build "RivalMode" — a one-click repo template that gamifies a GitHub repository and its ecosystem, rendering a LIVE scoreboard inside the repo's own README. Everything runs on GitHub Actions (free tier) + a single workflow. No servers, no accounts, no API keys beyond the built-in GITHUB_TOKEN. TARGET USERS - Developers and vibe-coders who want their repo to feel alive and competitive. - OSS maintainers who want contributors to see progress in real time. - Anyone building in public who wants a live trophy wall. CORE FEATURES (numbered) 1. Live repo scoreboard in README: a rendered SVG (via workflow) showing branches, open PRs, merges/day, commits today vs this week, stars, forks, contributors leaderboard, and a "momentum score" (activity vs 7-day average). 2. Rival tracking (the hook): a daily workflow scans for (a) forks with more commits than upstream, (b) same-topic repos (via GitHub search using the repo's primary topics), and (c) repos that starred YOUR repo (they're fans — list them). Rivals are ranked by star velocity. The README shows "You are #3 in your topic cluster" and names who's ahead. 3. Auto-updating README sections: a badge row (momentum, rank, streak of days-with-a-commit), a mini bar-race SVG of contributor commit counts this month, and a "recent conquests" list (issues closed, PRs merged, releases). 4. Event feed: the last 10 repo events (pushes, stars, forks, releases) rendered as timestamped lines in the README, updated hourly by Actions. 5. Weekly recap comment: every Monday, the workflow posts a friendly week-in-review issue comment (commits, top contributor, momentum change, rivals gained/lost) — public, shareable, zero effort. 6. One-command install: "Use this template" button + a single setup workflow that writes the README sections and schedules the jobs. Uninstall = delete one folder. All state in the repo itself (JSON + generated SVGs committed back by the bot identity). 7. Privacy & safety: public data only (the repo's own events + public search); no user tracking; rate-limit aware (ETag caching); works for private repos in degraded mode (no rival search). TECH STACK - GitHub Actions workflows (schedule: hourly scoreboard, daily rivals, weekly recap) using gh CLI + GitHub REST/GraphQL via curl or actions/github-script. - Node 20 or Python 3.12 (pick one) single-file script that fetches, computes, renders SVGs, and commits via [bot identity]. - No external services, no databases, no frontend framework. README is the UI. - Shields.io-style SVG generation written from scratch (no dependency). PROJECT STRUCTURE .github/workflows/scoreboard.yml, rivals.yml, weekly-recap.yml, setup.yml src/ (fetchers, scoring, svg/, render_readme.js) state/ (rivals.json, momentum.json — committed by the bot) templates/ (README sections, SVG partials) examples/, tests/ (fixtures for API responses; golden SVG tests), LICENSE (MIT) README REQUIREMENTS - Badges: momentum score, cluster rank, license. - 15-second animated demo GIF: a README visibly updating itself after a push, and a rival overtaking the repo's rank live. - Quick start: click "Use this template" → done; README shows first scoreboard within one workflow run. No tokens needed. - "How the game works" table: points for commits, merges, stars, beating rivals. - A live example: link to the RivalMode repo itself using RivalMode (the project must be its own first user — eat your own dog food). TESTING - Fixture-based unit tests for scoring and SVG generation. - Integration test workflow that runs the full pipeline against a scratch repo. - Snapshot tests for README rendering; API-failure graceful degradation tests. LICENSE: MIT. FIRST-RELEASE CHECKLIST - Ship with the project's own README as the flagship live demo. - Launch angle: "My repo roasts me when a rival passes it" — post the moment a fork out-commits your repo; pin that README state. - Seed 3-5 template categories (app, cli, skill, site) so rivals clustering works out of the box. - CONTRIBUTING.md: community themes for the scoreboard SVG (the visual moat).
This prompt asks for CommitSage, a local-first Python CLI that uses AI to review staged Git changes before a commit. It should help developers understand changes, identify plausible bugs and missing tests, and produce reports in English or Persian—without requiring a CommitSage account, web dashboard, authentication, billing, or GitHub integration.
Build CommitSage, a local-first AI code review CLI that reviews staged Git changes before a commit.
Product goal:
Help developers understand their changes, identify plausible bugs, and find missing tests. Support English and Persian output, local and cloud AI providers, and usage without a CommitSage account.
Scope:
Build a working, focused MVP. Do not build a web dashboard, authentication, billing, or automatic GitHub integration.
Tech stack:
- Python 3.11+
- Typer for the CLI
- Rich for terminal output
- Pydantic for configuration and structured review results
- httpx for model requests
- pytest for tests
- pyproject.toml with an installable `commitsage` entry point
Commands:
1. `commitsage review`
Review staged changes by default.
2. `commitsage review --lang fa`
Produce Persian explanations while preserving code, paths, and identifiers.
3. `commitsage review --format markdown`
Produce a clean Markdown report.
4. `commitsage review --format json`
Produce machine-readable JSON.
5. `commitsage review --output review.md`
Save the report to a file.
6. `commitsage commit-message`
Suggest a Conventional Commit message from staged changes.
Do not create a commit.
7. `commitsage pr-description`
Draft a PR description from staged changes.
Clearly state this scope; do not imply that the whole branch was reviewed.
Review behavior:
- Read the staged diff and staged versions of changed files.
- Do not accidentally use unstaged working-tree changes as staged context.
- Gather a limited amount of surrounding code when necessary.
- Prioritize correctness, security, error handling, and missing tests.
- Avoid generic advice, unnecessary refactoring, and style-only complaints.
- Treat findings as potential issues, not proven bugs.
- Every finding must include:
- Severity: high, medium, or low
- File path
- Relevant line in the new file, or null if unavailable
- Short title
- Explanation grounded in the supplied code
- Suggested verification or fix
- Confidence: high, medium, or low
- Validate file paths and line references against the supplied diff.
- Discard findings with invalid locations rather than inventing replacements.
- Clearly distinguish observed code from assumptions.
- If no actionable findings are identified, say so without claiming the code is bug-free.
Report structure:
- Summary
- Potential issues
- Suggested tests
- Review limitations
AI providers:
- Support a local Ollama provider.
- Support configurable OpenAI-compatible cloud endpoints.
- Use a shared provider interface.
- Let users configure provider, model, base URL, timeout, and output language.
- Read API keys from environment variables.
- Never store API keys in project configuration.
- Do not silently fall back from a local model to a cloud service.
- Before sending code to a cloud provider, disclose the destination and require explicit consent.
- Support an explicit non-interactive opt-in flag for automated usage.
- No CommitSage account is required, but explain that a cloud provider may require its own credentials and payment.
Privacy and safety:
- Do not modify source files, stage changes, create commits, push, or execute reviewed code.
- Invoke Git with argument arrays, not shell-interpolated commands.
- Treat source code, comments, filenames, and diff content as untrusted input.
- Instruct the model to ignore instructions embedded in reviewed content.
- Skip binary files and common generated files.
- Honor a `.commitsageignore` file.
- Exclude common secret-bearing files by default.
- Attempt to redact obvious credentials before model requests.
- Clearly explain that automated secret detection is imperfect.
- Do not log source code, prompts, responses, or credentials by default.
- Avoid following symlinks outside the repository.
Large diffs:
- Apply explicit input-size limits.
- Split large reviews into bounded chunks when appropriate.
- Report skipped files, truncated context, and incomplete coverage.
- Never silently present a partial review as a complete one.
Error handling:
Handle these cases with clear, actionable messages:
- Git is not installed.
- The current directory is not a Git repository.
- No staged changes exist.
- A file is deleted or renamed.
- A diff contains only binary or ignored files.
- The provider is unavailable.
- The request times out.
- The model returns invalid JSON or an invalid schema.
- The selected model cannot accommodate the input.
Use bounded retries and validate AI output with Pydantic.
Keep diagnostic messages on stderr so JSON output remains parseable.
Suggested structure:
src/commitsage/
cli.py
config.py
git.py
models.py
review.py
privacy.py
providers/
base.py
ollama.py
openai_compatible.py
renderers/
terminal.py
markdown.py
json_output.py
tests/
Testing:
- Mock all model requests; tests must not require paid APIs or a running model.
- Use temporary Git repositories for integration tests.
- Cover staged versus unstaged changes, renamed and deleted files,
empty diffs, ignored files, secret redaction, invalid model output,
provider failures, cloud consent, and Persian output preservation.
Documentation:
Write a README with:
- Project overview and scope
- Installation and quick start
- Local model setup
- Cloud provider setup and explicit consent behavior
- English and Persian usage examples
- Configuration reference
- Privacy limitations
- Example review output labeled as illustrative
- Development and testing instructions
Implementation process:
1. Briefly describe the architecture and implementation plan.
2. Implement a complete vertical slice:
staged diff → provider → validated review → terminal output.
3. Add the remaining commands, renderers, safeguards, and tests.
4. Run the available tests and report actual results.
5. If execution is unavailable, explicitly state that tests were not run.
Deliver working code, not pseudocode or placeholder functions.
Keep the implementation small and maintainable.
Do not claim that AI review guarantees correctness or security.Checks a GitHub CODEOWNERS file against the real repository file list - works out who owns every file (last matching line wins), then reports invalid or unknown owners, unowned files and critical paths left to the catch-all rule, rules that match nothing or are fully overridden by later lines, unsupported ! and [ ] syntax, duplicates, empty teams and one-person bottlenecks. Includes an offline stdlib Python checker.
---
name: codeowners-coverage-and-ownership-checker
description: Checks a GitHub CODEOWNERS file against the real repository file list - works out who owns every file (last matching line wins), then reports invalid or unknown owners, unowned files and critical paths left to the catch-all rule, rules that match nothing or are fully overridden by later lines, unsupported ! and [ ] syntax, duplicates, empty teams and one-person bottlenecks. Includes an offline stdlib Python checker.
---
# CODEOWNERS Coverage and Ownership Checker
You help engineering teams trust their CODEOWNERS file. Required reviews and auto-assigned reviewers only work when every line is valid, every owner exists and has access, and the rules are in the right order. In practice files quietly lose their owner: a team gets renamed and its files silently get no reviewer, a specific rule sits above a general one and never applies, `docs/*` does not cover `docs/guide/`, a `!` negation copied from .gitignore does nothing, or the only owner of the billing code is one person on holiday. You compute the effective owner of every file and show exactly what is wrong and how to fix it.
You check the file against GitHub's documented CODEOWNERS behaviour and the owner list the user gives you. You cannot see repository permissions; say so and ask the user to confirm write access in the repository settings or with `gh api`.
## Files in this skill
- `scripts/codeowners_check.py` - parses CODEOWNERS (comments, inline comments, escaped spaces), matches every path from `git ls-files` with GitHub's gitignore-style rules (anchored and floating patterns, `*`, `**`, `?`, directory patterns, `dir/*` = direct children only, last matching line wins), skips lines with invalid syntax and drops unknown owners like GitHub does and reports findings CO01-CO11 with coverage per directory, a rule table, owner load and a `--who PATH` lookup (Python 3.8+ standard library only)
- `references/codeowners-syntax-and-matching.md` - pattern semantics with examples, ordering rules, owner formats, file location and GitHub limits
- `references/checks-and-codes.md` - every finding code, its severity and the usual fix
- `templates/ownership-review.md` - the pull request description / review note for a CODEOWNERS fix
- `examples/CODEOWNERS` - a realistic file for a web app monorepo with typical mistakes (renamed team, specific rule above a general one, `docs/*`, negation, character range, GitLab section, owner without @, removed directory, duplicate line, explicitly unowned generated code)
- `examples/files.txt` - the repository file list (`git ls-files` output, 43 files)
- `examples/owners.json` - org, users with access, teams with members, paths that must have a specific owner and the individual-share limit
- `examples/ownership-report.md` - the real checker output on the example
## Workflow
### 1. Collect the inputs
Ask for the CODEOWNERS file (from `.github/`, the repository root or `docs/`; GitHub uses the first one it finds in that order) and the file list from the default branch: `git ls-files > files.txt`. Then ask for the owner list: the org name, users with write access, teams with their members (`gh api orgs/<org>/teams`, `gh api orgs/<org>/teams/<team>/members`) and the paths that must have a specific owner (CI workflows, infrastructure, payments, migrations, CODEOWNERS itself). Write them into a JSON like `examples/owners.json`. Without an owner list the checker still checks syntax, order and coverage.
### 2. Run the checker
```
python3 scripts/codeowners_check.py examples/CODEOWNERS examples/files.txt --owners examples/owners.json
python3 scripts/codeowners_check.py .github/CODEOWNERS files.txt --owners owners.json --who services/api/billing/invoices.py
python3 scripts/codeowners_check.py .github/CODEOWNERS files.txt --json
python3 scripts/codeowners_check.py --self-test
```
Exit 0 = no high findings, 1 = high findings, 2 = bad input. Without a shell, walk the rules bottom-up for each important path with `references/codeowners-syntax-and-matching.md`: the first line from the bottom that matches is the owner.
### 3. Read the result
- High first: CO01 (invalid owner format such as a name without @): GitHub skips the whole line as invalid syntax, so those files fall back to an earlier rule. CO02 (unknown user or team, no access): that owner is not requested; if no valid owner is left on the line, the line still matches and its files get no code owner at all. CO03 high: files under a must-own path have no owner.
- Medium: CO05 (rule fully overridden - usually a specific path above a general one), CO04 (rule matches nothing - renamed or deleted path), CO06 (`!` or `[ ]` - ignored), CO11 (critical path only covered by `*`), CO09 (empty team), CO07 (one person owns too much), CO03 medium (files with no rule).
- Low/info: GitLab section headers, single-person ownership, duplicate patterns, explicitly unowned paths (fine if intended).
- Use `--who` on the paths people care about to confirm the fix before and after.
### 4. Propose the fix
Write the corrected CODEOWNERS: general rules first, specific ones after; replace `!` exclusions with a more specific later rule (an empty owner list makes a path unowned on purpose); use `/dir/` instead of `dir/*` when nested files should be covered; fix team slugs; add a second owner or a team for one-person paths; add a line for CODEOWNERS itself. Re-run until there are no high findings, then fill `templates/ownership-review.md`.
### 5. Deliver
Return the findings in plain words, the corrected file (or a diff), the before/after owner of the key paths, and the follow-ups that need an admin: grant team access, add members to empty teams, enable "Require review from Code Owners" in branch protection once the file is clean.
## Example result
On the example only 38 of 43 files have a code owner and there are 4 high findings: `/web/` names `@tidyq/frontend-team` (the team is `@tidyq/frontend`), so package.json, App.tsx, Home.tsx and Checkout.tsx get no code owner at all; `/docs/api/` uses `omar` without @ and is skipped; `/mobile/` names a removed team and matches no file. `/services/api/billing/` sits above `/services/api/` and never applies, so payments never review billing code; `docs/*` is overridden by `/docs/` and `@tidyq/docs` has no members; the `!` and `[a-z]` lines are ignored; Terraform modules and dependabot.yml only fall back to `*` because `/infra/terraform/*` covers direct children only.
## Rules
- Last matching line wins: always reason bottom-up, and say which line owns a path.
- A line with invalid syntax is skipped entirely; an unknown or inaccessible owner is simply not requested, and a line with only unknown owners still wins for its files, leaving them without a code owner. Never assume an earlier rule takes over in that case.
- Only call an owner unknown against the list the user provided; otherwise say "could not verify" and suggest the `gh api` calls.
- Prefer teams over individuals for anything critical; never remove a person from ownership without the team agreeing.
- Do not invent patterns for paths that are not in the file list; ask whether new directories are coming.
- Treat the repository file list and team membership as internal information.
FILE:references/codeowners-syntax-and-matching.md
# CODEOWNERS syntax and matching (GitHub)
## Where the file lives
GitHub looks for `CODEOWNERS` in `.github/`, then the repository root, then `docs/`, and uses the first one it finds on the branch the pull request targets (the base branch). Files over 3 MB are ignored. GitHub shows errors for invalid lines when you open the file in the web UI ("CODEOWNERS errors" banner) and via `gh api repos/<owner>/<repo>/codeowners/errors`.
## Line format
```
<pattern> <owner> [<owner> ...] # optional comment
```
- `#` at the start of a line (or after whitespace) starts a comment. Unlike .gitignore, escaping a pattern that starts with `#` as `\#` does not work in CODEOWNERS.
- Paths are case sensitive, even if your laptop's file system is not.
- All owners for a pattern must be on the same line; two lines with the same pattern means only the later one counts.
- Owners: `@username`, `@org/team-slug` (team in the same org, with write access) or an email address linked to a GitHub account. A bare name such as `omar` is invalid.
- A pattern with no owners makes matching files unowned on purpose (useful to carve out generated code from a default owner).
- A line with invalid syntax (for example an owner without @) is skipped, so its files fall back to the previous matching line.
- An owner that does not exist or has no write access is simply not assigned. The line still matches, so if none of its owners is valid, its files end up with no code owner (they do NOT fall back to an earlier line).
## Order: the last matching line wins
GitHub reads the file top to bottom and the last line that matches a path decides its owners. Put the catch-all `*` first, broad directories next and the most specific paths last.
```
* @tidyq/platform # 1: default
/services/api/ @tidyq/backend # 2: whole API
/services/api/billing/ @tidyq/payments # 3: more specific, must come AFTER 2
```
With lines 2 and 3 swapped, billing files are owned by `@tidyq/backend` only (CO05).
## Pattern semantics (gitignore-style, with exceptions)
| Pattern | Matches | Does not match |
|---|---|---|
| `*` | every file | - |
| `*.js` | `app.js`, `web/lib/util.js` (any depth) | `app.jsx` |
| `/build/logs/` | everything under `build/logs/` at the root, at any depth | `src/build/logs/x` |
| `docs/` or `apps/` (no leading slash) | a `docs`/`apps` directory anywhere and everything under it | - |
| `docs/*` | files directly in `docs/` | `docs/guide/setup.md` (nested) |
| `/docs/` or `/docs/**` | everything under the root `docs/` | - |
| `**/logs` | `logs` directory or file at any depth | - |
| `/src/**/users.py` | `src/users.py`, `src/api/v2/users.py` | - |
| `README.md` | `README.md` at any depth | - |
| `/README.md` | only the root `README.md` | `sub/README.md` |
| `src/ap?.py` | `src/app.py` | `src/apps.py` |
Rules of thumb:
- A pattern with a slash at the start or in the middle is anchored to the repository root; one without (apart from a trailing slash) floats and matches at any depth.
- A trailing slash means "this directory and everything in it".
- A matching directory owns all files under it, except for `dir/*`, which covers direct children only.
## Not supported (the line is ignored or flagged)
- `!pattern` negation - use a later, more specific rule instead (with no owners to make it unowned).
- `[a-z]` character ranges - list the paths or use `*`.
- GitLab sections (`[Docs]`, `^[Optional]`, `[Docs][2]`) and default owners on section headers - GitLab only.
## Teams and access
- The team must be visible and have write access to the repository; the user must have write access.
- An empty team gets the review request but nobody is notified.
- Required code owner review (branch protection or rulesets) blocks merges until one of the owners approves (any one owner is enough). If a file ends up with no valid owner, no code owner approval is requested for it, so the protection silently does nothing for that file.
## Getting the inputs
```
git ls-files > files.txt
gh api orgs/<org>/teams --paginate -q '.[].slug'
gh api orgs/<org>/teams/<slug>/members --paginate -q '.[].login'
gh api repos/<owner>/<repo>/collaborators --paginate -q '.[] | select(.permissions.push) | .login'
gh api repos/<owner>/<repo>/codeowners/errors
```
FILE:references/checks-and-codes.md
# Checks and finding codes
| Code | Severity | Check | Typical fix |
|---|---|---|---|
| CO01 | high | owner is not `@user`, `@org/team` or an email (e.g. `omar`); pattern cannot be parsed | add the @ / fix the slug; the whole line is skipped until then |
| CO02 | high | user not in your users list, team not in your teams list, or team from another org (only with `--owners`); a second CO02 line says when no valid owner is left on a line, so its files get no code owner | fix the slug (the checker suggests a close team), give the team write access, or remove the owner |
| CO03 | high: unowned file under a `require_owner` path; medium: other files with no rule or only unknown owners (explicitly unowned files are CO10) | coverage | add a rule, or a catch-all `*` default |
| CO04 | medium | the pattern matches no file in the list | path renamed or deleted: update or remove the line |
| CO05 | medium | every file the rule matches is owned by later lines (last match wins) | move the specific rule below the general one |
| CO06 | medium: `!` negation, `[ ]` ranges (ignored by GitHub); low: GitLab section header | unsupported syntax | use a later more specific rule; empty owner list = unowned |
| CO07 | medium: one individual (not a team) is the effective owner of more than `max_individual_share` of files; low: files owned by a single individual and no team | bus factor | add a team or a second owner |
| CO08 | low | the same pattern appears twice; only the later line counts | merge the owners into one line |
| CO09 | medium | team has no members in your teams list | add members or use another team |
| CO10 | info | pattern with no owners: files intentionally unowned | fine if intended (generated code, vendored files) |
| CO11 | medium | files under a `require_owner` path are only owned by the catch-all `*` rule | add a specific rule for that path |
## Verdict
- **High findings**: fix before relying on "Require review from Code Owners".
- **Medium only**: the file works but some files go to the wrong people.
- **Healthy**: only low/info.
## Owners file (`--owners`, JSON)
| Key | Meaning |
|---|---|
| `org` | org name; teams from another org are flagged |
| `users` | logins with write access (without @) |
| `teams` | `{"org/slug": [members]}` |
| `require_owner` | patterns (same syntax) for paths that must have a specific owner |
| `max_individual_share` | share of files one person may own alone (default 0.4) |
| `ignore` | patterns for files to leave out (vendored code, lock files) |
## Limits of the check
- Repository permissions and team visibility are not checked - confirm with the `gh api` calls in the syntax reference or the "CODEOWNERS errors" banner.
- The file list is a snapshot of one branch; run it against the base branch of your pull requests.
FILE:templates/ownership-review.md
# CODEOWNERS fix: <repository>
**Branch:** <base branch> **Checked:** <YYYY-MM-DD> **Files:** <n> **Owned before / after:** <x% / y%>
## What was wrong
| Line | Rule | Problem | Effect |
|---|---|---|---|
| <11> | `<pattern> <owners>` | <unknown team @org/frontend-team> | <web files fall back to @org/platform> |
| <6> | `<pattern>` | <overridden by line 7> | <payments never review billing> |
## Changes
```diff
<- /services/api/billing/ @org/payments
< /services/api/ @org/backend
<+ /services/api/billing/ @org/payments>
```
## Who owns the key paths now
| Path | Before | After |
|---|---|---|
| <services/api/billing/invoices.py> | <@org/backend (line 7)> | <@org/payments (line 8)> |
| <infra/terraform/modules/vpc/main.tf> | <@org/platform (line 3, catch-all)> | <@org/sre> |
## Needs an admin
- [ ] <give @org/frontend write access / add members to @org/docs>
- [ ] <enable "Require review from Code Owners" on <branch> once this is merged>
## Check
`python3 scripts/codeowners_check.py .github/CODEOWNERS files.txt --owners owners.json` -> <0 high, n medium (explain the rest)>
*Matching follows GitHub's CODEOWNERS rules; repository permissions were checked with <gh api / settings page | not checked>.*
FILE:examples/CODEOWNERS
# CODEOWNERS for tidyq/tidyq-app (copied into .github/CODEOWNERS)
# Default owners for everything not matched below
* @tidyq/platform
# Backend
/services/api/billing/ @tidyq/payments
/services/api/ @tidyq/backend
/services/worker/ @tidyq/backend @marta-k
# Frontend
/web/ @tidyq/frontend-team
/web/src/design-system/ @lena-s
*.css @tidyq/frontend
# Infrastructure
/infra/terraform/* @tidyq/sre
/infra/k8s/ @tidyq/sre
!/infra/k8s/sandbox/
# CI and repository settings
/.github/workflows/ @tidyq/sre
/.github/CODEOWNERS @tidyq/platform-leads
# Docs
[Documentation]
docs/* @tidyq/docs
/docs/ @tidyq/docs
/docs/api/ omar
# Old mobile app (moved to tidyq/tidyq-mobile in 2026)
/mobile/ @tidyq/mobile
# Data
/data/migrations/ @jonas-b
/data/migrations/ @jonas-b @tidyq/backend
/data/fixtures/[a-z]* @tidyq/qa
# Generated client: owned by nobody on purpose
/web/src/generated/
FILE:examples/files.txt
.github/CODEOWNERS
.github/dependabot.yml
.github/workflows/ci.yml
.github/workflows/deploy.yml
.github/workflows/release.yml
README.md
package.json
docs/index.md
docs/getting-started.md
docs/api/endpoints.md
docs/api/auth.md
docs/runbooks/oncall.md
infra/terraform/main.tf
infra/terraform/variables.tf
infra/terraform/modules/vpc/main.tf
infra/terraform/modules/rds/main.tf
infra/k8s/api-deployment.yaml
infra/k8s/worker-deployment.yaml
infra/k8s/sandbox/debug-pod.yaml
services/api/app.py
services/api/routes/users.py
services/api/routes/orders.py
services/api/billing/invoices.py
services/api/billing/stripe_webhook.py
services/api/tests/test_routes.py
services/worker/main.py
services/worker/jobs/email.py
services/worker/jobs/reports.py
web/package.json
web/src/App.tsx
web/src/pages/Home.tsx
web/src/pages/Checkout.tsx
web/src/styles/main.css
web/src/design-system/Button.tsx
web/src/design-system/Modal.tsx
web/src/design-system/tokens.css
web/src/generated/api-client.ts
data/migrations/0041_add_orders.sql
data/migrations/0042_add_invoices.sql
data/fixtures/users.json
data/fixtures/orders.json
scripts/seed_db.py
scripts/rotate_keys.sh
FILE:examples/owners.json
{
"org": "tidyq",
"users": ["marta-k", "lena-s", "jonas-b", "omar-h", "priya-n", "sam-t"],
"teams": {
"tidyq/platform": ["priya-n", "sam-t"],
"tidyq/platform-leads": ["priya-n"],
"tidyq/backend": ["marta-k", "jonas-b", "omar-h"],
"tidyq/payments": ["marta-k"],
"tidyq/frontend": ["lena-s", "sam-t"],
"tidyq/sre": ["priya-n", "sam-t"],
"tidyq/docs": [],
"tidyq/qa": ["omar-h"]
},
"require_owner": [".github/", "infra/", "services/api/billing/", "data/migrations/"],
"max_individual_share": 0.25,
"ignore": []
}
FILE:examples/ownership-report.md
# CODEOWNERS check: examples/CODEOWNERS
20 rule line(s), 43 file(s), 38 owned (88.4%), 5 unowned.
**Verdict: 4 high finding(s) - fix CODEOWNERS before relying on required reviews**
Findings: 4 high, 9 medium, 3 low, 1 info.
Lines whose owners are all unknown (they still match, so their files get no code owner): 11, 31. Unknown owners are left out of the owner columns below.
## Findings
- **HIGH CO01** line 28: invalid owner 'omar' (use @user, @org/team or an email) - GitHub flags the whole line as an error and skips it
- **HIGH CO02** line 11: unknown team @tidyq/frontend-team (did you mean @tidyq/frontend?) - GitHub will not request reviews from it
- **HIGH CO02** line 11: no valid owner left - its 4 file(s) get no code owner (they do not fall back to earlier lines)
- **HIGH CO02** line 31: unknown team @tidyq/mobile - GitHub will not request reviews from it
- **MEDIUM CO03** 4 file(s) have no code owner (no matching rule, or only unknown owners): web/package.json, web/src/App.tsx, web/src/pages/Home.tsx, web/src/pages/Checkout.tsx
- **MEDIUM CO04** line 31: '/mobile/' matches no file - path renamed or removed?
- **MEDIUM CO05** line 6: '/services/api/billing/' (2 file(s)) is fully overridden by later line(s) 7 - last match wins, put specific rules after general ones
- **MEDIUM CO05** line 26: 'docs/*' (2 file(s)) is fully overridden by later line(s) 27 - last match wins, put specific rules after general ones
- **MEDIUM CO05** line 34: '/data/migrations/' (2 file(s)) is fully overridden by later line(s) 35 - last match wins, put specific rules after general ones
- **MEDIUM CO06** line 18: '!/infra/k8s/sandbox/' uses ! negation, which CODEOWNERS does not support - GitHub ignores the line
- **MEDIUM CO06** line 36: '/data/fixtures/[a-z]*' uses [ ] character ranges, which CODEOWNERS does not support - GitHub ignores the line
- **MEDIUM CO09** line 26: team @tidyq/docs has no members - review requests go nowhere
- **MEDIUM CO11** 3 file(s) under paths that must have an owner only fall back to the catch-all '*' rule (no specific owner): .github/dependabot.yml, infra/terraform/modules/vpc/main.tf, infra/terraform/modules/rds/main.tf
- **LOW CO06** line 25: '[Documentation]' is a GitLab section header; GitHub treats it as an invalid line
- **LOW CO07** 2 file(s) have a single individual owner and no team (e.g. web/src/design-system/Button.tsx, web/src/design-system/Modal.tsx)
- **LOW CO08** line 35 repeats the pattern '/data/migrations/' of line 34 - only the later line counts
- **INFO CO10** line 39: '/web/src/generated/' has no owners - its 1 file(s) are intentionally unowned
## Coverage by top-level directory
| Directory | Files | Owned | Unowned | Effective owners |
|---|---|---|---|---|
| (root) | 2 | 2 | 0 | @tidyq/platform (2) |
| .github/ | 5 | 5 | 0 | @tidyq/sre (3), @tidyq/platform-leads (1), @tidyq/platform (1) |
| data/ | 4 | 4 | 0 | @jonas-b (2), @tidyq/backend (2), @tidyq/platform (2) |
| docs/ | 5 | 5 | 0 | @tidyq/docs (5) |
| infra/ | 7 | 7 | 0 | @tidyq/sre (5), @tidyq/platform (2) |
| scripts/ | 2 | 2 | 0 | @tidyq/platform (2) |
| services/ | 9 | 9 | 0 | @tidyq/backend (9), @marta-k (3) |
| web/ | 9 | 4 | 5 | @tidyq/frontend (2), @lena-s (2) |
## Rules
| Line | Pattern | Owners | Files matched | Effective for | Note |
|---|---|---|---|---|---|
| 3 | `*` | @tidyq/platform | 43 | 9 | |
| 6 | `/services/api/billing/` | @tidyq/payments | 2 | 0 | CO05 |
| 7 | `/services/api/` | @tidyq/backend | 6 | 6 | |
| 8 | `/services/worker/` | @tidyq/backend @marta-k | 3 | 3 | |
| 11 | `/web/` | @tidyq/frontend-team | 9 | 4 | CO02 |
| 12 | `/web/src/design-system/` | @lena-s | 3 | 2 | |
| 13 | `*.css` | @tidyq/frontend | 2 | 2 | |
| 16 | `/infra/terraform/*` | @tidyq/sre | 2 | 2 | |
| 17 | `/infra/k8s/` | @tidyq/sre | 3 | 3 | |
| 18 | `!/infra/k8s/sandbox/` | (none) | - | - | CO06 |
| 21 | `/.github/workflows/` | @tidyq/sre | 3 | 3 | |
| 22 | `/.github/CODEOWNERS` | @tidyq/platform-leads | 1 | 1 | |
| 26 | `docs/*` | @tidyq/docs | 2 | 0 | CO05, CO09 |
| 27 | `/docs/` | @tidyq/docs | 5 | 5 | |
| 28 | `/docs/api/` | omar | - | - | CO01 |
| 31 | `/mobile/` | @tidyq/mobile | 0 | 0 | CO02, CO04 |
| 34 | `/data/migrations/` | @jonas-b | 2 | 0 | CO05 |
| 35 | `/data/migrations/` | @jonas-b @tidyq/backend | 2 | 2 | CO08 |
| 36 | `/data/fixtures/[a-z]*` | @tidyq/qa | - | - | CO06 |
| 39 | `/web/src/generated/` | (none) | 1 | 1 | CO10 |
## Owner load (effective)
| Owner | Files | Share |
|---|---|---|
| @tidyq/backend | 11 | 26% |
| @tidyq/platform | 9 | 21% |
| @tidyq/sre | 8 | 19% |
| @tidyq/docs | 5 | 12% |
| @marta-k | 3 | 7% |
| @tidyq/frontend | 2 | 5% |
| @lena-s | 2 | 5% |
| @jonas-b | 2 | 5% |
| @tidyq/platform-leads | 1 | 2% |
## Unowned files
- `web/package.json` (line 11: only unknown owners)
- `web/src/App.tsx` (line 11: only unknown owners)
- `web/src/pages/Home.tsx` (line 11: only unknown owners)
- `web/src/pages/Checkout.tsx` (line 11: only unknown owners)
- `web/src/generated/api-client.ts` (explicitly unowned, line 39)
## Who owns
- services/api/billing/invoices.py: @tidyq/backend (line 7: /services/api/)
- infra/terraform/modules/vpc/main.tf: @tidyq/platform (line 3: *)
- web/src/pages/Checkout.tsx: no valid owner (line 11: /web/ @tidyq/frontend-team - unknown)
Matching follows GitHub CODEOWNERS rules (gitignore-style patterns, last matching line wins, `!` and `[ ]` unsupported). Owners are checked against your owners file only; confirm write access in the repository settings.
FILE:scripts/codeowners_check.py
#!/usr/bin/env python3
"""CODEOWNERS coverage and ownership checker (stdlib only, Python 3.8+).
Reads a GitHub CODEOWNERS file and the repository file list (`git ls-files` output), works out
the effective owner of every file with GitHub's rules (gitignore-style patterns, the LAST
matching line wins) and reports syntax errors, unknown owners, unowned files (also under paths
that must have an owner), rules that match nothing, rules that are fully overridden by later
lines, unsupported syntax, duplicates, empty teams and owner concentration.
Usage:
codeowners_check.py CODEOWNERS FILES.txt [--owners OWNERS.json] [--who PATH]... [--json]
codeowners_check.py --self-test
Exit: 0 = no high findings, 1 = high findings, 2 = bad input.
"""
import argparse, json, re, sys
from collections import Counter, OrderedDict
SEV = {"high": 0, "medium": 1, "low": 2, "info": 3}
USER_RE = re.compile(r"^@[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})$")
TEAM_RE = re.compile(r"^@([A-Za-z0-9][A-Za-z0-9-]*)/([A-Za-z0-9][A-Za-z0-9._-]*)$")
EMAIL_RE = re.compile(r"^[^@\s]+@[^@\s]+\.[^@\s]+$")
class InputError(Exception):
pass
# ---------------------------------------------------------------- patterns
def pattern_regex(pat):
"""Return (compiled regex, dir_only, direct_children_only) for a CODEOWNERS pattern."""
dir_only = pat.endswith("/")
p = pat.rstrip("/")
anchored = p.startswith("/") or "/" in p
p = p.lstrip("/")
direct_only = p.endswith("/*")
out, i = "", 0
while i < len(p):
if p.startswith("**/", i):
out += "(?:.*/)?"; i += 3
elif p.startswith("/**", i) and i + 3 == len(p):
out += "/.*"; i += 3
elif p.startswith("**", i):
out += ".*"; i += 2
elif p[i] == "*":
out += "[^/]*"; i += 1
elif p[i] == "?":
out += "[^/]"; i += 1
elif p[i] == "\\" and i + 1 < len(p):
out += re.escape(p[i + 1]); i += 2
else:
out += re.escape(p[i]); i += 1
if not anchored:
out = "(?:.*/)?" + out
return re.compile("^" + out + "$"), dir_only, direct_only
def matches(compiled, path):
rx, dir_only, direct_only = compiled
parts = path.split("/")
if not dir_only and rx.match(path):
return True
if direct_only:
return False
for k in range(1, len(parts)): # a matching directory owns everything under it
if rx.match("/".join(parts[:k])):
return True
return False
# ---------------------------------------------------------------- parsing
def parse_codeowners(text):
rules, findings = [], []
for n, raw in enumerate(text.splitlines(), 1):
line = raw.strip()
if not line or line.startswith("#"):
continue
if re.match(r"^\^?\[[^\]]+\](\[\d+\])?(\s+@.*)?$", line):
findings.append(("low", "CO06", "line %d: '%s' is a GitLab section header; GitHub treats it as an invalid line" % (n, line), n))
continue
tokens = re.split(r"(?<!\\)\s+", line)
pat, owners = tokens[0], []
for t in tokens[1:]:
if t.startswith("#"):
break
owners.append(t)
rule = {"line": n, "pattern": pat, "owners": owners, "valid": True}
if pat.startswith("!"):
findings.append(("medium", "CO06", "line %d: '%s' uses ! negation, which CODEOWNERS does not support - GitHub ignores the line" % (n, pat), n))
rule["valid"] = False
elif "[" in pat or "]" in pat:
findings.append(("medium", "CO06", "line %d: '%s' uses [ ] character ranges, which CODEOWNERS does not support - GitHub ignores the line" % (n, pat), n))
rule["valid"] = False
bad = [o for o in owners if not (USER_RE.match(o) or TEAM_RE.match(o) or EMAIL_RE.match(o))]
if bad:
findings.append(("high", "CO01", "line %d: invalid owner %s (use @user, @org/team or an email) - GitHub flags the whole line as an error and skips it" % (n, ", ".join("'%s'" % b for b in bad)), n))
rule["valid"] = False
if rule["valid"]:
try:
rule["rx"] = pattern_regex(pat)
except re.error as e:
findings.append(("high", "CO01", "line %d: pattern '%s' cannot be parsed (%s)" % (n, pat, e), n))
rule["valid"] = False
rules.append(rule)
return rules, findings
def load_files(text):
files = []
for l in text.splitlines():
l = l.strip()
if l and not l.startswith("#"):
files.append(l[2:] if l.startswith("./") else l.lstrip("/"))
if not files:
raise InputError("file list is empty (use: git ls-files > files.txt)")
return files
# ---------------------------------------------------------------- analysis
def analyse(co_text, files_text, owners_cfg=None):
owners_cfg = owners_cfg or {}
allowed_keys = {"org", "users", "teams", "require_owner", "max_individual_share", "ignore"}
unknown = set(owners_cfg) - allowed_keys
if unknown:
raise InputError("unknown key(s) in owners file: %s" % ", ".join(sorted(unknown)))
rules, findings = parse_codeowners(co_text)
if not rules:
raise InputError("CODEOWNERS has no rules")
files = load_files(files_text)
ignore = [pattern_regex(p) for p in owners_cfg.get("ignore", [])]
files = [f for f in files if not any(matches(c, f) for c in ignore)]
valid = [r for r in rules if r["valid"]]
eff, matched_by = {}, {r["line"]: [] for r in valid}
for f in files:
last = None
for r in valid:
if matches(r["rx"], f):
matched_by[r["line"]].append(f)
last = r
eff[f] = last
effective = Counter(r["line"] for r in eff.values() if r)
# known owners
org = owners_cfg.get("org")
users = {u.lower().lstrip("@") for u in owners_cfg.get("users", [])}
teams = {k.lower().lstrip("@"): v for k, v in owners_cfg.get("teams", {}).items()}
have_list = bool(users or teams)
reported, unknown_owners = set(), set()
for r in valid:
for o in r["owners"]:
key = o.lower()
m = TEAM_RE.match(o)
problem = None
if m and have_list:
name = (m.group(1) + "/" + m.group(2)).lower()
if org and m.group(1).lower() != org.lower():
problem = "team %s is not in org @%s" % (o, org)
elif name not in teams:
close = [t for t in teams if t.split("/")[-1].startswith(m.group(2).lower()[:4])]
problem = "unknown team %s%s" % (o, (" (did you mean @%s?)" % close[0]) if close else "")
elif not teams[name] and key not in reported:
findings.append(("medium", "CO09", "line %d: team %s has no members - review requests go nowhere" % (r["line"], o), r["line"])); reported.add(key)
elif USER_RE.match(o) and have_list and key.lstrip("@") not in users:
problem = "unknown user %s (not in the owners list / no write access)" % o
if problem:
unknown_owners.add(key)
if key not in reported:
findings.append(("high", "CO02", "line %d: %s - GitHub will not request reviews from it" % (r["line"], problem), r["line"])); reported.add(key)
for r in rules:
r["ok"] = [o for o in r["owners"] if o.lower() not in unknown_owners]
bad_lines = sorted(r["line"] for r in valid if r["owners"] and not r["ok"])
for ln in [x for x in bad_lines if effective[x]]:
findings.append(("high", "CO02", "line %d: no valid owner left - its %d file(s) get no code owner (they do not fall back to earlier lines)" % (ln, effective[ln]), ln))
# dead, shadowed, duplicate rules
seen = {}
for r in valid:
if r["pattern"] in seen:
findings.append(("low", "CO08", "line %d repeats the pattern '%s' of line %d - only the later line counts" % (r["line"], r["pattern"], seen[r["pattern"]]), r["line"]))
seen[r["pattern"]] = r["line"]
if not matched_by[r["line"]]:
findings.append(("medium", "CO04", "line %d: '%s' matches no file - path renamed or removed?" % (r["line"], r["pattern"]), r["line"]))
elif effective[r["line"]] == 0:
later = sorted({eff[f]["line"] for f in matched_by[r["line"]] if eff[f]})
findings.append(("medium", "CO05", "line %d: '%s' (%d file(s)) is fully overridden by later line(s) %s - last match wins, put specific rules after general ones" % (r["line"], r["pattern"], len(matched_by[r["line"]]), ", ".join(map(str, later))), r["line"]))
if not r["owners"]:
findings.append(("info", "CO10", "line %d: '%s' has no owners - its %d file(s) are intentionally unowned" % (r["line"], r["pattern"], effective[r["line"]]), r["line"]))
# coverage
unowned = [f for f in files if not eff[f] or not eff[f]["ok"]]
no_rule = [f for f in unowned if not eff[f]]
req = [(p, pattern_regex(p)) for p in owners_cfg.get("require_owner", [])]
crit = [f for f in unowned if any(matches(c, f) for _, c in req)]
if crit:
findings.append(("high", "CO03", "%d file(s) under paths that must have an owner are unowned: %s" % (len(crit), ", ".join(crit[:6]) + (" ..." if len(crit) > 6 else "")), 0))
catch_all = [f for f in files if eff[f] and eff[f]["ok"] and eff[f]["pattern"] in ("*", "/*", "**", "/**")
and any(matches(c, f) for _, c in req)]
if catch_all:
findings.append(("medium", "CO11", "%d file(s) under paths that must have an owner only fall back to the catch-all '%s' rule (no specific owner): %s" % (len(catch_all), eff[catch_all[0]]["pattern"], ", ".join(catch_all[:6]) + (" ..." if len(catch_all) > 6 else "")), 0))
rest = [f for f in unowned if f not in crit and (not eff[f] or eff[f]["owners"])]
if rest:
findings.append(("medium", "CO03", "%d file(s) have no code owner (no matching rule, or only unknown owners): %s" % (len(rest), ", ".join(rest[:6]) + (" ..." if len(rest) > 6 else "")), 0))
# owner load
load = Counter()
for f in files:
if eff[f]:
for o in eff[f]["ok"]:
load[o] += 1
share = float(owners_cfg.get("max_individual_share", 0.4))
for o, n in load.most_common():
if USER_RE.match(o) and n / len(files) > share:
findings.append(("medium", "CO07", "%s is the owner of %d of %d files (%.0f%%) as an individual - bus factor; add a team or a second owner" % (o, n, len(files), 100.0 * n / len(files)), 0))
solo = [f for f in files if eff[f] and len(eff[f]["ok"]) == 1 and USER_RE.match(eff[f]["ok"][0])]
if solo:
findings.append(("low", "CO07", "%d file(s) have a single individual owner and no team (e.g. %s)" % (len(solo), ", ".join(solo[:3])), 0))
findings.sort(key=lambda f: (SEV[f[0]], f[1], f[3]))
return {"rules": rules, "files": files, "eff": eff, "matched_by": matched_by, "effective": effective,
"unowned": unowned, "load": load, "findings": findings, "no_valid_owner_lines": bad_lines}
def who(res, path):
r = res["eff"].get(path)
if path not in res["eff"]:
rx_hits = [x for x in res["rules"] if x["valid"] and matches(x["rx"], path)]
r = rx_hits[-1] if rx_hits else None
if not r:
return "%s: no owner (no matching rule)" % path
if r["owners"] and not r["ok"]:
return "%s: no valid owner (line %d: %s %s - unknown)" % (path, r["line"], r["pattern"], " ".join(r["owners"]))
return "%s: %s (line %d: %s)" % (path, " ".join(r["ok"]) or "explicitly unowned", r["line"], r["pattern"])
# ---------------------------------------------------------------- report
def report(res, title, whos=()):
f, files = res["findings"], res["files"]
cnt = Counter(x[0] for x in f)
owned = len(files) - len(res["unowned"])
L = ["# CODEOWNERS check: %s" % title, ""]
L.append("%d rule line(s), %d file(s), %d owned (%.1f%%), %d unowned." % (len(res["rules"]), len(files), owned, 100.0 * owned / len(files), len(res["unowned"])))
L.append("")
L.append("**Verdict: %s**" % ("%d high finding(s) - fix CODEOWNERS before relying on required reviews" % cnt["high"] if cnt["high"] else ("review the medium findings" if cnt["medium"] else "CODEOWNERS looks healthy")))
L.append("")
L.append("Findings: %d high, %d medium, %d low, %d info." % (cnt["high"], cnt["medium"], cnt["low"], cnt["info"]))
L.append("")
if res["no_valid_owner_lines"]:
L.append("Lines whose owners are all unknown (they still match, so their files get no code owner): %s. Unknown owners are left out of the owner columns below." % ", ".join(map(str, res["no_valid_owner_lines"])))
L.append("")
L += ["## Findings", ""]
for s, c, msg, _ in f:
L.append("- **%s %s** %s" % (s.upper(), c, msg))
L += ["", "## Coverage by top-level directory", "", "| Directory | Files | Owned | Unowned | Effective owners |", "|---|---|---|---|---|"]
dirs = OrderedDict()
for p in files:
d = p.split("/")[0] + "/" if "/" in p else "(root)"
dirs.setdefault(d, []).append(p)
for d, ps in sorted(dirs.items()):
un = [p for p in ps if p in res["unowned"]]
own = Counter(o for p in ps if res["eff"][p] for o in res["eff"][p]["ok"])
L.append("| %s | %d | %d | %d | %s |" % (d, len(ps), len(ps) - len(un), len(un), ", ".join("%s (%d)" % kv for kv in own.most_common()) or "-"))
L += ["", "## Rules", "", "| Line | Pattern | Owners | Files matched | Effective for | Note |", "|---|---|---|---|---|---|"]
notes = {}
for s, c, msg, ln in f:
if ln:
notes.setdefault(ln, []).append(c)
for r in res["rules"]:
m = len(res["matched_by"].get(r["line"], [])) if r["valid"] else "-"
e = res["effective"].get(r["line"], 0) if r["valid"] else "-"
L.append("| %d | `%s` | %s | %s | %s | %s |" % (r["line"], r["pattern"], " ".join(r["owners"]) or "(none)", m, e, ", ".join(sorted(set(notes.get(r["line"], [])))) or ""))
L += ["", "## Owner load (effective)", "", "| Owner | Files | Share |", "|---|---|---|"]
for o, n in res["load"].most_common():
L.append("| %s | %d | %.0f%% |" % (o, n, 100.0 * n / len(files)))
if res["unowned"]:
L += ["", "## Unowned files", ""]
for p in res["unowned"]:
e = res["eff"][p]
L.append("- `%s`%s" % (p, "" if not e else (" (explicitly unowned, line %d)" % e["line"] if not e["owners"] else " (line %d: only unknown owners)" % e["line"])))
if whos:
L += ["", "## Who owns", ""]
for p in whos:
L.append("- " + who(res, p))
L += ["", "Matching follows GitHub CODEOWNERS rules (gitignore-style patterns, last matching line wins, `!` and `[ ]` unsupported). Owners are checked against your owners file only; confirm write access in the repository settings."]
return "\n".join(L) + "\n"
def to_json(res):
return {"files": len(res["files"]), "unowned": res["unowned"], "no_valid_owner_lines": res["no_valid_owner_lines"],
"owners": {p: (res["eff"][p]["ok"] if res["eff"][p] else []) for p in res["files"]},
"rules": [{"line": r["line"], "pattern": r["pattern"], "owners": r["owners"], "valid": r["valid"],
"matched": len(res["matched_by"].get(r["line"], [])), "effective": res["effective"].get(r["line"], 0)} for r in res["rules"]],
"load": dict(res["load"]),
"findings": [{"severity": s, "code": c, "message": m, "line": ln} for s, c, m, ln in res["findings"]]}
# ---------------------------------------------------------------- self-test
def self_test():
tests = []
def t(name, cond):
tests.append((name, bool(cond)))
def owner(co, f, path, cfg=None):
r = analyse(co, f, cfg)
e = r["eff"][path]
return e["ok"] if e else None
def codes(co, f, cfg=None):
return [(x[0], x[1]) for x in analyse(co, f, cfg)["findings"]]
F = "README.md\nsrc/app.py\nsrc/api/routes.py\nsrc/api/v2/users.py\ndocs/index.md\ndocs/guide/setup.md\nweb/app.js\nweb/lib/util.js\n.github/workflows/ci.yml\n"
t("* matches everything", owner("* @a", F, "src/api/v2/users.py") == ["@a"])
t("last matching line wins", owner("* @a\n/src/ @b", F, "src/app.py") == ["@b"] and owner("* @a\n/src/ @b", F, "README.md") == ["@a"])
t("*.js matches at any depth", owner("*.js @js", F, "web/lib/util.js") == ["@js"])
t("/docs/ owns nested files", owner("/docs/ @d", F, "docs/guide/setup.md") == ["@d"])
t("docs/* does not own nested files", owner("docs/* @d", F, "docs/guide/setup.md") is None and owner("docs/* @d", F, "docs/index.md") == ["@d"])
t("unanchored dir name 'api/' matches anywhere", owner("api/ @x", F, "src/api/v2/users.py") == ["@x"])
t("** in the middle", owner("/src/**/users.py @u", F, "src/api/v2/users.py") == ["@u"])
t("anchored /README.md only at root", owner("/README.md @r", "README.md\nsub/README.md\n", "sub/README.md") is None)
t("? matches one character", owner("src/ap?.py @q", F, "src/app.py") == ["@q"])
t("no owners = explicitly unowned", owner("* @a\n/web/", F, "web/app.js") == [] and ("info", "CO10") in codes("* @a\n/web/", F))
t("invalid owner -> CO01 high, line skipped", ("high", "CO01") in codes("* @a\n/src/ alice", F) and owner("* @a\n/src/ alice", F, "src/app.py") == ["@a"])
t("negation -> CO06 medium", ("medium", "CO06") in codes("* @a\n!/src/", F))
t("[ ] range -> CO06 medium", ("medium", "CO06") in codes("* @a\n/src/[ab]* @b", F))
t("GitLab section -> CO06 low", ("low", "CO06") in codes("[Docs]\n* @a", F))
cfg = {"org": "acme", "users": ["a", "b"], "teams": {"acme/web": ["a"], "acme/empty": []}}
t("unknown team -> CO02 high, files get no owner (no fallback)", ("high", "CO02") in codes("* @a\n/web/ @acme/webb", F, cfg) and owner("* @a\n/web/ @acme/webb", F, "web/app.js", cfg) == [] and ("medium", "CO03") in codes("* @a\n/web/ @acme/webb", F, cfg))
t("unknown owner dropped, valid co-owner kept", owner("* @a\n/web/ @acme/webb @b", F, "web/app.js", cfg) == ["@b"])
t("team of other org -> CO02", ("high", "CO02") in codes("* @other/web", F, cfg))
t("unknown user -> CO02", ("high", "CO02") in codes("* @zed", F, cfg))
t("empty team -> CO09", ("medium", "CO09") in codes("* @a\n/web/ @acme/empty", F, cfg))
t("email owner accepted", ("high", "CO01") not in codes("* dev@acme.io", F))
t("dead rule -> CO04", ("medium", "CO04") in codes("* @a\n/legacy/ @b", F))
t("shadowed rule -> CO05", ("medium", "CO05") in codes("/src/api/ @b\n/src/ @a", F))
t("partially overridden is not CO05", ("medium", "CO05") not in codes("/src/ @a\n/src/api/ @b", F))
t("duplicate pattern -> CO08", ("low", "CO08") in codes("* @a\n/src/ @b\n/src/ @c", F))
t("unowned file -> CO03 medium", ("medium", "CO03") in codes("/src/ @a", F))
t("require_owner path unowned -> CO03 high", ("high", "CO03") in codes("/src/ @acme/web", F, dict(cfg, require_owner=[".github/"])))
t("required path only owned by '*' -> CO11", ("medium", "CO11") in codes("* @a\n/src/ @b", F, {"require_owner": [".github/"]}))
t("dead rule with unknown owner still -> CO04", ("medium", "CO04") in codes("* @a\n/legacy/ @acme/zz", F, cfg))
t("individual owner concentration -> CO07", ("medium", "CO07") in codes("* @a", F, {"max_individual_share": 0.5}))
t("ignore list removes files", len(analyse("* @a", F, {"ignore": ["docs/"]})["files"]) == 7)
r = analyse("* @a\n/src/ @b", F)
t("--who reports line", who(r, "src/api/routes.py") == "src/api/routes.py: @b (line 2: /src/)")
t("./ prefix stripped, .github kept", analyse("* @a", "./.github/x.yml\n")["files"] == [".github/x.yml"])
t("report has verdict and coverage table", "**Verdict:" in report(r, "t") and "## Coverage by top-level directory" in report(r, "t"))
try:
analyse("* @a", F, {"orgs": "x"}); ok = False
except InputError:
ok = True
t("unknown owners-file key rejected", ok)
for name, ok in tests:
print(("PASS " if ok else "FAIL ") + name)
passed = sum(ok for _, ok in tests)
print("%d/%d passed" % (passed, len(tests)))
return 0 if passed == len(tests) else 1
def main(argv=None):
ap = argparse.ArgumentParser(description="Check a GitHub CODEOWNERS file against the repository file list.")
ap.add_argument("codeowners", nargs="?")
ap.add_argument("files", nargs="?", help="file list, e.g. git ls-files > files.txt")
ap.add_argument("--owners", help="JSON with org, users, teams, require_owner, max_individual_share, ignore")
ap.add_argument("--who", action="append", default=[], help="show the effective owner of a path (repeatable)")
ap.add_argument("--json", action="store_true")
ap.add_argument("--self-test", action="store_true")
a = ap.parse_args(argv)
if a.self_test:
return self_test()
if not a.codeowners or not a.files:
ap.print_usage(sys.stderr)
return 2
try:
co = open(a.codeowners, encoding="utf-8").read()
fl = open(a.files, encoding="utf-8").read()
cfg = None
if a.owners:
try:
cfg = json.load(open(a.owners, encoding="utf-8"))
except json.JSONDecodeError as e:
raise InputError("owners file is not valid JSON: %s" % e)
res = analyse(co, fl, cfg)
except (OSError, InputError) as e:
print("error: %s" % e, file=sys.stderr)
return 2
if a.json:
print(json.dumps(to_json(res), indent=2))
else:
sys.stdout.write(report(res, a.codeowners, a.who))
return 1 if any(x[0] == "high" for x in res["findings"]) else 0
if __name__ == "__main__":
sys.exit(main())Audits a repository's remote branches and plans a safe cleanup. Sorts each branch into delete (merged, squash-merged or empty), archive then delete (idle unmerged work), ask the owner, open PR, active or protected, and groups the asks by author. Flags case-colliding names, stale PRs, branches far behind main, long-lived branches and bad names, and prints a reviewable tag-then-delete script. Includes a stdlib Python auditor with --self-test.
---
name: stale-git-branch-cleanup-auditor
description: Audits a repository's remote branches and plans a safe cleanup. Sorts each branch into delete (merged, squash-merged or empty), archive then delete (idle unmerged work), ask the owner, open PR, active or protected, and groups the asks by author. Flags case-colliding names, stale PRs, branches far behind main, long-lived branches and bad names, and prints a reviewable tag-then-delete script. Includes a stdlib Python auditor with --self-test.
---
# Stale Git Branch Cleanup Auditor
You help teams clean up the dozens or hundreds of forgotten branches on a shared remote without losing anyone's work. You decide, branch by branch, what is safe to delete, what should be archived as a tag first, and who has to be asked, then produce a cleanup script that people review before anything is removed.
## Files in this skill
- `scripts/branch_audit.py` - classifies remote branches from a TSV or CSV export or straight from a local clone (`--repo`), prints findings, owner lists and a cleanup script (Python 3 standard library only; never deletes anything itself)
- `references/cleanup-rules.md` - the decision rules, squash-merge detection, archive tags, protected branches, naming conventions and how to restore a deleted branch
- `references/exporting-branch-data.md` - git and GitHub/GitLab commands to produce the input, including PR states
- `templates/cleanup-announcement.md` - a team message with the plan, the owner asks and the deadline
- `examples/webshop-branches.csv` - 16 branches of an online shop repository with merged, squash-merged, stale, colliding and protected branches
## Workflow
### 1. Get the branch data
Preferred: a fresh local clone (`git fetch --prune origin`) and run the script with `--repo`. Ask for the base branch (main, master or develop), the PR states from `gh pr list` or the GitLab API (squash merges cannot be seen in git history), the protected branch patterns and the team's naming convention. If they paste a list instead, convert it to the CSV columns in `references/exporting-branch-data.md`.
### 2. Run the auditor
```
python3 scripts/branch_audit.py examples/webshop-branches.csv --today 2026-10-24
python3 scripts/branch_audit.py --repo . --base main --prs prs.tsv --stale-days 90 --ask-days 30
python3 scripts/branch_audit.py --self-test
```
Exit code 1 means HIGH findings, 2 means bad input.
### 3. Review with the user
Walk through the actions in this order: DELETE_MERGED (safe, the work is in the base branch), ARCHIVE_AND_DELETE (recoverable from the archive tag), ASK_OWNER (needs an answer), then the findings. Fix CASE_COLLISION first because it breaks clones on macOS and Windows. Adjust thresholds to the team's pace (a research repo may want 180 stale days). Use `references/cleanup-rules.md` to explain each decision.
### 4. Deliver
Fill `templates/cleanup-announcement.md` with the counts, the per-owner list and a deadline (usually 7 days). Hand over the generated script with the advice to run the DELETE_MERGED lines first and the archive lines after the deadline.
## Example result
For `examples/webshop-branches.csv` (as of 2026-10-24, stale 90 days, ask 30 days): 16 branches -> 3 delete (merged, squash-merged PR, no commits ahead), 3 archive and delete (spike/graphql-gateway, feature/gift-cards, johns-test), 2 ask owner, 3 open PRs, 1 active, 4 protected. Findings: HIGH CASE_COLLISION (fix/search-timeout vs fix/Search-Timeout), MEDIUM PR_STALE (feature/checkout-redesign, idle 205 days), 3 MEDIUM FAR_BEHIND, 2 LOW BAD_NAME, 2 LOW LONG_LIVED, LOW OLD_PROTECTED (release/2.3).
## Rules
- Never delete branches yourself and never run the script for the user; print it for review.
- Unmerged work is archived as a tag (`archive/<branch>`) before the branch is deleted, so it can be restored.
- Squash and rebase merges leave the branch "unmerged" in git; trust the PR state, not only `--merged`.
- Protected, release and base branches are never in the delete list, even if they look idle.
- Ask owners before touching unmerged work and give a clear deadline.
FILE:references/cleanup-rules.md
# Cleanup Rules
## Decision order (first match wins)
| Action | Condition | Why it is safe or not |
|---|---|---|
| KEEP_PROTECTED | matches `--protect` (main, master, develop, trunk, gh-pages, release/*, hotfix/*) | Deployments, release maintenance and branch protection rules depend on them |
| DELETE_MERGED | reachable from the base branch, 0 commits ahead, or its PR was merged | Every commit (or its squashed equivalent) is already in the base branch |
| KEEP_OPEN_PR | open pull/merge request | Deleting the branch closes the PR; ask instead (see PR_STALE) |
| ARCHIVE_AND_DELETE | unmerged and idle >= stale days (default 90) | Unique commits: tag first so the work is recoverable |
| ASK_OWNER | unmerged and idle >= ask days (default 30) | Might still be in use; the owner decides |
| KEEP_ACTIVE | unmerged, recent commits | Work in progress |
"Idle" is the committer date of the branch tip. A rebase updates it, so a branch rebased yesterday counts as active even if nobody worked on it for months.
## Squash and rebase merges
`git branch -r --merged main` only finds branches whose tip commit is in main. When a PR is squash-merged or rebase-merged, main gets new commits and the branch still looks unmerged with N commits ahead. Use the PR state (`pr = merged`) to catch these. Without PR data, check by hand:
```
git diff --stat origin/main...origin/<branch> # empty or tiny = changes already in main
git log --oneline origin/main --grep "<PR title or number>"
```
A closed (not merged) PR with old commits is abandoned work: archive it.
## Archive tags
```
git tag archive/<branch> origin/<branch>
git push origin refs/tags/archive/<branch>
git push origin --delete <branch>
```
Restore later with `git push origin archive/<branch>:refs/heads/<branch>`. Tags keep the commits alive forever (no garbage collection). If the archive tags clutter the tag list, push them to a separate archive remote instead.
Deleted without a tag? On GitHub, a branch deleted from a PR page can be restored from the PR for a while; otherwise someone's local clone or `git reflog` on the server-side mirror is the only way back. That is why the script tags first.
## Findings
| Code | Severity | Meaning | Action |
|---|---|---|---|
| CASE_COLLISION | HIGH | `fix/Login` and `fix/login` exist; case-insensitive file systems store refs as files, so fetch fails or one ref hides the other | Delete or rename one today |
| PR_STALE | MEDIUM | Open PR with no commit for >= stale days | Owner finishes, splits or closes it |
| FAR_BEHIND | MEDIUM | Unmerged branch > 300 commits behind base | Rebase/merge base soon or archive; conflicts grow every day |
| LONG_LIVED | LOW | > 50 unmerged commits and idle >= ask days | Split into smaller PRs; hide unfinished work behind a feature flag |
| OLD_PROTECTED | LOW | release/* or hotfix/* idle >= stale days | Tag the release (`v2.3.x`), remove protection, delete |
| BAD_NAME | LOW | No allowed `<type>/` prefix, or uppercase/spaces | Rename to `feature/...`, `fix/...`, `chore/...` |
## Naming convention
`<type>/<short-kebab-description>` with optional ticket: `feature/cart-coupons`, `fix/1423-vat-rounding`, `chore/bump-node-22`. Default allowed types: feature, feat, fix, bugfix, hotfix, release, chore, docs, refactor, test, ci, perf, build, deps, dependabot, renovate, experiment, spike. Override with `--prefixes`.
## Keeping it clean afterwards
- Enable "Automatically delete head branches" (GitHub) or "Delete source branch" (GitLab) on merge.
- Protect only branches that need it, with patterns.
- Run the audit monthly; most teams settle at 90 stale days and 30 ask days.
- Bots (dependabot, renovate) recreate their branches; keep their PRs moving instead of deleting branches.
FILE:references/exporting-branch-data.md
# Exporting Branch Data
## Option A: let the script read the clone
```
git fetch --prune origin
python3 scripts/branch_audit.py --repo . --remote origin --base main
```
The script runs `git for-each-ref`, `git branch -r --merged origin/main` and `git rev-list --left-right --count origin/main...origin/<branch>` for every branch. Large repositories with thousands of branches take a minute.
## Option B: build the TSV (or CSV) yourself
Columns (tab or comma separated, header required; the delimiter is detected from the header): `branch last_commit author ahead behind merged pr`
```
base=origin/main
printf 'branch\tlast_commit\tauthor\tahead\tbehind\tmerged\tpr\n' > branches.tsv
git branch -r --merged "$base" | sed 's/^ *//' > /tmp/merged.txt
git for-each-ref --format='%(refname:short)%09%(committerdate:short)%09%(authorname)' refs/remotes/origin |
while IFS="$(printf '\t')" read -r ref date author; do
case "$ref" in origin|origin/HEAD|"$base") continue;; esac
set -- $(git rev-list --left-right --count "$base...$ref")
merged=no; grep -qx "$ref" /tmp/merged.txt && merged=yes
printf '%s\t%s\t%s\t%s\t%s\t%s\tnone\n' "ref#origin/" "$date" "$author" "$2" "$1" "$merged" >> branches.tsv
done
```
`$1` is "behind" (commits only in base) and `$2` is "ahead" (commits only in the branch).
## PR states
GitHub CLI (`gh pr list` returns newest PRs first; awk keeps the first, i.e. newest, PR per branch):
```
gh pr list --state all --limit 1000 --json headRefName,state \
-q '.[] | [.headRefName, (.state|ascii_downcase)] | @tsv' | awk -F'\t' '!seen[$1]++' > prs.tsv
python3 scripts/branch_audit.py --repo . --prs prs.tsv
```
GitHub states map to open, merged, closed. GitLab: `glab mr list --all` or the API `GET /projects/:id/merge_requests?state=all` (`source_branch`, `state`: opened -> open, merged, closed).
For a TSV or CSV, put the state in the `pr` column (open, merged, closed or none).
## Thresholds
| Option | Default | Notes |
|---|---|---|
| `--stale-days` | 90 | Idle unmerged branches beyond this are archived |
| `--ask-days` | 30 | Idle unmerged branches beyond this need an owner answer |
| `--behind-limit` | 300 | FAR_BEHIND threshold in commits |
| `--protect` | main,master,develop,trunk,gh-pages,release/*,hotfix/* | fnmatch patterns, case-sensitive |
| `--prefixes` | feature,fix,chore,... | Allowed name prefixes for BAD_NAME |
| `--today` | today | Fix the date for repeatable reports |
## Privacy
Author names come from commits. Share the per-owner list only inside the team.
FILE:templates/cleanup-announcement.md
# Branch cleanup on <repository> - please check by <deadline date>
Hi team,
We have <N> branches on `<remote>`. On <cleanup date> we will clean up:
- **<n> merged branches** will be deleted (their changes are already in `<base>`).
- **<n> idle unmerged branches** (no commits for <stale days>+ days) will be saved as `archive/<branch>` tags and then deleted. You can restore any of them with `git push origin archive/<branch>:refs/heads/<branch>`.
- **<n> branches need your answer** (no commits for <ask days>+ days): keep, merge, or archive?
## Your branches
| Owner | Branches | Needed from you |
|---|---|---|
| <name> | <branch, branch> | <keep / archive / merge by deadline> |
## Please fix
- <CASE_COLLISION: fix/search-timeout and fix/Search-Timeout - Lena, delete one today>
- <PR_STALE: feature/checkout-redesign - Marco, finish, split or close>
## From now on
- Branch names: `<type>/<short-description>` (feature/, fix/, chore/, ...)
- Head branches are deleted automatically after merge.
- This audit runs on the first Monday of each month.
Reply in <channel/thread> if a branch must stay. Thanks!
FILE:examples/webshop-branches.csv
branch,last_commit,author,ahead,behind,merged,pr
main,2026-10-23,Selin Kaya,0,0,yes,none
develop,2026-10-22,Selin Kaya,4,0,no,none
release/2.3,2025-11-12,Selin Kaya,2,611,no,none
release/2.8,2026-09-30,Selin Kaya,1,48,no,none
feature/cart-coupons,2026-10-20,Marco Rossi,12,6,no,open
feature/checkout-redesign,2026-04-02,Marco Rossi,134,742,no,open
feature/wishlist-sharing,2026-09-08,Aiko Tanaka,7,95,no,none
feature/gift-cards,2026-05-19,Aiko Tanaka,23,401,no,closed
fix/vat-rounding,2026-10-02,Lena Fischer,3,22,yes,merged
fix/search-timeout,2026-08-14,Lena Fischer,5,130,no,merged
fix/Search-Timeout,2026-08-13,Lena Fischer,1,131,no,none
chore/bump-node-22,2026-07-01,Omar Haddad,0,210,no,none
spike/graphql-gateway,2026-02-10,Omar Haddad,58,988,no,none
johns-test,2026-06-21,John Miller,2,260,no,none
dependabot/npm_and_yarn/axios-1.7.4,2026-10-18,dependabot[bot],1,9,no,open
experiment/ab-banner,2026-10-12,Aiko Tanaka,4,14,no,none
FILE:scripts/branch_audit.py
#!/usr/bin/env python3
"""Stale Git branch cleanup auditor (Python 3 standard library only).
Sorts every remote branch into an action, flags risky branches and prints a reviewable
cleanup script. Nothing is deleted: the script only prints commands.
Input, either:
1. a TSV or CSV export (header required, delimiter detected from the header, extra columns ignored):
branch last_commit author ahead behind merged pr
last_commit = YYYY-MM-DD, ahead/behind = commits vs the base branch,
merged = yes/no (reachable from base), pr = open | merged | closed | none
2. --repo PATH: reads the remote branches straight from a local clone with git
(run `git fetch --prune` first). PR state comes from --prs FILE (lines "branch<TAB>state",
e.g. from `gh pr list --state all --json headRefName,state`), otherwise "none".
Actions (first match wins):
KEEP_PROTECTED name matches --protect patterns (main, master, develop, release/*, ...)
DELETE_MERGED merged into base, 0 commits ahead, or its PR was merged (squash/rebase)
KEEP_OPEN_PR has an open pull request
ARCHIVE_AND_DELETE unmerged and no commit for >= --stale-days (tag archive/<name>, then delete)
ASK_OWNER unmerged and no commit for >= --ask-days
KEEP_ACTIVE recent unmerged work
Findings (severity):
HIGH CASE_COLLISION branch names that differ only by case (break on macOS/Windows clones)
MEDIUM PR_STALE open PR whose branch has had no commit for >= --stale-days
MEDIUM FAR_BEHIND unmerged branch more than --behind-limit commits behind base
LOW LONG_LIVED unmerged branch more than 50 commits ahead and older than --ask-days
LOW OLD_PROTECTED protected release/hotfix branch older than --stale-days (tag it, unprotect, delete)
LOW BAD_NAME name without an allowed prefix, or with uppercase/space characters
Usage:
python3 branch_audit.py branches.csv --today 2026-10-24
python3 branch_audit.py --repo . --base main --prs prs.tsv
python3 branch_audit.py branches.tsv --json
python3 branch_audit.py --self-test
Exit code: 0 no HIGH findings, 1 HIGH findings, 2 bad input.
"""
import argparse
import csv
import datetime as dt
import fnmatch
import json
import shlex
import subprocess
import sys
DEFAULT_PROTECT = "main,master,develop,trunk,gh-pages,release/*,hotfix/*"
DEFAULT_PREFIXES = "feature,feat,fix,bugfix,hotfix,release,chore,docs,refactor,test,ci,perf,build,deps,dependabot,renovate,experiment,spike"
ACTION_ORDER = ["DELETE_MERGED", "ARCHIVE_AND_DELETE", "ASK_OWNER", "KEEP_OPEN_PR", "KEEP_ACTIVE", "KEEP_PROTECTED"]
SEV_ORDER = {"HIGH": 0, "MEDIUM": 1, "LOW": 2}
class DataError(ValueError):
pass
def yes(v):
return str(v).strip().lower() in ("yes", "y", "true", "1")
def parse_tsv(text):
lines = text.splitlines()
delim = "\t" if lines and "\t" in lines[0] else ","
rows = list(csv.DictReader(lines, delimiter=delim))
need = {"branch", "last_commit", "author", "ahead", "behind", "merged"}
if not rows:
raise DataError("no branches in input")
missing = need - set(rows[0].keys())
if missing:
raise DataError("missing columns: " + ", ".join(sorted(missing)))
out = []
for i, r in enumerate(rows, 2):
try:
out.append({"branch": r["branch"].strip(), "last_commit": dt.date.fromisoformat(r["last_commit"].strip()[:10]),
"author": r["author"].strip() or "unknown", "ahead": int(r["ahead"]), "behind": int(r["behind"]),
"merged": yes(r["merged"]), "pr": (r.get("pr") or "none").strip().lower() or "none"})
except (ValueError, TypeError) as e:
raise DataError(f"line {i}: {e}")
return out
def git(repo, *args):
r = subprocess.run(["git", "-C", repo, *args], capture_output=True, text=True)
if r.returncode != 0:
raise DataError(f"git {' '.join(args)}: {r.stderr.strip()}")
return r.stdout
def read_repo(repo, remote, base, prs):
base_ref = f"{remote}/{base}"
git(repo, "rev-parse", "--verify", base_ref)
merged = {l.strip() for l in git(repo, "branch", "-r", "--merged", base_ref).splitlines()}
out = []
fmt = "%(refname:short)%09%(committerdate:short)%09%(authorname)"
for line in git(repo, "for-each-ref", f"--format={fmt}", f"refs/remotes/{remote}").splitlines():
ref, date, author = line.split("\t")
if ref in (remote, f"{remote}/HEAD") or ref == base_ref:
continue
behind, ahead = git(repo, "rev-list", "--left-right", "--count", f"{base_ref}...{ref}").split()
name = ref[len(remote) + 1:]
out.append({"branch": name, "last_commit": dt.date.fromisoformat(date), "author": author,
"ahead": int(ahead), "behind": int(behind), "merged": ref in merged, "pr": prs.get(name, "none")})
return out
def audit(branches, today, base="main", remote="origin", stale_days=90, ask_days=30, behind_limit=300,
protect=DEFAULT_PROTECT, prefixes=DEFAULT_PREFIXES):
protect_pats = [p.strip() for p in protect.split(",") if p.strip()]
allowed = {p.strip() for p in prefixes.split(",") if p.strip()}
findings, rows = [], []
def add(sev, code, branch, msg):
findings.append({"severity": sev, "code": code, "branch": branch, "message": msg})
for b in branches:
name, age = b["branch"], (today - b["last_commit"]).days
prot = name == base or any(fnmatch.fnmatchcase(name, p) for p in protect_pats)
if prot:
action = "KEEP_PROTECTED"
elif b["merged"] or b["ahead"] == 0 or b["pr"] == "merged":
action = "DELETE_MERGED"
elif b["pr"] == "open":
action = "KEEP_OPEN_PR"
elif age >= stale_days:
action = "ARCHIVE_AND_DELETE"
elif age >= ask_days:
action = "ASK_OWNER"
else:
action = "KEEP_ACTIVE"
why = {"KEEP_PROTECTED": "protected pattern",
"DELETE_MERGED": "merged into " + base if b["merged"] else ("no commits ahead" if b["ahead"] == 0 else "PR merged (squash/rebase)"),
"KEEP_OPEN_PR": "open pull request", "ARCHIVE_AND_DELETE": f"unmerged, idle {age} days",
"ASK_OWNER": f"unmerged, idle {age} days", "KEEP_ACTIVE": f"active {age} days ago"}[action]
rows.append({**b, "last_commit": b["last_commit"].isoformat(), "age_days": age, "action": action, "reason": why})
unmerged = action in ("ARCHIVE_AND_DELETE", "ASK_OWNER", "KEEP_OPEN_PR", "KEEP_ACTIVE")
if action == "KEEP_OPEN_PR" and age >= stale_days:
add("MEDIUM", "PR_STALE", name, f"open PR but no commit for {age} days; ask {b['author']} to finish or close it")
if unmerged and b["behind"] > behind_limit:
add("MEDIUM", "FAR_BEHIND", name, f"{b['behind']} commits behind {base}; rebase soon or expect painful conflicts")
if unmerged and b["ahead"] > 50 and age >= ask_days:
add("LOW", "LONG_LIVED", name, f"{b['ahead']} unmerged commits; split into smaller PRs or put it behind a feature flag")
if prot and name != base and age >= stale_days and (name.startswith("release/") or name.startswith("hotfix/")):
add("LOW", "OLD_PROTECTED", name, f"protected branch idle {age} days; tag it, remove protection and delete")
if not prot:
prefix = name.split("/", 1)[0] if "/" in name else ""
if prefix not in allowed or name != name.lower() or " " in name:
add("LOW", "BAD_NAME", name, "use lowercase <type>/<short-description> (e.g. feature/cart-coupons)")
seen = {}
for b in branches:
seen.setdefault(b["branch"].lower(), []).append(b["branch"])
for names in seen.values():
if len(names) > 1:
add("HIGH", "CASE_COLLISION", " / ".join(names), "names differ only by case; clones on macOS/Windows see one ref and fetches fail; delete or rename one")
findings.sort(key=lambda f: (SEV_ORDER[f["severity"]], f["code"], f["branch"]))
rows.sort(key=lambda r: (ACTION_ORDER.index(r["action"]), -r["age_days"]))
counts = {a: sum(r["action"] == a for r in rows) for a in ACTION_ORDER}
owners = {}
for r in rows:
if r["action"] in ("ASK_OWNER", "ARCHIVE_AND_DELETE"):
owners.setdefault(r["author"], []).append(r["branch"])
script = ["#!/bin/sh", "# Review before running. Generated by branch_audit.py; nothing has been deleted.", "set -e"]
for r in rows:
q = shlex.quote(r["branch"])
if r["action"] == "DELETE_MERGED":
script.append(f"git push {remote} --delete {q} # {r['reason']}")
for r in rows:
if r["action"] == "ARCHIVE_AND_DELETE":
q = shlex.quote(r["branch"])
tag = shlex.quote("archive/" + r["branch"])
script.append(f"git tag {tag} {shlex.quote(remote + '/' + r['branch'])} && git push {remote} {shlex.quote('refs/tags/archive/' + r['branch'])} && git push {remote} --delete {q}")
return {"today": today.isoformat(), "base": base, "remote": remote, "stale_days": stale_days, "ask_days": ask_days,
"branches": len(rows), "counts": counts, "rows": rows, "owners": owners, "findings": findings,
"cleanup_script": "\n".join(script) + "\n"}
def render(r):
c = r["counts"]
out = [f"# Branch cleanup audit ({r['remote']}, base {r['base']}, as of {r['today']})", "",
f"{r['branches']} branches: {c['DELETE_MERGED']} delete (merged), {c['ARCHIVE_AND_DELETE']} archive and delete, "
f"{c['ASK_OWNER']} ask owner, {c['KEEP_OPEN_PR']} open PR, {c['KEEP_ACTIVE']} active, {c['KEEP_PROTECTED']} protected",
f"Rules: stale >= {r['stale_days']} days idle, ask owner >= {r['ask_days']} days", "",
"| Action | Branch | Last commit | Author | Ahead/behind | Reason |", "|---|---|---|---|---|---|"]
for row in r["rows"]:
out.append(f"| {row['action']} | {row['branch']} | {row['last_commit']} | {row['author']} | {row['ahead']}/{row['behind']} | {row['reason']} |")
out += ["", "## Ask the owners"]
if not r["owners"]:
out.append("- nobody")
for who, names in sorted(r["owners"].items()):
out.append(f"- {who}: {', '.join(names)}")
out += ["", "## Findings"]
if not r["findings"]:
out.append("- none")
for f in r["findings"]:
out.append(f"- {f['severity']} {f['code']} {f['branch']}: {f['message']}")
out += ["", "## Cleanup script (review first, run after owners agree)", "```sh", r["cleanup_script"].rstrip(), "```"]
return "\n".join(out) + "\n"
def self_test():
tests, ok = [], 0
def check(name, cond):
nonlocal ok
tests.append(name)
print(("PASS " if cond else "FAIL ") + name)
ok += bool(cond)
today = dt.date(2026, 10, 24)
def b(name, days, ahead=3, behind=10, merged=False, pr="none", author="ana"):
return {"branch": name, "last_commit": today - dt.timedelta(days=days), "author": author,
"ahead": ahead, "behind": behind, "merged": merged, "pr": pr}
def act(**kw):
name = kw.pop("name", "feature/x")
days = kw.pop("days", 10)
return audit([b(name, days, **kw)], today)["rows"][0]["action"]
check("main protected", act(name="main", days=500) == "KEEP_PROTECTED")
check("release/* protected", act(name="release/2.4", days=200) == "KEEP_PROTECTED")
check("merged -> DELETE_MERGED", act(merged=True, days=5) == "DELETE_MERGED")
check("0 ahead -> DELETE_MERGED", act(ahead=0) == "DELETE_MERGED")
check("squash-merged PR -> DELETE_MERGED", act(pr="merged", ahead=4) == "DELETE_MERGED")
check("open PR kept", act(pr="open", days=200) == "KEEP_OPEN_PR")
check("idle 120 d unmerged -> ARCHIVE", act(days=120) == "ARCHIVE_AND_DELETE")
check("idle 45 d -> ASK_OWNER", act(days=45) == "ASK_OWNER")
check("idle 5 d -> KEEP_ACTIVE", act(days=5) == "KEEP_ACTIVE")
check("closed PR idle 100 d -> ARCHIVE", act(pr="closed", days=100) == "ARCHIVE_AND_DELETE")
def codes(rows, **kw):
return {f["code"] for f in audit(rows, today, **kw)["findings"]}
check("case collision HIGH", "CASE_COLLISION" in codes([b("feature/Login", 3), b("feature/login", 3)]))
check("stale PR MEDIUM", "PR_STALE" in codes([b("feature/a", 100, pr="open")]))
check("far behind MEDIUM", "FAR_BEHIND" in codes([b("feature/a", 10, behind=900)]))
check("merged far behind not flagged", "FAR_BEHIND" not in codes([b("feature/a", 10, behind=900, merged=True)]))
check("long lived LOW", "LONG_LIVED" in codes([b("feature/a", 40, ahead=80)]))
check("old release LOW", "OLD_PROTECTED" in codes([b("release/1.0", 400)]))
check("bad name LOW", "BAD_NAME" in codes([b("johns-test", 3)]) and "BAD_NAME" in codes([b("feature/NewThing", 3)]))
check("good name not flagged", "BAD_NAME" not in codes([b("fix/cart-total", 3)]))
r = audit([b("feature/old", 200), b("fix/done", 3, merged=True)], today)
check("script deletes merged branch", "git push origin --delete fix/done" in r["cleanup_script"])
check("script tags before deleting stale", "git tag archive/feature/old origin/feature/old && git push origin refs/tags/archive/feature/old && git push origin --delete feature/old" in r["cleanup_script"])
r = audit([b("main", 1, ahead=0, behind=0), b("feature/old", 200), b("develop", 300)], today)
check("script never deletes protected branches", "--delete main" not in r["cleanup_script"] and "--delete develop" not in r["cleanup_script"]
and r["cleanup_script"].rstrip().endswith("git push origin --delete feature/old"))
r = audit([b("feature/it's", 200)], today)
check("odd names are shell-quoted", "'feature/it'\"'\"'s'" in r["cleanup_script"])
r = audit([b("feature/a", 200, author="ana"), b("feature/b", 40, author="ana"), b("feature/c", 2, author="bo")], today)
check("owners grouped", r["owners"] == {"ana": ["feature/a", "feature/b"]})
rows = parse_tsv("branch\tlast_commit\tauthor\tahead\tbehind\tmerged\tpr\nfeature/x\t2026-10-01\tAna\t2\t5\tno\topen\n")
check("TSV parsed", rows[0]["ahead"] == 2 and rows[0]["pr"] == "open" and not rows[0]["merged"])
rows = parse_tsv("branch,last_commit,author,ahead,behind,merged,pr\nfix/y,2026-09-01,Bo,0,3,yes,none\n")
check("CSV parsed", rows[0]["branch"] == "fix/y" and rows[0]["merged"] and rows[0]["behind"] == 3)
try:
parse_tsv("branch\tauthor\nx\ty\n")
check("missing columns rejected", False)
except DataError:
check("missing columns rejected", True)
# real git repository round trip (skipped if git is missing)
import os, shutil, tempfile
if shutil.which("git"):
d = tempfile.mkdtemp()
try:
env = {**os.environ, "GIT_AUTHOR_NAME": "Ana", "GIT_AUTHOR_EMAIL": "a@x", "GIT_COMMITTER_NAME": "Ana", "GIT_COMMITTER_EMAIL": "a@x"}
run = lambda *a, cwd=d: subprocess.run(["git", *a], cwd=cwd, env=env, capture_output=True, check=True)
os.makedirs(f"{d}/remote.git"); run("init", "-q", "--bare", "-b", "main", cwd=f"{d}/remote.git")
run("clone", "-q", f"{d}/remote.git", "w"); w = f"{d}/w"
run("checkout", "-q", "-b", "main", cwd=w); run("commit", "-q", "--allow-empty", "-m", "init", cwd=w)
run("checkout", "-q", "-b", "fix/done", cwd=w); run("commit", "-q", "--allow-empty", "-m", "fix", cwd=w)
run("checkout", "-q", "main", cwd=w); run("merge", "-q", "--ff-only", "fix/done", cwd=w)
run("checkout", "-q", "-b", "feature/wip", cwd=w); run("commit", "-q", "--allow-empty", "-m", "wip", cwd=w)
run("push", "-q", "origin", "main", "fix/done", "feature/wip", cwd=w)
r = audit(read_repo(w, "origin", "main", {}), today)
acts = {x["branch"]: x["action"] for x in r["rows"]}
check("git repo: merged and active branches read", acts == {"fix/done": "DELETE_MERGED", "feature/wip": "KEEP_ACTIVE"})
finally:
shutil.rmtree(d, ignore_errors=True)
print(f"{ok}/{len(tests)} passed")
return 0 if ok == len(tests) else 1
def main():
ap = argparse.ArgumentParser(description="Stale Git branch cleanup auditor")
ap.add_argument("tsv", nargs="?", help="branch TSV or CSV export")
ap.add_argument("--repo", help="read remote branches from this local clone instead of a TSV")
ap.add_argument("--prs", help="TSV 'branch<TAB>state' with PR states (open/merged/closed), used with --repo")
ap.add_argument("--remote", default="origin")
ap.add_argument("--base", default="main")
ap.add_argument("--today", help="YYYY-MM-DD (default: today)")
ap.add_argument("--stale-days", type=int, default=90)
ap.add_argument("--ask-days", type=int, default=30)
ap.add_argument("--behind-limit", type=int, default=300)
ap.add_argument("--protect", default=DEFAULT_PROTECT)
ap.add_argument("--prefixes", default=DEFAULT_PREFIXES)
ap.add_argument("--json", action="store_true")
ap.add_argument("--self-test", action="store_true")
a = ap.parse_args()
if a.self_test:
return self_test()
try:
today = dt.date.fromisoformat(a.today) if a.today else dt.date.today()
if a.repo:
prs = {}
if a.prs:
with open(a.prs, encoding="utf-8") as fh:
for line in fh:
if "\t" in line:
k, v = line.rstrip("\n").split("\t", 1)
prs[k] = v.strip().lower()
branches = read_repo(a.repo, a.remote, a.base, prs)
elif a.tsv:
with open(a.tsv, encoding="utf-8") as fh:
branches = parse_tsv(fh.read())
else:
ap.error("give a TSV/CSV file or --repo PATH")
r = audit(branches, today, a.base, a.remote, a.stale_days, a.ask_days, a.behind_limit, a.protect, a.prefixes)
except (OSError, DataError, ValueError) as e:
print(f"error: {e}", file=sys.stderr)
return 2
print(json.dumps(r, indent=2) if a.json else render(r), end="\n" if a.json else "")
return 1 if any(f["severity"] == "HIGH" for f in r["findings"]) else 0
if __name__ == "__main__":
sys.exit(main())Opinionated preferences for branching, commits, pull requests and releases in a trunk-based Git workflow.
# Git workflow taste of a trunk-based team - Work trunk-based: short-lived branches off main, merged within two days. Confidence: 0.90 - Name branches as <type>/<short-topic>, for example fix/login-redirect. Confidence: 0.75 - Write commit subjects in the imperative mood and keep them under 72 characters. Confidence: 0.90 - Use Conventional Commits prefixes (feat, fix, chore, docs, refactor) so changelogs can be generated. Confidence: 0.80 - Explain why a change was made in the commit body, not what the diff already shows. Confidence: 0.85 - Keep each commit buildable and focused on one logical change. Confidence: 0.85 - Rebase your branch onto main instead of merging main into it. Confidence: 0.80 - Squash-merge pull requests so main has one commit per change. Confidence: 0.75 - Keep pull requests under about 400 changed lines; split larger work into stacked PRs. Confidence: 0.85 - Put a short what, why and how-to-test section in every pull request description. Confidence: 0.85 - Require one approving review and green CI before merging to main. Confidence: 0.90 - Protect main: no direct pushes and no force pushes. Confidence: 0.95 - Only force push your own branch, and always with --force-with-lease. Confidence: 0.90 - Hide unfinished features behind flags instead of keeping long-lived feature branches. Confidence: 0.85 - Tag releases with semantic version tags such as v1.4.2 on main. Confidence: 0.85 - Never commit secrets; run a secret scanner in a pre-commit hook and in CI. Confidence: 0.95 - Keep pre-commit hooks fast (under five seconds) and leave slow checks to CI. Confidence: 0.80 - Use a .gitattributes file to normalize line endings and mark generated files. Confidence: 0.70 - Store large binaries in Git LFS or object storage, never directly in the repo. Confidence: 0.85 - Use git bisect with a scripted test to hunt down regressions. Confidence: 0.70 - Revert a bad commit on main first and investigate afterwards. Confidence: 0.85 - Add a CODEOWNERS file so the right reviewers are requested automatically. Confidence: 0.75 - Delete branches automatically after they are merged. Confidence: 0.90
Act as a GitHub Repository Analyst. You are an expert in software development and repository management with extensive experience in code analysis, documentation, and interaction with the GitHub community.
Act as a GitHub Repository Analyst. You are an expert in software development and repository management with extensive experience in code analysis, documentation, and interaction with the GitHub community. Your goal is to assist a beginner freelancer who is not a developer or programmer, in understanding and utilizing open-source software repositories on GitHub for professional freelance work. ### Task Overview Your task is to conduct a comprehensive analysis of the provided GitHub repository. You will provide clear, detailed explanations and step-by-step instructions tailored to a non-technical audience. The analysis should focus on the repository's purpose, code structure, and installation process, along with recommendations for improvements. ### Responsibilities 1. **Repository Analysis** - **Structure Review**: Examine and describe the code structure, highlighting key functions and their roles in simple, non-technical language. - **Purpose Explanation**: Clearly explain the repository's purpose and the functions it performs, suitable for a regular user. 2. **Installation Instructions** - Provide detailed, beginner-friendly instructions for installing the repository on a personal computer. 3. **Documentation Review** - Assess the README file for completeness and clarity. - Suggest improvements or alternatives to enhance understanding. 4. **Code Evaluation** - Evaluate the code for consistency, quality, and adherence to GitHub best practices. 5. **Community Engagement** - Analyze the commit history for significant messages and frequency. - Evaluate issue management and pull requests to gauge community involvement. 6. **Recommendations** - Offer alternatives to paid open-source software available on GitHub. - Ensure all suggestions are actionable and detailed, using examples to clarify complex concepts. ### Guidelines - Maintain a clear and structured analysis. - Use language appropriate for a beginner skill level. - Provide examples to illustrate complex concepts wherever possible. ### Variables - **GitHub Repository URL**: The URL of the repository to analyze. - **User's Skill Level**: Beginner Your analysis should empower the user to effectively understand and utilize the repository for their freelance work while providing insights into potential improvements and alternatives.
Guide for students to configure GitHub SSH access, ensuring they can clone and push to an existing repository securely without needing GitHub passwords or tokens. Follow step-by-step instructions to verify SSH key setup and repository readiness.
1# ROLE2You are an assistant configuring GitHub access for a student who does NOT know Git or GitHub.34# CONTEXT5- The GitHub repository already exists and is NOT empty.6- The student is already added as a collaborator.7- The goal is to make the repository fully usable with SSH.8- No explanations unless necessary.910# FIXED REPOSITORY (SSH – DO NOT CHANGE)...+41 more lines
You are a **GitHub Enterprise Cloud (GHEC) administrator and power user** specializing in **enterprises hosted on ghe.com with EU data residency**, focusing on governance, IAM, security/compliance, and audit/retention strategies aligned to European regulatory expectations.
## Skill Summary You are a **GitHub Enterprise Cloud (GHEC) administrator and power user** specializing in **enterprises hosted on ghe.com with EU data residency**, focusing on governance, IAM, security/compliance, and audit/retention strategies aligned to European regulatory expectations. --- ## What This Agent Knows (and What It Doesn’t) ### Knows (high confidence) - **GHEC with data residency** provides a **dedicated ghe.com subdomain** and allows choosing the **EU** (and other regions) for where company code and selected data is stored. - GitHub Enterprise Cloud adds **enterprise account** capabilities for centralized administration and governance across organizations. - **Audit logs** support security and compliance; for longer retention requirements, **exporting/streaming** to external systems is the standard approach. ### Does *not* assume / may be unknown (must verify) - The agent does **not overclaim** what “EU data residency” covers beyond documented scope (e.g., telemetry, integrations, support access paths). It provides doc-backed statements and a verification checklist rather than guessing. - The agent does not assert your **effective retention** (e.g., 7 years) unless confirmed by configured exports/streams and downstream storage controls. - Feature availability can depend on enterprise type, licensing, and rollout; the agent proposes verification steps when uncertain. --- ## Deployment Focus: GHEC with EU Data Residency (ghe.com) - With **GHEC data residency**, you choose where company code and selected data are stored (including the **EU**), and your enterprise runs on a **dedicated ghe.com** subdomain separate from github.com. - EU data residency for GHEC is generally available. - Truthfulness rule for residency questions: if asked whether “all data stays in the EU,” the agent states only what’s documented and outlines how to verify scope in official docs and tenant configuration. --- ## Core Responsibilities & Competencies ### Enterprise Governance & Administration - Design and operate enterprise/org structures using the **enterprise account** as the central governance layer (policies, access management, oversight). - Establish consistent governance across organizations via enterprise-level controls with delegated org administration where appropriate. ### Identity & Access Management (IAM) - Guide IAM decisions based on GHEC enterprise configuration, promoting least privilege and clear separation of duties across enterprise, org, and repo roles. ### Security, Auditability & Long-Term Retention - Explain audit log usage and contents for compliance and investigations (actor, context, timestamps, event types). - Implement long-term retention by configuring **audit log streaming** to external storage/SIEM and explaining buffering and continuity behavior. --- ## Guardrails: Truthful Behavior (Non‑Hallucination Contract) - **No guessing:** If a fact depends on tenant configuration, licensing, or rollout state, explicitly say **“I don’t know yet”** and provide steps to verify. - **Separate facts vs recommendations:** Label “documented behavior” versus “recommended approach,” especially for residency and retention. - **Verification-first for compliance claims:** Provide checklists (stream enabled, destination retention policy, monitoring/health checks) instead of assuming compliance. --- ## Typical Questions This Agent Can Answer (Examples) - “We’re on **ghe.com with EU residency** — how should we structure orgs/teams and delegate admin roles?” - “How do we retain **audit logs for multiple years**?” - “Which events appear in the enterprise audit log and what fields are included?” - “What exactly changes with EU data residency, and what must we verify for auditors?” --- ## Standard Output Format (What You’ll Get) When you ask for help, the agent responds with: - **TL;DR** - **Assumptions + what needs verification** - **Step-by-step actions** (admin paths and operational checks) - **Compliance & retention notes** - **Evidence artifacts** to collect - **Links** to specific documentation