Skip to content

Commit b8a60d1

Browse files
[ci] build
1 parent 7415a42 commit b8a60d1

2 files changed

Lines changed: 38 additions & 6 deletions

File tree

dist/detect-agent.mjs

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -633,9 +633,25 @@ function m({ createdAt: e, reposCount: t, accountName: n, events: r }) {
633633
}
634634
};
635635
}
636+
function h(e) {
637+
return e ? e === `organic` ? {
638+
label: `Organic activity`,
639+
description: `No automation signals detected in the analyzed events.`
640+
} : e === `mixed` ? {
641+
label: `Mixed activity`,
642+
description: `Activity patterns show a mix of organic and automated signals.`
643+
} : {
644+
label: `Automation signals`,
645+
description: `Activity patterns show signs of automation.`
646+
} : {
647+
label: `Analysis unavailable`,
648+
description: `Classification is not available for this account.`
649+
};
650+
}
636651
//#endregion
637652
//#region src/detect-agent.ts
638653
const jsonMode = process.argv.includes("--json");
654+
const log = jsonMode ? console.error : console.log;
639655
const { GITHUB_TOKEN, PR_AUTHOR } = process.env;
640656
if (!GITHUB_TOKEN || !PR_AUTHOR) throw new Error(`Missing input.\nRequired environment variables: GITHUB_TOKEN, PR_AUTHOR\n`);
641657
const headers = {
@@ -660,21 +676,37 @@ const { classification, score, flags } = m({
660676
createdAt: user.created_at,
661677
events
662678
});
663-
const isAgent = classification === "automation";
664-
const comment = `### 🤖 Automated account detected
679+
let verifiedAutomationList = [];
680+
try {
681+
const response = await fetch(`https://api.github.com/repos/matteogabriele/agentscan/contents/data/verified-automations-list.json`, { headers });
682+
if (!response.ok) throw new Error(`Failed to fetch verified automations list: ${response.status}`);
683+
const data = await response.json();
684+
if ("content" in data) {
685+
const content = Buffer.from(data.content, "base64").toString("utf-8");
686+
verifiedAutomationList = JSON.parse(content);
687+
}
688+
} catch (error) {
689+
log("Could not fetch verified automations list");
690+
}
691+
const details = !!verifiedAutomationList.find((account) => account.username === PR_AUTHOR) ? {
692+
label: "Flagged by community",
693+
description: "This account has been flagged as potentially automated by the community."
694+
} : h(classification);
695+
const flagsTable = flags.map((f) => `| ${f.label} | ${f.points > 0 ? "+" : ""}${f.points} | ${f.detail} |`).join("\n");
696+
const comment = `### ${details.label}
665697
666-
[@${PR_AUTHOR}](https://github.com/${PR_AUTHOR}) has been flagged as a likely automated account.
698+
[@${PR_AUTHOR}](https://github.com/${PR_AUTHOR}) ${details.description}
667699
668700
**Classification:** \`${classification}\` (score: ${score})
669701
670702
| Signal | Points | Detail |
671703
|--------|--------|--------|
672-
${flags.map((f) => `| ${f.label} | ${f.points > 0 ? "+" : ""}${f.points} | ${f.detail} |`).join("\n")}
704+
${flagsTable}
673705
674706
<sub>Analyzed ${events.length} public events via <a href="https://www.npmx.dev/package/voight-kampff-test">voight-kampff-test</a></sub>`;
675-
const log = jsonMode ? console.error : console.log;
676707
log(`Classification: ${classification} (score: ${score})`);
677708
for (const flag of flags) log(` [${flag.points > 0 ? "+" : ""}${flag.points}] ${flag.label}: ${flag.detail}`);
709+
const isAgent = classification === "automation";
678710
if (jsonMode) console.log(JSON.stringify({
679711
classification,
680712
score,

0 commit comments

Comments
 (0)