From ee347a76fdc4b465d7d17d90edc4542f04f64a38 Mon Sep 17 00:00:00 2001 From: gemini-cli-robot Date: Mon, 27 Apr 2026 20:05:40 +0000 Subject: [PATCH] # Fix: 1000-issue metric cap for accurate repository health tracking ## Description This change updates the `open_issues` and `open_prs` metric scripts to use the GitHub Search API (`gh api search/issues`) instead of `gh issue list` and `gh pr list`. ## Why it is recommended The current scripts use a hardcoded `--limit 1000`, which caused the `open_issues` metric to cap at 1000. This masks the true size of the repository backlog and prevents accurate analysis of maintenance burden and throughput. ## Expected Metric Improvement - `open_issues` and `open_prs` will now reflect the true total counts, even if they exceed 1000. - This will allow for more accurate delta calculations and historical trends. ## Impact This is a low-risk change that significantly improves data quality for the Gemini CLI Bot Brain, enabling better-informed decisions regarding stale issue management and contributor latency. --- .../metrics/scripts/open_issues.ts | 23 +++++++++++++++---- .../metrics/scripts/open_prs.ts | 23 +++++++++++++++---- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/tools/gemini-cli-bot/metrics/scripts/open_issues.ts b/tools/gemini-cli-bot/metrics/scripts/open_issues.ts index 4996ec7ce4..875d75c499 100644 --- a/tools/gemini-cli-bot/metrics/scripts/open_issues.ts +++ b/tools/gemini-cli-bot/metrics/scripts/open_issues.ts @@ -5,16 +5,29 @@ */ import { execSync } from 'node:child_process'; +import { GITHUB_OWNER, GITHUB_REPO, type MetricOutput } from '../types.js'; try { + const repo = process.env.GITHUB_REPOSITORY || `${GITHUB_OWNER}/${GITHUB_REPO}`; const count = execSync( - 'gh issue list --state open --limit 1000 --json number --jq length', + `gh api "search/issues?q=repo:${repo}+is:issue+is:open" --jq .total_count`, { encoding: 'utf-8', }, ).trim(); - console.log(`open_issues,${count}`); -} catch { - // Fallback if gh fails or no issues found - console.log('open_issues,0'); + + const metric: MetricOutput = { + metric: 'open_issues', + value: parseInt(count, 10) || 0, + timestamp: new Date().toISOString(), + }; + process.stdout.write(JSON.stringify(metric) + '\n'); +} catch (err) { + process.stderr.write(`Error fetching open issues: ${err instanceof Error ? err.message : String(err)}\n`); + const fallback: MetricOutput = { + metric: 'open_issues', + value: 0, + timestamp: new Date().toISOString(), + }; + process.stdout.write(JSON.stringify(fallback) + '\n'); } diff --git a/tools/gemini-cli-bot/metrics/scripts/open_prs.ts b/tools/gemini-cli-bot/metrics/scripts/open_prs.ts index 35819ef0f9..e04bad7bd6 100644 --- a/tools/gemini-cli-bot/metrics/scripts/open_prs.ts +++ b/tools/gemini-cli-bot/metrics/scripts/open_prs.ts @@ -5,16 +5,29 @@ */ import { execSync } from 'node:child_process'; +import { GITHUB_OWNER, GITHUB_REPO, type MetricOutput } from '../types.js'; try { + const repo = process.env.GITHUB_REPOSITORY || `${GITHUB_OWNER}/${GITHUB_REPO}`; const count = execSync( - 'gh pr list --state open --limit 1000 --json number --jq length', + `gh api "search/issues?q=repo:${repo}+is:pr+is:open" --jq .total_count`, { encoding: 'utf-8', }, ).trim(); - console.log(`open_prs,${count}`); -} catch { - // Fallback if gh fails or no PRs found - console.log('open_prs,0'); + + const metric: MetricOutput = { + metric: 'open_prs', + value: parseInt(count, 10) || 0, + timestamp: new Date().toISOString(), + }; + process.stdout.write(JSON.stringify(metric) + '\n'); +} catch (err) { + process.stderr.write(`Error fetching open PRs: ${err instanceof Error ? err.message : String(err)}\n`); + const fallback: MetricOutput = { + metric: 'open_prs', + value: 0, + timestamp: new Date().toISOString(), + }; + process.stdout.write(JSON.stringify(fallback) + '\n'); }