(params: {
db: WorkerDb;
gitTokenService: GitTokenService;
owner: SecurityReviewOwner;
runId: string;
trigger?: 'scheduled' | 'manual';
actor?: { id: string; email?: string | null; name?: string | null };
repoFullName?: string;
notificationMaterializationEnabled?: boolean;
})
| 1602 | let pending = 0; |
| 1603 | let cancelled = 0; |
| 1604 | for (const row of result.rows) { |
| 1605 | if (row.status === 'pending') pending = row.count; |
| 1606 | if (row.status === 'cancelled') cancelled = row.count; |
| 1607 | } |
| 1608 | return { pending, cancelled }; |
| 1609 | } |
| 1610 | |
| 1611 | type AutoAnalysisQueueSyncResult = { |
| 1612 | enqueueCount: number; |
| 1613 | eligibleCount: number; |
| 1614 | boundarySkipCount: number; |
| 1615 | unknownSeverityCount: number; |
| 1616 | }; |
| 1617 | |
| 1618 | const AUTO_ANALYSIS_REOPEN_REQUEUE_CAP = 2; |
| 1619 | export function isFindingEligibleForAutoAnalysis(params: { |
| 1620 | findingCreatedAt: string; |
| 1621 | findingStatus: string; |
| 1622 | severity: string | null; |
| 1623 | ownerAutoAnalysisEnabledAt: string | null; |
| 1624 | isAgentEnabled: boolean; |
| 1625 | autoAnalysisEnabled: boolean; |
| 1626 | autoAnalysisMinSeverity: AutoAnalysisMinSeverity; |
| 1627 | autoAnalysisIncludeExisting?: boolean; |
| 1628 | }): { eligible: boolean; severityRank: number } { |
| 1629 | const decision = decideAutoAnalysisEligibility({ |
| 1630 | findingCreatedAt: params.findingCreatedAt, |
| 1631 | findingStatus: params.findingStatus, |
| 1632 | findingSeverity: params.severity, |
| 1633 | autoAnalysisEnabledAt: params.ownerAutoAnalysisEnabledAt, |
| 1634 | isAgentEnabled: params.isAgentEnabled, |
| 1635 | autoAnalysisEnabled: params.autoAnalysisEnabled, |
| 1636 | autoAnalysisMinSeverity: params.autoAnalysisMinSeverity, |
| 1637 | autoAnalysisIncludeExisting: params.autoAnalysisIncludeExisting, |
| 1638 | }); |
| 1639 | |
| 1640 | return { eligible: decision.eligible, severityRank: decision.severityRank }; |
| 1641 | } |
| 1642 | |
| 1643 | export async function syncAutoAnalysisQueueForFinding( |
| 1644 | db: WorkerDb, |
| 1645 | params: { |
| 1646 | owner: SecurityReviewOwner; |
| 1647 | findingId: string; |
| 1648 | findingCreatedAt: string; |
| 1649 | previousStatus: SecurityFindingStatus | null; |
| 1650 | currentStatus: SecurityFindingStatus; |
| 1651 | severity: string | null; |
| 1652 | isAgentEnabled: boolean; |
| 1653 | autoAnalysisEnabled: boolean; |
| 1654 | autoAnalysisMinSeverity: AutoAnalysisMinSeverity; |
| 1655 | ownerAutoAnalysisEnabledAt: string | null; |
| 1656 | autoAnalysisIncludeExisting?: boolean; |
| 1657 | } |
| 1658 | ): Promise<AutoAnalysisQueueSyncResult> { |
| 1659 | const decision = decideAutoAnalysisEligibility({ |
| 1660 | findingCreatedAt: params.findingCreatedAt, |
| 1661 | findingStatus: params.currentStatus, |
no test coverage detected