Script updates.

This commit is contained in:
Christian Gunderman
2026-04-23 07:57:37 -07:00
parent 9109505145
commit 87485c87a4
8 changed files with 367 additions and 93 deletions
@@ -14,11 +14,11 @@ async function run() {
console.log(`Stale Manager starting for ${owner}/${repo}... (EXECUTE_ACTIONS=${EXECUTE_ACTIONS})`);
try {
// 1. Fetch open issues/PRs that might be stale
const query = `
// 1. Fetch open issues
const issueQuery = `
query($owner: String!, $repo: String!) {
repository(owner: $owner, name: $repo) {
issues(first: 200, states: OPEN, orderBy: {field: UPDATED_AT, direction: ASC}) {
issues(first: 1000, states: OPEN, orderBy: {field: UPDATED_AT, direction: ASC}) {
nodes {
number
authorAssociation
@@ -28,7 +28,22 @@ async function run() {
}
}
}
pullRequests(first: 200, states: OPEN, orderBy: {field: UPDATED_AT, direction: ASC}) {
}
}
`;
let issueOutput;
try {
issueOutput = execSync(`gh api graphql -F owner=${owner} -F repo=${repo} -f query='${issueQuery}'`, { encoding: 'utf-8', maxBuffer: 50 * 1024 * 1024 });
} catch (err) {
console.error('Failed to fetch issues from GitHub:', err);
process.exit(1);
}
// 2. Fetch open PRs
const prQuery = `
query($owner: String!, $repo: String!) {
repository(owner: $owner, name: $repo) {
pullRequests(first: 500, states: OPEN, orderBy: {field: UPDATED_AT, direction: ASC}) {
nodes {
number
authorAssociation
@@ -52,16 +67,17 @@ async function run() {
}
}
`;
let output;
let prOutput;
try {
output = execSync(`gh api graphql -F owner=${owner} -F repo=${repo} -f query='${query}'`, { encoding: 'utf-8', maxBuffer: 10 * 1024 * 1024 });
prOutput = execSync(`gh api graphql -F owner=${owner} -F repo=${repo} -f query='${prQuery}'`, { encoding: 'utf-8', maxBuffer: 50 * 1024 * 1024 });
} catch (err) {
console.error('Failed to fetch issues/PRs from GitHub:', err);
console.error('Failed to fetch PRs from GitHub:', err);
process.exit(1);
}
const data = JSON.parse(output).data.repository;
const items = [...data.issues.nodes.map(i => ({...i, type: 'issue'})), ...data.pullRequests.nodes.map(p => ({...p, type: 'pr'}))];
const issueData = JSON.parse(issueOutput).data.repository;
const prData = JSON.parse(prOutput).data.repository;
const items = [...issueData.issues.nodes.map(i => ({...i, type: 'issue'})), ...prData.pullRequests.nodes.map(p => ({...p, type: 'pr'}))];
const now = new Date();
const actions = [];
@@ -71,10 +87,23 @@ async function run() {
const daysSinceUpdate = (now.getTime() - updatedAt.getTime()) / (1000 * 60 * 60 * 24);
const isMaintainerOnly = item.labels.nodes.some(l => l.name === '🔒 maintainer only');
const isStale = item.labels.nodes.some(l => l.name === 'Stale');
const needsInfo = item.labels.nodes.some(l => l.name === 'status/needs-info');
const isCommunity = !['MEMBER', 'OWNER', 'COLLABORATOR'].includes(item.authorAssociation);
if (isMaintainerOnly) continue; // Maintainer issues have their own lifecycle
// Special handling for needs-info: mark stale faster
if (needsInfo && !isStale && daysSinceUpdate > 7) {
actions.push({
number: item.number,
target: item.type,
type: 'label',
label: 'Stale',
comment: `Hi! This ${item.type} was marked as 'status/needs-info' but has had no activity for 7 days. We are labeling it as 'Stale'. It will be closed in 14 days if no further activity occurs. Thank you!`
});
continue;
}
// Safeguard: Don't mark as stale if it's a PR ready for review (Maintainer bottleneck)
if (item.type === 'pr') {
const ciState = item.commits?.nodes[0]?.commit?.statusCheckRollup?.state;
@@ -124,14 +153,14 @@ async function run() {
const simulationMap = action.target === 'pr' ? prSimulationUpdates : issueSimulationUpdates;
if (action.type === 'label') {
execGh(`${cmdPrefix} edit ${action.number} --add-label "Stale"`, EXECUTE_ACTIONS);
simulationMap.set(action.number.toString(), { labels: 'Stale' });
await execGh(`${cmdPrefix} edit ${action.number} --add-label "${action.label}"`, EXECUTE_ACTIONS);
simulationMap.set(action.number.toString(), { labels: action.label });
}
if (action.comment) {
execGh(`${cmdPrefix} comment ${action.number} --body "${action.comment}"`, EXECUTE_ACTIONS);
await execGh(`${cmdPrefix} comment ${action.number} --body "${action.comment}"`, EXECUTE_ACTIONS);
}
if (action.type === 'close') {
execGh(`${cmdPrefix} close ${action.number}`, EXECUTE_ACTIONS);
await execGh(`${cmdPrefix} close ${action.number}`, EXECUTE_ACTIONS);
simulationMap.set(action.number.toString(), { state: 'CLOSED' });
}
} catch (err) {