feat(optimizer): improve process scripts to address stuck issues and stale PRs

This commit is contained in:
Christian Gunderman
2026-04-21 16:29:32 -07:00
parent 9d1ed876cc
commit 15da1a26cf
11 changed files with 294 additions and 0 deletions
@@ -0,0 +1,23 @@
import { execSync } from 'node:child_process';
try {
const repoInfo = execSync('gh repo view --json nameWithOwner', { encoding: 'utf-8' });
const repo = JSON.parse(repoInfo).nameWithOwner;
const [owner, name] = repo.split('/');
const query = `query($endCursor: String) { repository(owner: "${owner}", name: "${name}") { pullRequests(states: MERGED, first: 100, after: $endCursor) { nodes { authorAssociation } pageInfo { hasNextPage endCursor } } } }`;
const command = `gh api graphql --paginate -f query='${query}' --jq '.data.repository.pullRequests.nodes[] | select(.authorAssociation != "MEMBER" and .authorAssociation != "OWNER" and .authorAssociation != "COLLABORATOR") | .authorAssociation' | wc -l`;
const output = execSync(command, { encoding: 'utf-8' });
const completedCommunityPrs = parseInt(output.trim(), 10);
process.stdout.write(JSON.stringify({
metric: 'completed_community_prs',
value: completedCommunityPrs,
timestamp: new Date().toISOString()
}));
} catch (err) {
process.stderr.write(err.message);
process.exit(1);
}
@@ -0,0 +1,21 @@
import { execSync } from 'node:child_process';
try {
const repoInfo = execSync('gh repo view --json nameWithOwner', { encoding: 'utf-8' });
const repo = JSON.parse(repoInfo).nameWithOwner;
const output = execSync(`gh search prs --state open --repo ${repo} --limit 1000 --json authorAssociation`, { encoding: 'utf-8' });
const prs = JSON.parse(output);
const communityPrs = prs.filter(pr =>
pr.authorAssociation !== 'MEMBER' &&
pr.authorAssociation !== 'OWNER' &&
pr.authorAssociation !== 'COLLABORATOR'
);
process.stdout.write(JSON.stringify({
metric: 'open_community_prs',
value: communityPrs.length,
timestamp: new Date().toISOString()
}));
} catch (err) {
process.stderr.write(err.message);
process.exit(1);
}