chore(issues): Mark stale issues

This commit is contained in:
jyxjjj
2025-11-12 13:42:43 +08:00
parent 91076058ac
commit b45c260468

View File

@@ -2,7 +2,7 @@ name: Mark stale issues
on:
schedule:
- cron: '0 0 * * *' # daily at 00:00 UTC
- cron: "0 0/2 * * *"
workflow_dispatch:
permissions:
@@ -12,49 +12,16 @@ jobs:
mark-stale:
runs-on: ubuntu-latest
steps:
- name: Mark issues stale after 90 days inactivity
uses: actions/github-script@v7
- name: Mark issues stale using actions/stale
uses: actions/stale@v10
with:
script: |
const days = 90;
const cutoff = new Date(Date.now() - days * 24 * 60 * 60 * 1000);
const labelName = 'stale';
const whitelist = ['WIP', 'has-parent', 'collection', 'Announcement'];
const staleComment = `This issue has been automatically marked as stale because it hasn't had recent activity for ${days} days. If you'd like to keep it open, please reply and the label will be removed.`;
// Ensure the stale label exists; create if missing
try {
await github.rest.issues.getLabel({ ...context.repo, name: labelName });
} catch (err) {
if (err.status === 404) {
await github.rest.issues.createLabel({ ...context.repo, name: labelName, color: 'cccccc', description: 'Marked as stale after inactivity' });
} else {
throw err;
}
}
// List open issues (not PRs) and paginate
const issues = await github.paginate(github.rest.issues.listForRepo, {
...context.repo,
state: 'open',
per_page: 100
});
for (const issue of issues) {
// Skip PRs
if (issue.pull_request) continue;
// Skip locked issues
if (issue.locked) continue;
// Skip if already labeled stale
const labels = (issue.labels || []).map(l => (typeof l === 'string' ? l : l.name));
// Skip if contains any whitelist label
if (labels.some(l => whitelist.includes(l))) continue;
if (labels.includes(labelName)) continue;
const updated = new Date(issue.updated_at || issue.created_at);
if (updated < cutoff) {
// Add stale label and comment
await github.rest.issues.addLabels({ ...context.repo, issue_number: issue.number, labels: [labelName] });
await github.rest.issues.createComment({ ...context.repo, issue_number: issue.number, body: staleComment });
console.log(`Marked #${issue.number} as stale`);
}
}
days-before-stale: 90
days-before-close: 90
days-before-pr-stale: -1
days-before-pr-close: -1
stale-issue-message: "This issue has been automatically marked as stale because it hasn't had recent activity for 90 days. If you'd like to keep it open, please reply and the label will be removed."
stale-issue-label: "stale"
close-issue-message: "This issue has been automatically closed due to inactivity for 90 days after being marked as stale. If you believe this was done in error, please feel free to reopen the issue or contact the maintainers."
any-of-labels: "bug"
exempt-labels: "WIP,has-parent,collection,Announcement"
operations-per-run: 100