Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,14 @@ Prints a weekly backlog and review-cost report for the cataloged repositories to
```sh
uv run --no-project --script scripts/backlog_metrics.py
uv run --no-project --script scripts/backlog_metrics.py --days 14 --format json --repo Example
uv run --no-project --script scripts/backlog_metrics.py --billing
```

It is a uv script, with the same inline metadata as `pr_review.py`. That lets it import the review gate's readers instead of keeping copies that would drift from them.

The table has a row per repository and a totals row. The columns are issues opened and closed in the window, handoff issues created, and issues open now. Next come pull requests merged, issues opened per merged pull request (`n/a` without a merge), and workflow runs. Last come runs named `Running Copilot Code Review` and those review runs per merged pull request (`n/a` without a merge). Every issue count except the handoff column leaves out issues labeled `handoff`. In the Markdown output each repository name links to its GitHub page. Each issue and pull request count links to the GitHub search listing what it counts. Each dated search runs from the window's first day through its last, and the open-now search lists what is open when it is opened. The workflow run counts print plain, since they come from `gh run list` rather than from a search.

A line per repository follows with its open issues by label, and an issue with several labels counts under each. The labels the script names print first, a zero included, and every other label an open issue carries follows them. An issue labeled `handoff` is left out here too. The month's Actions minutes per repository and Copilot gross come from the user billing usage endpoint. They cover the calendar month to date rather than the window, so the report does not divide them by the window's merges. A failed call prints one line saying billing was unavailable rather than a zero. A list that reaches the item limit is noted in the report. A failed issue, pull request, or run call exits `1` with no report.
A line per repository follows with its open issues by label, and an issue with several labels counts under each. The labels the script names print first, a zero included, and every other label an open issue carries follows them. An issue labeled `handoff` is left out here too. With `--billing`, the month's Actions minutes per repository and Copilot gross come from the user billing usage endpoint. They cover the calendar month to date rather than the window, so the report does not divide them by the window's merges. A failed call prints one line saying billing was unavailable rather than a zero. Without the flag, which is the default, the read is skipped and the report prints no billing line and no billing note. The endpoint needs the "Plan" user permission, which a fine-grained personal access token cannot be granted, so only a classic token reaches it. A list that reaches the item limit is noted in the report. A failed issue, pull request, or run call in the backlog counts exits `1` with no report.

Two more tables measure what the pull request bots return for what they cost. They let a move from automatic to requested review be judged before and after. They read the window's merged pull requests through one paged GraphQL search per repository, newest created first. A pull request that appears twice while paging is counted once and noted. The search stops at 500 pull requests per repository, and each pull request connection is capped as well. A cap that was reached is named in the report, so a truncated figure never reads as a whole one. The bot logins come from the gate's reviewer vocabularies. A promotion pull request, one from `develop` into the default branch, is left out and counted in its own column. It would otherwise dominate the commit and failing-head counts.

Expand All @@ -368,15 +369,22 @@ Threaded findings are the review threads the bot opened. Qodo's findings listed

The per-repository table lists commits per merged pull request. It lists the sum of local attestation findings, with `unknown` attestations counted apart. The gate's own readers decide what counts, `trusted_comments` and its attestation pattern. So a marker counts only from an owner, member or collaborator, in a comment that is not minimized. Its `base=` must match the pull request's base, and the marker must stand on a line of its own outside a code block. The first marker for a head is the one counted, as the gate reads it. The table also lists the failing heads and how many of those had a `findings=0` attestation on the same head.

The policy trigger is read once per repository from `.github/agent-policy.json` at the head of `develop`. The review gate reads a pull request's policy from its base, and feature pull requests merge there. A repository without `develop` falls back to its default branch, and the table names the branch read. The file is read through `pr_review_policy.py`'s `fetch`, as the review gate reads it. So a file the gate refuses prints `error` here as well. A file the gate takes as absent, or one stating no `review` section, prints the trigger from the hub's `spec/agent-policy.default.json`. That trigger is marked `(default)`, since the repository runs under it. The file's commit history on that branch is read for the window too. Where it changed inside the window, a note names the dates, because the window may then mix two review policies. The file holds other sections too, so a change there may leave the review policy as it was. A failed trigger read prints `error`. So does a failed read of the default branch or of whether `develop` exists, which also prints `n/a` as the branch. A failed history read prints its own note and leaves the trigger as read. Each still writes the report, names the failed read on stderr, and exits `1`. A failed review query leaves the two review tables out. The report still carries the backlog table and the billing lines. It adds one line saying the review figures were unavailable, with the error. It also names the error on stderr and exits `1`. A failed backlog read still exits `1` with no report.
The policy trigger is read once per repository from `.github/agent-policy.json` at the head of `develop`. The review gate reads a pull request's policy from its base, and feature pull requests merge there. A repository without `develop` falls back to its default branch, and the table names the branch read. The file is read through `pr_review_policy.py`'s `fetch`, as the review gate reads it. So a file the gate refuses prints `error` here as well. A file the gate takes as absent, or one stating no `review` section, prints the trigger from the hub's `spec/agent-policy.default.json`. That trigger is marked `(default)`, since the repository runs under it. The file's commit history on that branch is read for the window too. Where it changed inside the window, a note names the dates, because the window may then mix two review policies. The file holds other sections too, so a change there may leave the review policy as it was. A failed trigger read prints `error`. So does a failed read of the default branch or of whether `develop` exists, which also prints `n/a` as the branch. A failed history read prints its own note and leaves the trigger as read. Each still writes the report, names the failed read on stderr, and exits `1`. A failed review query leaves the two review tables out. The report still carries the backlog table, and the billing lines where `--billing` asked for them. It adds one line saying the review figures were unavailable, with the error. It also names the error on stderr and exits `1`. A failed backlog read still exits `1` with no report.

