mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-13 15:13:07 +00:00
Decisão (2026-08-21): o GitHub passa a ser a fonte única — main, branches, PRs, CI via Actions E tracker de Issues. O Forgejo deixa de ser canal ativo (git.e issue tracker congelados pós-convergência). Data: 17 issues migradas do Forgejo para o GitHub (frontmatter id/depends/ serializes/priority/model preservados, labels mapeados, comment de origem em cada uma; tabela Forgejo→GitHub registrada). Tooling: github-api.mjs estendido com a camada de issues/labels/comments/ close/workflow-dispatch/contents (mesmo shape normalizado do forgejo-api); 18 scripts trocam o transporte forgejo-api → github-api; forgejo-api.mjs e seu teste (961 linhas) removidos; teste githubApi.unit.spec.ts novo (7 casos); issue-transition-on-merge.mjs renomeado e reapontado. Flips pós-merge: issue-done e plan-issue-ready agora usam o GITHUB_TOKEN com issues:write no repo (sem FORGEJO_API_TOKEN) e fecham/flipam Issues no GitHub. Docs: AGENTS.md, AGENT-OPS.md e skills do fluxo vivo (work-issue, plan-issue, project-status, capture-review-debts, worktree-next-issue, agent-work-issue) apontam o tracker para github.com/fsolla/teqo/issues. Gates: tsc/lint/format/knip/cycles/unit 2416 verdes.
93 lines
3.5 KiB
JavaScript
93 lines
3.5 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.
|
|
*
|
|
* OPS76: the PR lives on GitHub and the ISSUE TRACKER is on GitHub too. The
|
|
* workflow passes the PR body via the `PR_BODY` env (from the GitHub event
|
|
* payload) and the script flips Issues on the GitHub API (repo GITHUB_TOKEN,
|
|
* `issues: write`). Without PR_BODY the script falls back to reading the PR
|
|
* from the GitHub API (the manual `workflow_dispatch` recovery path).
|
|
*
|
|
* OPS61: a failed flip exits 1 — the flip is the whole purpose of this
|
|
* workflow, and the 403 era proved that a swallowed error ends the job
|
|
* "success" while the status labels lie. Sibling issues are still attempted
|
|
* (the loop does not abort), but the job goes red so the breakage is visible.
|
|
*
|
|
* node scripts/issue-transition-on-merge.mjs --pr <N>
|
|
* PR_BODY='Closes #97' node scripts/issue-transition-on-merge.mjs --pr <N>
|
|
*/
|
|
|
|
import { createApi } from './lib/github-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 bodyFromEnv = process.env.PR_BODY
|
|
const pr =
|
|
typeof bodyFromEnv === 'string'
|
|
? { merged: true, body: bodyFromEnv }
|
|
: 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)
|
|
}
|
|
|
|
let flipFailed = false
|
|
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\` + Issue fechada. Deploy de produção é manual (workflow_dispatch no GitHub Actions) — ver docs/AGENT-OPS.md.`,
|
|
)
|
|
// OPS76: o PR e a Issue vivem no GitHub; o close nativo por keyword
|
|
// (`Closes #N`) só acontece para issues AINDA abertas citadas no body —
|
|
// o flip de labels (done/in-prod/remover in-progress) é explícito aqui.
|
|
await api.closeIssue(number)
|
|
console.log(`[forgejo-issue-transition] #${number}: done + in-prod + fechada`)
|
|
} catch (error) {
|
|
flipFailed = true
|
|
console.error(
|
|
`[forgejo-issue-transition] #${number}: FLIP FALHOU — ${error instanceof Error ? error.message : error}`,
|
|
)
|
|
}
|
|
}
|
|
if (flipFailed) {
|
|
console.error(
|
|
`[forgejo-issue-transition] PR #${prNumber}: ${numbers.length} Issue(s) citada(s), pelo menos 1 flip falhou — os labels de status podem estar mentindo.`,
|
|
)
|
|
process.exit(1)
|
|
}
|