Repository navigation
feat(repo-stats): count review cycles per PR and show them on the dashboard - #4
Merged
Merged
Conversation
…hboard A review cycle is one round of review on one version of the PR. GitHub reviews name the commit they were made against; GitLab cycles come from the MR notes (pushes split cycles, comments and approvals by others are reviews), read in full up to 50 cycles. Git mode leaves cycles empty. Records, CSV and JSON gain review_cycles, changes_requested and reviewers. The dashboard adds Median review cycles and Merged without review KPIs, a Review cycles section (statistics with and without unreviewed PRs, distribution, monthly trend, by size, top ten), a by-type column and a Methodology entry. GitLab approvals without a comment now count as a review.
…view covered On GitHub a reply to an older review thread is a new review of the older commit, so comparing each review with the previous one counted A, B, A, B as four cycles. Found by running on googleapis/librarian (#7469 was counted 6, has 2).
g-husam
added a commit
that referenced
this pull request
Oct 28, 2026
…ned CI, 404 probe) (#5) Follow-ups from the #3 review. They fix GitHub Enterprise logins, run the CLI from a private directory, pin the CI examples, and stop a single 404 from turning off GitLab commit lookups for every MR. The tests no longer reach a real `gh` or depend on timing. ### What changed ```diff Cli(tool, host) - hint: "in CI set GH_TOKEN" # wrong for GitHub Enterprise Server + hint: "in CI set " + ci_login_hint(tool, host) # GH_TOKEN for github.com / *.ghe.com, else GH_ENTERPRISE_TOKEN - _run: cwd = tempfile.gettempdir() # shared /tmp: another user can plant a .git + _run: cwd = private TemporaryDirectory # new, empty, 0700, one per run, removed after it + close() / with-block collect - cli = Cli(...) + with Cli(...) as cli fetch_gitlab - probe refused on 401 / 403 / 404 # one missing MR turned off commits for all MRs + probe refused on 401 / 403 # a 404 only affects that MR retries - time.sleep(...) + _backoff(...) # tests patch this instead of time.sleep for everyone ``` ### Docs (`README.adoc`) ```diff Logging in + NOTE: GitHub Enterprise Server uses GH_ENTERPRISE_TOKEN, not GH_TOKEN GitHub Actions + ref: <full commit SHA> # pin the tool: it runs next to the token + GHES: set GH_ENTERPRISE_TOKEN instead GitLab CI - git clone --depth 1 …scripts.git # unpinned HEAD + git fetch --depth 1 …scripts.git "$REPO_STATS_SHA" && git checkout FETCH_HEAD Security - runs from the system temp directory + runs from a new, empty, private temp directory ``` ### Tests ```text tests/test_repo_stats.py ├── B3 login hint names GH_ENTERPRISE_TOKEN for a GHES host (and GH_TOKEN alone is not enough) ├── B3 glab with no login → anonymous 401 → git fallback naming `glab auth login` ├── B3 "gh missing" test puts only git on PATH (/usr/bin also holds a real gh, which it used to run) ├── B4/F2/… patch rs._backoff instead of time.sleep (subprocess's own sleeps made the retry tests flaky) ├── G1 every CLI call runs in one private repo-stats-cli-* dir, mode 0700, removed after the run ├── G2 a 404 on the probed MR's commits does not stop lookups for the other MRs └── review cycles (#4) close the Cli the GitLab helper creates ``` ### Not changed - The review also said the "no PRs in the selected date range" warning ignores `--until`. That was wrong: the API filters only by `--since`, so an empty result with only `--until` means the repository has no PRs. The message is correct as it is. - No code left over from #3 needed deleting: no unused imports, functions or constants were found. ### Testing - `python3 -m unittest test_repo_stats`: 222 tests pass on Python 3.13 (rebased on main with #4), with no `ResourceWarning`. Run with `GIT_CONFIG_GLOBAL=/dev/null`, because a global `tag.gpgSign` breaks the fixtures' annotated tags. - Not run: the Playwright UI tests (no node here) and Python 3.8. `template.html` is unchanged. - The real `glab` no-login behaviour and the job-token permissions are still checked only against the fakes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Counts how many review cycles each PR goes through and shows them on the dashboard.
A review cycle is one round of review on one version of the PR, by anyone other than the author and bots, before the merge:
Data
reviews{commit{oid}}), so a review of a new oid starts a new cycle. Force-pushes and rebases are handled correctly, and no extra API calls are needed. The page size is raised to 100 reviews. Above that, the count is marked as a lower bound.added N commitsandforce-pushedsystem notes are pushes, and comments and approvals by other people are reviews. All notes are read, up to 50 cycles; past that, the value is capped and marked as a lower bound. This uses no new endpoint, so it still works with a CI job token.None), never guessed.review_cycles,changes_requested(GitHub only) andreviewers.Dashboard
Tests
test_repo_stats.H1_ReviewCycles(15 new tests): the counting rule, the cap, every scenario above, force-pushes, ignored reviews (author, bot, pending, post-merge), truncation, GitLab pushes and approvals,--no-reviews, git mode and the CSV columns.test_ui(2 new tests, 40 in total): the KPIs and statistics tables are checked against Python's numbers with and without unreviewed PRs, and git mode is checked for the "needs API" message. The synthetic API dataset now has multi-cycle reviews.B3/B4tests fail the same way onmainin my sandbox; this is an environment issue (a realghon PATH, and sleep mocking), not this change.