teqo-backup/scripts/configure-branch-protection.mjs
Francisco Solla 4626a2ea06 chore(ci): remove o migration-lock — deadlock de CI com PRs de schema paralelos (checks passa a ser o único required)
O check falhava quando >1 PR aberto tocava src/migrations/ + payload-types.ts,
deadlockando AMBOS os PRs (9 de 13 runs de CI falhos desde 11/08). A validação
real da cadeia de migrations já roda em todo PR e na main: pnpm migrate +
test:int (incl. campaignMigrationReconciliation). Pool mantém a serialização
de spawn de issues needs:migration via countOpenSchemaPrs.
2026-08-12 13:42:05 -03:00

55 lines
1.5 KiB
JavaScript

/**
* One-time / drift repair for branch protection (main-only).
*
* pnpm configure:branch-protection # apply
* pnpm configure:branch-protection -- --dry-run
*
* main: required checks `checks`, strict=false, 0 reviews.
* Feature PRs auto-merge when that context is green.
* (migration-lock removed 2026-08-12 — see ci-pr.yml header.)
*/
import { execFileSync } from 'node:child_process'
import { parseArgs } from './lib/agent-github.mjs'
const { flags } = parseArgs(process.argv.slice(2), new Set())
const dryRun = flags['dry-run'] === true
const repo = execFileSync(
'gh',
['repo', 'view', '--json', 'nameWithOwner', '-q', '.nameWithOwner'],
{
encoding: 'utf8',
},
).trim()
const ghApiJson = (method, path, body) => {
const payload = JSON.stringify(body)
if (dryRun) {
console.log(`[dry-run] gh api -X ${method} ${path} ${payload}`)
return
}
execFileSync('gh', ['api', '-X', method, path, '--input', '-'], {
input: payload,
stdio: ['pipe', 'inherit', 'inherit'],
})
}
console.log(`[configure:branch-protection] repo ${repo}${dryRun ? ' (dry-run)' : ''}`)
ghApiJson('PUT', `repos/${repo}/branches/main/protection`, {
required_status_checks: {
strict: false,
contexts: ['checks'],
},
enforce_admins: false,
required_pull_request_reviews: {
required_approving_review_count: 0,
},
restrictions: null,
allow_force_pushes: false,
allow_deletions: false,
})
console.log('[configure:branch-protection] done (main: checks, strict=false, 0 reviews).')