mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-17 05:20:23 -07:00
6ec068c2ab
Fix Metrics History Retention & Accuracy This PR addresses several issues identified in the repository's metrics collection and analysis pipeline: 1. **Increased History Retention**: Increased the rolling window in `metrics/index.ts` from 100 rows to 5000 rows. The previous limit was too small (holding only ~1.5 runs of data), which prevented meaningful delta calculations. 2. **Restored Backlog Age Metric**: Re-introduced `backlog_age.ts` to calculate the average age of the oldest 100 open issues. This provides visibility into backlog stagnation. 3. **Enhanced Throughput Accuracy**: Updated `throughput.ts` to distinguish between items **authored** by maintainers and items **processed** (merged/closed) by maintainers. This gives a more accurate measure of maintainer velocity. 4. **Added Bottleneck Analysis**: Introduced `bottlenecks.ts` to sample open PRs and identify if they are likely waiting on a maintainer review or an author's response. These changes will significantly improve the "Brain's" ability to identify trends and bottlenecks in the repository workflow. # Impact - More accurate 7-day and 30-day deltas for all metrics. - Better visibility into maintainer workload and backlog health. - Data-driven identification of whether bottlenecks are due to maintainer capacity or author responsiveness.
75 lines
2.0 KiB
TypeScript
75 lines
2.0 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2026 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
import { GITHUB_OWNER, GITHUB_REPO } from '../types.js';
|
|
import { execSync } from 'node:child_process';
|
|
|
|
try {
|
|
const query = `
|
|
query($owner: String!, $repo: String!) {
|
|
repository(owner: $owner, name: $repo) {
|
|
pullRequests(states: OPEN, last: 50) {
|
|
nodes {
|
|
author { login }
|
|
timelineItems(last: 10, itemTypes: [ISSUE_COMMENT, PULL_REQUEST_REVIEW, PULL_REQUEST_REVIEW_COMMENT]) {
|
|
nodes {
|
|
... on IssueComment { author { login } createdAt }
|
|
... on PullRequestReview { author { login } createdAt }
|
|
... on PullRequestReviewComment { author { login } createdAt }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
`;
|
|
const output = execSync(
|
|
`gh api graphql -F owner=${GITHUB_OWNER} -F repo=${GITHUB_REPO} -f query='${query}'`,
|
|
{ encoding: 'utf-8' },
|
|
);
|
|
const data = JSON.parse(output).data.repository;
|
|
const prs = data.pullRequests.nodes;
|
|
|
|
let waitingOnMaintainer = 0;
|
|
let waitingOnAuthor = 0;
|
|
|
|
for (const pr of prs) {
|
|
const author = pr.author?.login;
|
|
if (!author) continue;
|
|
|
|
const items = pr.timelineItems.nodes as {
|
|
author: { login: string };
|
|
createdAt: string;
|
|
}[];
|
|
if (items.length === 0) {
|
|
waitingOnMaintainer++;
|
|
continue;
|
|
}
|
|
|
|
// Sort by createdAt just in case
|
|
items.sort(
|
|
(a, b) =>
|
|
new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime(),
|
|
);
|
|
const lastItem = items[items.length - 1];
|
|
const lastActor = lastItem.author?.login;
|
|
|
|
if (lastActor === author) {
|
|
waitingOnMaintainer++;
|
|
} else {
|
|
waitingOnAuthor++;
|
|
}
|
|
}
|
|
|
|
process.stdout.write(
|
|
`prs_waiting_on_maintainer_sample,${waitingOnMaintainer}\n`,
|
|
);
|
|
process.stdout.write(`prs_waiting_on_author_sample,${waitingOnAuthor}\n`);
|
|
} catch (err) {
|
|
process.stderr.write(err instanceof Error ? err.message : String(err));
|
|
process.exit(1);
|
|
}
|