mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2026-02-03 20:03:25 +01:00
Paginate search and lock issues silently
Replace single-page search with paginated queries (per_page=100) and iterate pages up to GitHub's 1000-result limit. Remove the hardcoded cutoffDate and the logic that added comments; instead lock issues/PRs directly with lock_reason='resolved'. Add logging for pages processed, skipped items, failures, and a total locked count. This makes the workflow scalable for large repositories and avoids posting automatic comments.
This commit is contained in:
73
.github/workflows/lock-issue.yaml
generated
vendored
73
.github/workflows/lock-issue.yaml
generated
vendored
@@ -18,7 +18,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
const daysBeforeLock = 3;
|
const daysBeforeLock = 3;
|
||||||
const cutoffDate = new Date('2026-01-27T00:00:00Z');
|
|
||||||
const lockDate = new Date();
|
const lockDate = new Date();
|
||||||
lockDate.setDate(lockDate.getDate() - daysBeforeLock);
|
lockDate.setDate(lockDate.getDate() - daysBeforeLock);
|
||||||
|
|
||||||
@@ -29,48 +28,48 @@ jobs:
|
|||||||
/dependabot/i
|
/dependabot/i
|
||||||
];
|
];
|
||||||
|
|
||||||
// Search for closed, unlocked issues older than 3 days
|
// Search for closed, unlocked issues older than 3 days (paginated)
|
||||||
const issues = await github.rest.search.issuesAndPullRequests({
|
let page = 1;
|
||||||
q: `repo:${context.repo.owner}/${context.repo.repo} is:closed is:unlocked updated:<${lockDate.toISOString().split('T')[0]}`,
|
let totalLocked = 0;
|
||||||
per_page: 50
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(`Found ${issues.data.items.length} issues/PRs to process`);
|
while (true) {
|
||||||
|
const issues = await github.rest.search.issuesAndPullRequests({
|
||||||
|
q: `repo:${context.repo.owner}/${context.repo.repo} is:closed is:unlocked updated:<${lockDate.toISOString().split('T')[0]}`,
|
||||||
|
per_page: 100,
|
||||||
|
page: page
|
||||||
|
});
|
||||||
|
|
||||||
for (const item of issues.data.items) {
|
if (issues.data.items.length === 0) break;
|
||||||
// Skip excluded items
|
|
||||||
const shouldExclude = excludePatterns.some(pattern => pattern.test(item.title));
|
|
||||||
if (shouldExclude) {
|
|
||||||
console.log(`Skipped #${item.number}: "${item.title}" (matches exclude pattern)`);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const createdAt = new Date(item.created_at);
|
console.log(`Processing page ${page} with ${issues.data.items.length} issues/PRs`);
|
||||||
const isNew = createdAt >= cutoffDate;
|
|
||||||
|
|
||||||
try {
|
for (const item of issues.data.items) {
|
||||||
// Add comment only for new issues (created after 2026-01-27)
|
// Skip excluded items
|
||||||
if (isNew) {
|
const shouldExclude = excludePatterns.some(pattern => pattern.test(item.title));
|
||||||
const comment = item.pull_request
|
if (shouldExclude) {
|
||||||
? 'This pull request has been automatically locked. Please open a new issue for related bugs.'
|
console.log(`Skipped #${item.number}: "${item.title}" (matches exclude pattern)`);
|
||||||
: 'This issue has been automatically locked. Please open a new issue for related bugs and reference this issue if needed.';
|
continue;
|
||||||
|
|
||||||
await github.rest.issues.createComment({
|
|
||||||
...context.repo,
|
|
||||||
issue_number: item.number,
|
|
||||||
body: comment
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lock the issue/PR
|
try {
|
||||||
await github.rest.issues.lock({
|
// Lock the issue/PR silently
|
||||||
...context.repo,
|
await github.rest.issues.lock({
|
||||||
issue_number: item.number,
|
...context.repo,
|
||||||
lock_reason: 'resolved'
|
issue_number: item.number,
|
||||||
});
|
lock_reason: 'resolved'
|
||||||
|
});
|
||||||
|
|
||||||
console.log(`Locked #${item.number} (${item.pull_request ? 'PR' : 'Issue'})`);
|
totalLocked++;
|
||||||
} catch (error) {
|
console.log(`Locked #${item.number} (${item.pull_request ? 'PR' : 'Issue'})`);
|
||||||
console.log(`Failed to lock #${item.number}: ${error.message}`);
|
} catch (error) {
|
||||||
|
console.log(`Failed to lock #${item.number}: ${error.message}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
page++;
|
||||||
|
|
||||||
|
// GitHub search API limit: max 1000 results
|
||||||
|
if (page > 10) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(`Total locked: ${totalLocked} issues/PRs`);
|
||||||
|
|||||||
Reference in New Issue
Block a user