Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

feat(ui): show the owner's line share and the merge commit count (#2730)

Raghav Chamadiya60dfe463f7d8
diff --git a/packages/server/src/repowise/server/routers/files.py b/packages/server/src/repowise/server/routers/files.py
index cbeb51726..ea8949c20 100644
--- a/packages/server/src/repowise/server/routers/files.py
+++ b/packages/server/src/repowise/server/routers/files.py
@@ -323,6 +323,8 @@ async def file_detail(
# onto HotspotResponse so the hotspots list does not carry a per-symbol
# map on every row; only this page has symbols to spend it on.
git["fix_symbol_counts"] = _json_or(git_meta.fix_symbol_counts_json, {})
+ # The blame owner's share of current lines, next to their commit share.
+ git["primary_owner_line_pct"] = git_meta.primary_owner_line_pct
git["agent"] = {
"agent_commit_count": git_meta.agent_commit_count or 0,
"agent_authored_pct": git_meta.agent_authored_pct,
diff --git a/packages/types/src/files.ts b/packages/types/src/files.ts
index 6fb6549a4..d829d5893 100644
--- a/packages/types/src/files.ts
+++ b/packages/types/src/files.ts
@@ -117,6 +117,9 @@ export interface FileDetailGit extends Hotspot {
co_change_partners: CoChangePartner[];
agent: FileAgentProvenance;
first_commit_at: string | null;
+ /** The primary (blame) owner's share of current lines, 0-1. Null without
+ * blame; `primary_owner_commit_pct` is the same person's share of commits. */
+ primary_owner_line_pct?: number | null;
/** `symbol_id` -> counted fixes that landed in it, over the same window as
* `prior_defect_count`. Approximate: symbol spans are current-tree while
* each fix's line ranges are numbered on its own parent commit. A symbol
diff --git a/packages/ui/__tests__/files/file-page-header.test.tsx b/packages/ui/__tests__/files/file-page-header.test.tsx
index f9ff74d0a..3e2038a1e 100644
--- a/packages/ui/__tests__/files/file-page-header.test.tsx
+++ b/packages/ui/__tests__/files/file-page-header.test.tsx
@@ -137,6 +137,37 @@ describe("FilePageHeader documentation door", () => {
});
});
+describe("FilePageHeader owner shares", () => {
+ function owned(git: Record<string, unknown>) {
+ return makeData({
+ git: { primary_owner: "Ada", commit_count_total: 40, ...git } as never,
+ });
+ }
+
+ it("labels the line share and the commit share apart", () => {
+ render(
+ <FilePageHeader
+ data={owned({ primary_owner_line_pct: 0.45, primary_owner_commit_pct: 0.6 })}
+ linkPrefix="/repos/r1"
+ />,
+ );
+ expect(
+ screen.getByText(/\(45% of current lines, 60% of commits\), across 40 commits\./),
+ ).toBeTruthy();
+ });
+
+ it("keeps the commit share alone when blame did not run", () => {
+ render(
+ <FilePageHeader
+ data={owned({ primary_owner_line_pct: null, primary_owner_commit_pct: 0.6 })}
+ linkPrefix="/repos/r1"
+ />,
+ );
+ expect(screen.getByText(/\(60% of commits\)/)).toBeTruthy();
+ expect(screen.queryByText(/current lines/)).toBeNull();
+ });
+});
+
describe("fileTabsFor", () => {
it("badges only what there is something to say about", () => {
const tabs = fileTabsFor(makeData());
diff --git a/packages/ui/__tests__/stats/stats-report.test.tsx b/packages/ui/__tests__/stats/stats-report.test.tsx
index 792c52757..738627d59 100644
--- a/packages/ui/__tests__/stats/stats-report.test.tsx
+++ b/packages/ui/__tests__/stats/stats-report.test.tsx
@@ -73,6 +73,17 @@ describe("StatsReport", () => {
expect(screen.getByText("70 lines of tests")).toBeInTheDocument();
});
+ it("counts merge commits apart from the commit total", () => {
+ const data = makeData();
+ render(<StatsReport data={{ ...data, origin: { ...data.origin, total_merge_commits: 312 } }} />);
+ expect(screen.getByText("plus 312 merges")).toBeInTheDocument();
+ });
+
+ it("says nothing about merges an older index did not count", () => {
+ render(<StatsReport data={makeData()} />);
+ expect(screen.queryByText(/merges?$/)).not.toBeInTheDocument();
+ });
+
it("names the commit window when it is not the whole history", () => {
render(<StatsReport data={makeData()} />);
expect(screen.getByText(/Drawn from the latest 6 of 5,000 commits/)).toBeInTheDocument();
diff --git a/packages/ui/src/files/file-page-header.tsx b/packages/ui/src/files/file-page-header.tsx
index c434634e2..177a034ba 100644
--- a/packages/ui/src/files/file-page-header.tsx
+++ b/packages/ui/src/files/file-page-header.tsx
@@ -140,7 +140,14 @@ function FileProse({
const deduction = data.health.breakdown?.total_deduction;
const owner = data.git?.primary_owner;
const ownerPct = data.git?.primary_owner_commit_pct;
+ const ownerLinePct = data.git?.primary_owner_line_pct;
const commits = data.git?.commit_count_total ?? 0;
+ // Two different shares of the same person: blame lines they hold today, and
+ // the commits they made. Each is labelled, since they often disagree.
+ const ownerShares = [
+ ownerLinePct != null ? `${Math.round(ownerLinePct * 100)}% of current lines` : null,
+ ownerPct != null ? `${Math.round(ownerPct * 100)}% of commits` : null,
+ ].filter(Boolean);
return (
<>
@@ -162,7 +169,7 @@ function FileProse({
>
{owner}
</A>
- {ownerPct != null && ` (${Math.round(ownerPct * 100)}% of commits)`}
+ {ownerShares.length > 0 && ` (${ownerShares.join(", ")})`}
{commits > 0 && `, across ${formatNumber(commits)} commit${commits === 1 ? "" : "s"}`}.
</p>
)}
diff --git a/packages/ui/src/stats/stats-report.tsx b/packages/ui/src/stats/stats-report.tsx
index e3ec67613..af3602cf1 100644
--- a/packages/ui/src/stats/stats-report.tsx
+++ b/packages/ui/src/stats/stats-report.tsx
@@ -81,7 +81,16 @@ function identityStats(data: StatsHighlights): RibbonStat[] {
sub: languageMix(data),
hint: "Programming languages by file count. Data and markup formats such as JSON, YAML and Markdown are not counted.",
},
- { label: "Commits", value: formatNumber(origin.total_commits) },
+ {
+ label: "Commits",
+ value: formatNumber(origin.total_commits),
+ ...(origin.total_merge_commits != null
+ ? {
+ sub: `plus ${formatNumber(origin.total_merge_commits)} merge${origin.total_merge_commits === 1 ? "" : "s"}`,
+ hint: "Non-merge commits reachable from HEAD. Merge commits are counted apart.",
+ }
+ : {}),
+ },
];
}
diff --git a/tests/unit/server/test_git.py b/tests/unit/server/test_git.py
index ce964e14a..dd258fe17 100644
--- a/tests/unit/server/test_git.py
+++ b/tests/unit/server/test_git.py
@@ -46,6 +46,7 @@ async def _insert_git_metadata(session_factory, repo_id: str) -> None:
commit_count_capped=True,
original_path="src/old_main.py",
fix_symbol_counts_json=json.dumps({"src/main.py::run": 3}),
+ primary_owner_line_pct=0.45,
)
await crud.upsert_git_metadata(
session,
@@ -103,12 +104,16 @@ async def test_file_detail_carries_symbol_fix_counts(client: AsyncClient, app) -
assert resp.status_code == 200, resp.text
git = resp.json()["git"]
assert git["fix_symbol_counts"] == {"src/main.py::run": 3}
+ # The blame line share rides beside the commit share, never in its place.
+ assert git["primary_owner_line_pct"] == 0.45
+ assert git["primary_owner_commit_pct"] == 0.6
# A file the rollup never touched reports an empty map, not a missing key,
# so a consumer can index into it unconditionally.
resp = await client.get(f"/api/repos/{repo['id']}/files/src/utils.py")
assert resp.status_code == 200
assert resp.json()["git"]["fix_symbol_counts"] == {}
+ assert resp.json()["git"]["primary_owner_line_pct"] is None
@pytest.mark.asyncio