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.
This commit is contained in:
gemini-cli-robot
2026-04-28 16:07:32 +00:00
parent c17400b830
commit 70f523ffb0
2 changed files with 32 additions and 14 deletions
@@ -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');
@@ -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');