Simplify scripts: unify bot detection, remove redundant API calls and TOCTOU checks

This commit is contained in:
BukeLy 2026-03-02 17:23:33 +08:00
parent fd9330c434
commit 7df8510bde
4 changed files with 11 additions and 99 deletions

View file

@ -92,13 +92,16 @@ async function fetchDuplicateIssues() {
return issues.filter(i => new Date(i.created_at) < cutoff);
}
function isBot(user) {
return user.type === 'Bot' || user.login.endsWith('[bot]') || user.login === 'github-actions';
}
/**
* Finds the bot's duplicate comment on an issue (contains "possible duplicate").
*/
function findDuplicateComment(comments) {
return comments.find(c =>
(c.user.type === 'Bot' || c.user.login === 'github-actions[bot]') &&
c.body.includes('possible duplicate')
isBot(c.user) && c.body.includes('possible duplicate')
);
}
@ -107,9 +110,7 @@ function findDuplicateComment(comments) {
*/
function hasHumanCommentAfter(comments, afterDate) {
return comments.some(c => {
if (c.user.type === 'Bot' || c.user.login.endsWith('[bot]') || c.user.login === 'github-actions') {
return false;
}
if (isBot(c.user)) return false;
return new Date(c.created_at) > afterDate;
});
}
@ -145,12 +146,6 @@ async function closeAsDuplicate(issueNumber) {
`/repos/${REPO_OWNER}/${REPO_NAME}/issues/${issueNumber}`,
{ state: 'closed', state_reason: 'completed' }
);
await githubRequest(
'POST',
`/repos/${REPO_OWNER}/${REPO_NAME}/issues/${issueNumber}/labels`,
{ labels: ['duplicate'] }
);
}
async function processIssue(issue) {