iara-pwa/scripts/lib/github-pr-flow.mjs
Francisco Solla 8d4a944127 feat(ci): CI/PR no GitHub Actions — tracker de Issues permanece no Forgejo (Closes #17)
- .github/workflows: ci.yml (job único checks hosted), deploy.yml (verify
  hosted full → deploy self-hosted no homeserver), flips pós-merge via API
  (FORGEJO_API_TOKEN/PR_BODY, fail-loud), auto-merge nativo (GraphQL)
- scripts: github-api/pr-flow/branch-protection (plain Node zero-dep),
  pr.mjs reescrito (GitHub + auto-merge), configure-branch-protection,
  deploy-iara.sh (local, sem SSH, idempotente), forgejo-issue-transition
  com PR_BODY + fail-loud (I10 absorvida)
- AGENTS.md/runbook: seção CI GitHub, branch protection REAL em main,
  passos manuais do cutover
2026-08-19 23:06:23 -03:00

28 lines
No EOL
1.3 KiB
JavaScript

/**
* Pure decision logic for the GitHub PR auto-merge safety net
* (scripts/github-pr-automerge.mjs) and `bun run pr -- --automerge`
* (scripts/pr.mjs). Unit-tested in tests/unit/github-pr-flow.test.ts — the
* OPS57 (draft veto) / OPS64 (never merge on red CI) pins ported to the
* GitHub mechanism.
*
* GitHub's native auto-merge only fires with the required checks green, so
* the decision is reduced to: skip (non-main base, draft veto, already
* merged/closed) or arm auto-merge.
*
* Unlike the teqo OPS71 port, there is NO `cursor/*` mark-ready path: Iara
* has no draft-creating flow (`bun run pr` never drafts) — any draft is the
* actor's veto, always skipped.
*/
/**
* @param {object|null} pr - normalized PR from github-api (or null)
* @returns {{ action: 'skip' | 'enable-auto-merge', reason: string }}
*/
export const decideAutomergeAction = (pr) => {
if (!pr) return { action: 'skip', reason: 'pr-inexistente' }
if (pr.merged) return { action: 'skip', reason: 'ja-mergeada' }
if (pr.state !== 'OPEN') return { action: 'skip', reason: 'pr-nao-aberta' }
if (pr.base?.ref !== 'main') return { action: 'skip', reason: 'base-nao-main' }
if (pr.draft) return { action: 'skip', reason: 'draft-veto' }
return { action: 'enable-auto-merge', reason: 'ready' }
}