From 70f523ffb01bbdc49e42dd59f4b2644f4389f447 Mon Sep 17 00:00:00 2001 From: gemini-cli-robot Date: Tue, 28 Apr 2026 16:07:32 +0000 Subject: [PATCH] fix(bot): refactor open_issues and open_prs to use GraphQL This change refactors the `open_issues.ts` and `open_prs.ts` metric scripts to use the GitHub GraphQL API instead of the `gh` CLI's list commands with hardcoded limits. **Why it is recommended:** The previous implementation used `gh issue list --limit 1000`, which caused the metrics to cap at 1000 items. As the repository now has approximately 2400 open issues, the metrics were reporting inaccurate data, hiding the true scale of the backlog and potentially misleading repository health analysis. **Expected metric improvement:** The `open_issues` and `open_prs` metrics will now report accurate total counts, regardless of the 1000-item CLI limit. This will result in an immediate correction of the `open_issues` metric from 1000 to approximately 2400. **Productivity Impact:** Accurate metrics enable better data-backed decisions regarding maintainer workload and triage prioritization. --- .../metrics/scripts/open_issues.ts | 23 +++++++++++++------ .../metrics/scripts/open_prs.ts | 23 +++++++++++++------ 2 files changed, 32 insertions(+), 14 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..0683e5a72b 100644 --- a/tools/gemini-cli-bot/metrics/scripts/open_issues.ts +++ b/tools/gemini-cli-bot/metrics/scripts/open_issues.ts @@ -4,16 +4,25 @@ * SPDX-License-Identifier: Apache-2.0 */ +import { GITHUB_OWNER, GITHUB_REPO } from '../types.js'; import { execSync } from 'node:child_process'; try { - const count = execSync( - 'gh issue list --state open --limit 1000 --json number --jq length', - { - encoding: 'utf-8', - }, - ).trim(); - console.log(`open_issues,${count}`); + const query = ` + query($owner: String!, $repo: String!) { + repository(owner: $owner, name: $repo) { + issues(states: OPEN) { + totalCount + } + } + } + `; + 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; + console.log(`open_issues,${data.issues.totalCount}`); } catch { // Fallback if gh fails or no issues found console.log('open_issues,0'); diff --git a/tools/gemini-cli-bot/metrics/scripts/open_prs.ts b/tools/gemini-cli-bot/metrics/scripts/open_prs.ts index 35819ef0f9..666a243cd9 100644 --- a/tools/gemini-cli-bot/metrics/scripts/open_prs.ts +++ b/tools/gemini-cli-bot/metrics/scripts/open_prs.ts @@ -4,16 +4,25 @@ * SPDX-License-Identifier: Apache-2.0 */ +import { GITHUB_OWNER, GITHUB_REPO } from '../types.js'; import { execSync } from 'node:child_process'; try { - const count = execSync( - 'gh pr list --state open --limit 1000 --json number --jq length', - { - encoding: 'utf-8', - }, - ).trim(); - console.log(`open_prs,${count}`); + const query = ` + query($owner: String!, $repo: String!) { + repository(owner: $owner, name: $repo) { + pullRequests(states: OPEN) { + totalCount + } + } + } + `; + 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; + console.log(`open_prs,${data.pullRequests.totalCount}`); } catch { // Fallback if gh fails or no PRs found console.log('open_prs,0');