mirror of
https://github.com/stablyai/orca.git
synced 2026-11-13 09:27:29 +00:00
Main went red right away on the full main-push runs. Reverting to the previous PR-only checks.
This reverts commit a7ae68fc6f.
34 lines
1.1 KiB
JavaScript
34 lines
1.1 KiB
JavaScript
import { execFileSync } from 'node:child_process'
|
||
import process from 'node:process'
|
||
import { pathToFileURL } from 'node:url'
|
||
|
||
export function selectPullRequestDiffBase(requestedBase, headParents, eventName) {
|
||
if (eventName === 'pull_request' && headParents.length >= 2) {
|
||
return headParents[0]
|
||
}
|
||
return requestedBase
|
||
}
|
||
|
||
export function resolvePullRequestDiffBase(
|
||
root,
|
||
requestedBase,
|
||
eventName = process.env.GITHUB_EVENT_NAME
|
||
) {
|
||
const [, ...headParents] = execFileSync('git', ['rev-list', '--parents', '-n', '1', 'HEAD'], {
|
||
cwd: root,
|
||
encoding: 'utf8'
|
||
})
|
||
.trim()
|
||
.split(/\s+/)
|
||
return selectPullRequestDiffBase(requestedBase, headParents, eventName)
|
||
}
|
||
|
||
// Print shared gate’s resolved base so workflow shell gates can use merge-ref HEAD^1 instead of requiring full history for payload merge-base.
|
||
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
||
const resolved = resolvePullRequestDiffBase(process.cwd(), process.argv[2])
|
||
if (!resolved) {
|
||
throw new Error('No diff base: pass the pull request base SHA, or run on a merge ref.')
|
||
}
|
||
process.stdout.write(`${resolved}\n`)
|
||
}
|