#!/usr/bin/env -S npx --yes tsx
// =============================================================================
// list_prs_missing_ci_checks.ts — Open PRs with zero approvals and no CI
//                                  checks reported at all
//
// Part of: .opencode/skills/auto-agents-system/scripts/
//
// Delegates to list_prs.ts with hard-coded filters.
//
// Returns all OPEN pull requests that:
//   • have zero active review approvals                  (approvals_count == 0)
//     i.e. no reviewer's most recent non-dismissed review is APPROVED.
//   • have no CI checks reported                         (ci_status == 'unknown')
//     i.e. the Forgejo combined commit-status endpoint returned an empty or
//     unknown state — no status checks have been created for the PR's head
//     commit at all.
//   • do NOT have unaddressed REQUEST_CHANGES reviews
//     (hasUnaddressedRequestChanges == false)
//     i.e. either no reviewer has requested changes, or every REQUEST_CHANGES
//     review has been followed by at least one new commit from the author.
//     This excludes PRs where the author still needs to respond to reviewer
//     feedback (those are the implementation supervisor's responsibility).
//
// PRs in this bucket have no CI pipeline running or configured for them.
// Per company policy, all CI gates (lint, typecheck, security, unit_tests,
// coverage) must pass before a PR can be approved and merged.  The appropriate
// review action for these PRs is a lightweight REQUEST_CHANGES review that
// flags the missing CI checks and requests the author ensure CI is configured
// and passing before a full code review will be conducted.
//
// This bucket intentionally combines two review states (no active
// REQUEST_CHANGES and addressed REQUEST_CHANGES) because the CI-unknown
// condition supersedes the review state — regardless of prior review history,
// the absence of CI is the primary blocker and the review comment will focus
// on that.
//
// Hard-coded filters (not configurable):
//   state:                         'open'      only open PRs are considered
//   ciStatus:                      ['unknown']  no CI checks reported
//   maxApprovals:                  0           no active approvals from any reviewer
//   hasUnaddressedRequestChanges:  false       excludes PRs waiting for author
//                                              response to reviewer feedback
//
// USAGE:
//   list_prs_missing_ci_checks.ts --url URL --pat TOKEN --owner OWNER --repo REPO
//
// OUTPUT (stdout): JSON array — same schema as list_prs.ts
// DEPENDENCIES: Node.js >= 18 (native fetch), npx tsx (for TypeScript execution)
// =============================================================================
import { listPRs, parseConnectionArgs } from './list_prs.ts';

async function main(): Promise<void> {
  const config = parseConnectionArgs(process.argv);
  const prs    = await listPRs(config, {
    state:                        'open',
    ciStatus:                     ['unknown'],
    maxApprovals:                 0,
    hasUnaddressedRequestChanges: false,
  });
  process.stdout.write(JSON.stringify(prs, null, 2) + '\n');
}

main().catch((err: unknown) => {
  process.stderr.write(`ERROR: ${err instanceof Error ? err.message : String(err)}\n`);
  process.exit(1);
});