`--format json` prints the same figures as one JSON document, for a consumer that renders its own report. A test pins this shape, since a downstream template depends on its field names. A change that renames or removes a field raises `schema`. Each `html_url` is that item's GitHub page.

- `schema` is `1`. `start` and `end` are the window's dates, as `YYYY-MM-DD`.
- `totals` holds the totals row as numbers. Its fields are `issues_opened`, `issues_closed`, `handoffs_created`, `issues_open`, `prs_merged`, `issues_opened_per_merged_pr`, `workflow_runs`, `copilot_review_runs`, and `copilot_review_runs_per_merged_pr`. A ratio is `null` where the Markdown prints `n/a`.
- `billing` holds `month`, `error`, `actions_minutes` (repository name to minutes), and `copilot_gross_usd`. Where billing failed, `error` names the failure and the two figures are `null`, and otherwise `error` is `null`.
- `billing` is `null` where the run skipped the billing read, which is the default and adds no note. With `--billing` it holds `month`, `error`, `actions_minutes` (repository name to minutes), and `copilot_gross_usd`. Where that read failed, `error` names the failure and the two figures are `null`, and otherwise `error` is `null`.
- `notes` is the list of billing lines and notes the Markdown report prints after its label lines. Those label lines are each repository's `open_issues_by_label` here.
- `repositories` holds one entry per repository, in the order read. Each carries `name`, `html_url`, and the same nine fields `totals` carries, counted for that repository. Next come `open_issues_by_label`, label name to count, and `truncated`, true where a list reached the item limit.
- `repositories` holds one entry per repository, in the order read. Each carries `name`, `html_url`, and the same nine fields `totals` carries, counted for that repository. Next come `open_issues_by_label`, label name to count, and `truncated`, true where a list reached the item limit. `truncated_lists` names each list that reached it, from `issues_opened`, `issues_closed`, `issues_open`, `prs_merged`, and `workflow_runs`, and is empty where `truncated` is false. Then comes `attention`.
- Each repository's `attention` is read only for `--format json`, and is `null` for every repository where that read failed. It reads all of them in one pass, so a failure in any one leaves every `attention` `null`. A failed read adds one note, names the error on stderr, and exits `1`. Open pull requests are read newest-updated first, up to 500, drafts counting toward that cap and in no list. It holds these lists, each empty where nothing needs the maintainer:
- `failing_pull_requests`: open pull requests whose head has a check run concluded `FAILURE`, `TIMED_OUT`, `ACTION_REQUIRED`, or `STARTUP_FAILURE`, or a status context in `FAILURE` or `ERROR`. The checks are read as the review gate reads them. `CANCELLED` is left out. Each entry has `number`, `title`, `html_url`, `author`, `base_branch`, and `failing_checks`, the names of the failing checks.
- `stale_pull_requests`: open pull requests with no update for `--stale-days` days, 7 by default, counted to the instant, and no failing check. Each entry has the same fields, with `updated_at` in place of `failing_checks`.
- `failing_branches`: for the default branch, and `develop` where it exists, each workflow whose latest completed run concluded `failure`, `timed_out`, or `startup_failure`. Each entry has `branch`, `workflow`, `conclusion`, the run's `html_url`, and `failed_runs_in_window`. The latest 200 runs of each branch are read. A cancelled, skipped, or neutral run decides nothing. A pull request's run and a Copilot review run are left out, since both carry another branch's name.
- `recovered_branches`: on those branches, each workflow that failed in the window while its latest completed run did not. Each entry has `branch`, `workflow`, `failed_runs_in_window`, and the `html_url` of its newest failed run.
- `truncated`: strings naming a cap that was reached, such as a cut pull request list or run list.
The open `decision` issues are already in `items.issues_open`.
- Each repository's `items` lists what each count counted, under the same names. `issues_opened`, `issues_closed`, `handoffs_created`, and `issues_open` hold issues as `number`, `title`, `html_url`, and `labels`. `prs_merged` holds pull requests as `number`, `title`, and `html_url`. `workflow_runs` and `copilot_review_runs` hold runs as `id`, `name`, and `html_url`.
- Each repository's `review` is `null` where the review query failed. Otherwise it holds the per-repository table's figures: `merged_prs_read`, `promotion_prs_excluded`, `commits_per_merged_pr`, `local_findings`, `local_attestations_unknown`, `failing_heads`, and `failing_heads_after_clean_local_review`. Then come `policy_branch`, `policy_error`, and `policy_history_error`, each a string or `null`. `policy_changes` lists the dates the policy file changed, as `YYYY-MM-DD`. An entry reads `unknown` for a commit carrying no date, and a last entry reads `more than 10 commits` past that many. `truncated` lists the caps reached. `bots` maps each bot to its per-bot row. That row holds `policy_trigger`, `policy_from_default`, `requests_by_automation`, `requests_by_user`, `automatic_rounds`, `explicit_rounds`, `unclassified_rounds`, `rounds_per_reviewed_pr_mean`, `rounds_per_reviewed_pr_max`, `threaded_findings`, `findings_missed_by_local_review`, and `findings_on_green_heads`. A figure the Markdown prints as `n/a` or `error` is `null`. `policy_trigger` is the trigger as the policy states it, and `policy_from_default` is true where it comes from the hub default, which the Markdown marks `(default)`.

Expand Down
Loading
Loading