ci/github-script/prepare: run biome

This will be added to treefmt in a different commit / PR.
This commit is contained in:
Wolfgang Walther
2025-08-20 15:10:02 +02:00
parent c787c66de6
commit f5d3e43368

View File

@@ -1,46 +1,58 @@
module.exports = async function ({ github, context, core }) { module.exports = async ({ github, context, core }) => {
for (const retryInterval of [5, 10, 20, 40, 80]) { for (const retryInterval of [5, 10, 20, 40, 80]) {
console.log("Checking whether the pull request can be merged...") console.log('Checking whether the pull request can be merged...')
const prInfo = (await github.rest.pulls.get({ const prInfo = (
owner: context.repo.owner, await github.rest.pulls.get({
repo: context.repo.repo, owner: context.repo.owner,
pull_number: context.payload.pull_request.number repo: context.repo.repo,
})).data pull_number: context.payload.pull_request.number,
})
).data
if (prInfo.state != 'open') throw new Error ("PR is not open anymore.") if (prInfo.state !== 'open') throw new Error('PR is not open anymore.')
if (prInfo.mergeable == null) { if (prInfo.mergeable == null) {
console.log(`GitHub is still computing whether this PR can be merged, waiting ${retryInterval} seconds before trying again...`) console.log(
await new Promise(resolve => setTimeout(resolve, retryInterval * 1000)) `GitHub is still computing whether this PR can be merged, waiting ${retryInterval} seconds before trying again...`,
)
await new Promise((resolve) => setTimeout(resolve, retryInterval * 1000))
continue continue
} }
let mergedSha, targetSha let mergedSha, targetSha
if (prInfo.mergeable) { if (prInfo.mergeable) {
console.log("The PR can be merged.") console.log('The PR can be merged.')
mergedSha = prInfo.merge_commit_sha mergedSha = prInfo.merge_commit_sha
targetSha = (await github.rest.repos.getCommit({ targetSha = (
owner: context.repo.owner, await github.rest.repos.getCommit({
repo: context.repo.repo, owner: context.repo.owner,
ref: prInfo.merge_commit_sha repo: context.repo.repo,
})).data.parents[0].sha ref: prInfo.merge_commit_sha,
})
).data.parents[0].sha
} else { } else {
console.log("The PR has a merge conflict.") console.log('The PR has a merge conflict.')
mergedSha = prInfo.head.sha mergedSha = prInfo.head.sha
targetSha = (await github.rest.repos.compareCommitsWithBasehead({ targetSha = (
owner: context.repo.owner, await github.rest.repos.compareCommitsWithBasehead({
repo: context.repo.repo, owner: context.repo.owner,
basehead: `${prInfo.base.sha}...${prInfo.head.sha}` repo: context.repo.repo,
})).data.merge_base_commit.sha basehead: `${prInfo.base.sha}...${prInfo.head.sha}`,
})
).data.merge_base_commit.sha
} }
console.log(`Checking the commits:\nmerged:${mergedSha}\ntarget:${targetSha}`) console.log(
`Checking the commits:\nmerged:${mergedSha}\ntarget:${targetSha}`,
)
core.setOutput('mergedSha', mergedSha) core.setOutput('mergedSha', mergedSha)
core.setOutput('targetSha', targetSha) core.setOutput('targetSha', targetSha)
return return
} }
throw new Error("Not retrying anymore. It's likely that GitHub is having internal issues: check https://www.githubstatus.com.") throw new Error(
"Not retrying anymore. It's likely that GitHub is having internal issues: check https://www.githubstatus.com.",
)
} }