Skip to content

Commit 49d13cf

Browse files
Add filtering for low-quality install scripts and deprioritize specified patterns
1 parent 9efa03d commit 49d13cf

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

lib/sources.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,12 @@ const SCRIPT_DETECTION_CONFIG = {
545545
"brew update",
546546
"brew upgrade",
547547
"sed",
548+
"copy and paste",
549+
"```",
550+
"sudo rm",
551+
"http://",
552+
"open powershell",
553+
"open terminal",
548554
],
549555
SCORE_WEIGHTS: {
550556
HIGH: 10,
@@ -693,17 +699,22 @@ const findInstallScripts = async (owner, repo, body) => {
693699
const uniqueSnippets = [];
694700
const seenCodes = new Set();
695701

696-
snippets
697-
.sort((a, b) => b.score - a.score)
698-
.forEach((snippet) => {
699-
const normalizedCode = normalizeCode(snippet.code);
700-
if (!seenCodes.has(normalizedCode)) {
701-
seenCodes.add(normalizedCode);
702-
uniqueSnippets.push(snippet);
703-
}
704-
});
702+
const sortedSnippets = snippets
703+
.sort((a, b) => b.score - a.score);
704+
705+
sortedSnippets.forEach((snippet) => {
706+
const normalizedCode = normalizeCode(snippet.code);
707+
if (!seenCodes.has(normalizedCode)) {
708+
seenCodes.add(normalizedCode);
709+
uniqueSnippets.push(snippet);
710+
}
711+
});
712+
713+
// Filter out the lowest 50% scoring items
714+
const keepCount = Math.max(1, Math.ceil(uniqueSnippets.length / 2));
715+
const filteredSnippets = uniqueSnippets.slice(0, keepCount);
705716

706-
return uniqueSnippets;
717+
return filteredSnippets;
707718
};
708719

709720
const hasHighPriorityInstallScript = (installScripts) => {

0 commit comments

Comments
 (0)