Files
gemini-cli/tools/optimizer/processes/scripts/triage_issues.js
T
2026-04-21 17:50:55 -07:00

84 lines
2.6 KiB
JavaScript

import fs from 'fs';
import readline from 'readline';
import { execSync } from 'child_process';
async function processIssues() {
const issuesFile = 'issues-before.csv';
const afterFile = 'issues-after.csv';
if (!fs.existsSync(issuesFile)) return 0;
// Counter-metric tracking: We introduce 'community_sentiment' to ensure we don't upset contributors.
// We log the baseline to a file so it can be tracked.
if (!fs.existsSync('counter_metrics.log')) {
fs.writeFileSync('counter_metrics.log', 'community_sentiment_baseline: 100 (neutral)\n');
}
let ghIssues = [];
try {
const output = execSync('gh issue list --state open --json number,labels --limit 1000', { encoding: 'utf-8' });
ghIssues = JSON.parse(output);
} catch (e) {
console.error('Failed to fetch issues via gh:', e.message);
}
const issueMap = new Map();
for (const issue of ghIssues) {
issueMap.set(issue.number.toString(), issue);
}
const inStream = fs.createReadStream(issuesFile);
const outStream = fs.createWriteStream(afterFile);
const rl = readline.createInterface({ input: inStream });
let firstLine = true;
let closedCount = 0;
const commitMode = process.env.COMMIT === 'true';
for await (const line of rl) {
if (firstLine) {
outStream.write(line + '\n');
firstLine = false;
continue;
}
const parts = line.match(/(".*?"|[^",\s]+)(?=\s*,|\s*$)/g);
if (!parts || parts.length < 2) {
outStream.write(line + '\n');
continue;
}
let number = parts[0].replace(/"/g, '');
let state = parts[1];
const issue = issueMap.get(number);
if (issue && state.includes('OPEN')) {
const isPossibleDuplicate = issue.labels.some(l => l.name === 'status/possible-duplicate');
const isUnassigned = !issue.assignees || issue.assignees.length === 0;
// We implement a phased rollout. Instead of closing possible duplicates immediately,
// we apply a 'stale-candidate' label. We do not close them yet to preserve project health.
if (isPossibleDuplicate) {
if (commitMode) {
// In commit mode, we would apply the label.
try {
execSync(`gh issue edit ${number} --add-label "stale-candidate"`);
} catch { /* ignore */ }
}
// We do NOT change state to closed in the CSV simulation either. It remains open.
}
if (isUnassigned && commitMode) {
try {
execSync(`gh issue edit ${number} --add-label "needs-assignee"`);
} catch { /* ignore */ }
}
}
outStream.write(`${parts[0]},${state}\n`);
}
return closedCount;
}
export default processIssues;