( suspects: BotSuspect[], now: Date, logger: Logger, )
| 405 | } |
| 406 | |
| 407 | async function enrichWithGithubAge( |
| 408 | suspects: BotSuspect[], |
| 409 | now: Date, |
| 410 | logger: Logger, |
| 411 | ): Promise<void> { |
| 412 | const targets = suspects.filter((s) => s.githubId) |
| 413 | if (targets.length === 0) return |
| 414 | |
| 415 | const queue = [...targets] |
| 416 | let failures = 0 |
| 417 | let rateLimited = 0 |
| 418 | |
| 419 | const worker = async () => { |
| 420 | while (queue.length > 0) { |
| 421 | const s = queue.shift() |
| 422 | if (!s?.githubId) continue |
| 423 | const result = await fetchGithubCreatedAt(s.githubId) |
| 424 | if (result === 'rate-limited') { |
| 425 | rateLimited++ |
| 426 | continue |
| 427 | } |
| 428 | if (result === null) { |
| 429 | failures++ |
| 430 | continue |
| 431 | } |
| 432 | const ageDays = (now.getTime() - result.getTime()) / 86400_000 |
| 433 | s.githubAgeDays = ageDays |
| 434 | if (ageDays < 7) { |
| 435 | s.flags.push(`gh-new<7d:${ageDays.toFixed(1)}d`) |
| 436 | s.score += 60 |
| 437 | } else if (ageDays < 30) { |
| 438 | s.flags.push(`gh-new<30d:${ageDays.toFixed(0)}d`) |
| 439 | s.score += 30 |
| 440 | } else if (ageDays < 90) { |
| 441 | s.flags.push(`gh-new<90d:${ageDays.toFixed(0)}d`) |
| 442 | s.score += 10 |
| 443 | } else if (ageDays >= 365 * 3) { |
| 444 | // Established GitHub accounts are a strong counter-signal: buying |
| 445 | // a 3+ year old account is rare at our abuse scale. Subtract enough |
| 446 | // to pull a day-1 heavy user (new-acct<1d + very-heavy = 90) back |
| 447 | // below the high-tier threshold without fully clearing them — |
| 448 | // genuine 24/7 patterns still surface. |
| 449 | s.counterSignals.push(`gh-established:${(ageDays / 365).toFixed(1)}y`) |
| 450 | s.score -= 40 |
| 451 | } else if (ageDays >= 365) { |
| 452 | s.counterSignals.push(`gh-established:${(ageDays / 365).toFixed(1)}y`) |
| 453 | s.score -= 20 |
| 454 | } |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | await Promise.all( |
| 459 | Array.from({ length: Math.min(GITHUB_API_CONCURRENCY, targets.length) }, () => |
| 460 | worker(), |
| 461 | ), |
| 462 | ) |
| 463 | |
| 464 | if (failures > 0 || rateLimited > 0) { |
no test coverage detected