mirror of
https://github.com/stablyai/orca.git
synced 2026-10-31 00:57:45 +00:00
* Require exact-commit PR checks before agent merges * Give full PR checks a unique required status context * Validate required context ownership on every pull request
28 lines
1.0 KiB
JavaScript
28 lines
1.0 KiB
JavaScript
import { readdirSync, readFileSync } from 'node:fs'
|
|
import { join } from 'node:path'
|
|
import { pathToFileURL } from 'node:url'
|
|
|
|
export function verifyRequiredPrContext(parseYaml) {
|
|
const directory = '.github/workflows'
|
|
const providers = readdirSync(directory)
|
|
.filter((file) => /\.ya?ml$/.test(file))
|
|
.flatMap((file) => {
|
|
const workflow = parseYaml(readFileSync(join(directory, file), 'utf8'))
|
|
return Object.entries(workflow.jobs)
|
|
.filter(([id, job]) => (job.name ?? id) === 'PR checks passed')
|
|
.map(([id]) => `${file}:${id}`)
|
|
})
|
|
if (providers.length !== 1 || providers[0] !== 'pr.yml:verify') {
|
|
throw new Error(`Required PR context must belong only to pr.yml:verify; found ${providers}`)
|
|
}
|
|
}
|
|
|
|
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
const yaml = globalThis.Bun?.YAML
|
|
if (!yaml) {
|
|
throw new Error('Run workflow context validation with the pinned Bun runtime.')
|
|
}
|
|
verifyRequiredPrContext(yaml.parse)
|
|
console.log('Required PR check context verified.')
|
|
}
|