iara-pwa/scripts/forgejo-issue-transition.mjs
Francisco Solla e2eccc5741
Some checks failed
Agent PR Ready + auto-merge / ready-automerge (pull_request) Failing after 4s
CI / checks (pull_request) Failing after 4s
CI / deploy (pull_request) Has been skipped
fluxo de agente tipo teqo: scripts worktree/issue/agent, skills, CI com e2e só no CI, labels e branch protection
- scripts/ portados do teqo e adaptados (sem DB — SPA): worktree (next/plan/new/kill,
  claim + branch <code>-<slug> + bun install), issue, agent:{claim,register,ready,
  file-miss,status}, pr (cria PR + auto-merge sem gh), transitions de CI
- config por projeto em .forgejo/worktree.env (FORGEJO_REPOSITORY, WORKTREES_ROOT)
  + roteador global de terminal em ~/.config/shell/worktree.sh (escopo por git rev-parse)
- .opencode/commands e .agents/skills (plan-issue, work-issue, capture-review-debts,
  worktree-next-issue, code-simplification) + AGENTS.md com o workflow
- CI Forgejo Actions unificado: checks (lint+build+e2e) em PR e main; deploy
  gated; issue-done / plan-issue-ready / agent-pr-automerge workflows
- Playwright: config + 2 specs smoke (settings→chat, ws reconnect) — e2e só no CI
- package.json: aliases worktree/issue/agent:*/pr + gate + test:e2e
2026-08-17 21:16:12 -03:00

67 lines
2.2 KiB
JavaScript

/**
* Plain-Node CLI (no pnpm) — on merge to main, flip Issues cited as
* `Closes #N` / `Fixes #N` in the PR body to `done` + `in-prod` and comment.
* Replacement for the `gh issue edit/comment` loop of issue-done-on-main-merge.
* The PR body comes from the API (Forgejo's PR webhook payload is not relied
* on), so the workflow only needs the PR number.
*
* node scripts/forgejo-issue-transition.mjs --pr <N>
*/
import { createApi } from './lib/forgejo-api.mjs'
const parseArgs = (argv) => {
const flags = {}
for (let index = 2; index < argv.length; index += 1) {
const arg = argv[index]
if (arg.startsWith('--')) {
const name = arg.slice(2)
const next = argv[index + 1]
flags[name] = typeof next === 'string' && !next.startsWith('--') ? next : true
if (typeof next === 'string' && !next.startsWith('--')) index += 1
}
}
return flags
}
const flags = parseArgs(process.argv)
const prNumber = Number(flags.pr)
if (!Number.isInteger(prNumber) || prNumber <= 0) {
console.error('Usage: node scripts/forgejo-issue-transition.mjs --pr <N>')
process.exit(1)
}
const api = createApi({})
const pr = await api.getPullRequest(prNumber)
if (!pr) {
console.error(`[forgejo-issue-transition] PR #${prNumber} não encontrada`)
process.exit(1)
}
if (!pr.merged) {
console.log(`[forgejo-issue-transition] PR #${prNumber} não mergeada — skip`)
process.exit(0)
}
const numbers = [
...new Set([...pr.body.matchAll(/(?:closes|fixes)\s+#(\d+)/gi)].map((match) => Number(match[1]))),
]
if (numbers.length === 0) {
console.log(`[forgejo-issue-transition] PR #${prNumber}: nenhum Closes/Fixes #N — nada a fazer`)
process.exit(0)
}
for (const number of numbers) {
try {
await api.setLabels(number, { add: ['done', 'in-prod'], remove: ['in-progress'] })
await api.addComment(
number,
`Merged em main via PR #${prNumber} — \`done\` + \`in-prod\`. Deploy de produção segue o verificador \`ci.yml\` (gated).`,
)
console.log(`[forgejo-issue-transition] #${number}: done + in-prod`)
} catch (error) {
console.log(
`[forgejo-issue-transition] #${number}: skip (${error instanceof Error ? error.message : error})`,
)
}
}