1
0
mirror of synced 2025-12-20 18:36:31 -05:00
Files
docs/src/workflows/find-past-built-pr.ts
2025-10-27 22:01:39 +00:00

53 lines
1.4 KiB
TypeScript

import { setOutput } from '@actions/core'
import github from './github'
import { getActionContext } from './action-context'
import { octoSecondaryRatelimitRetry } from './secondary-ratelimit-retry'
async function main() {
const sha = await getBuiltSHA()
console.log({ sha })
const actionContext = getActionContext()
const { owner, repo } = actionContext
const octokit = github()
let number = ''
const q = `${sha} repo:"${owner}/${repo}"`
const { data } = await octoSecondaryRatelimitRetry(() =>
octokit.rest.search.issuesAndPullRequests({ q }),
)
for (const issue of data.items) {
console.log('ID:', issue.id)
console.log('Number:', issue.number)
console.log('URL:', issue.html_url)
number = String(issue.number)
if (number) {
// We've found the issue (pull request), but before we accept
// this `number`, check that the issue isn't locked.
if (issue.locked) {
number = ''
}
break
}
}
setOutput('number', number)
}
async function getBuiltSHA() {
const r = await fetch('https://docs.github.com/_build')
if (!r.ok) {
throw new Error(`HTTP ${r.status}: ${r.statusText}`)
}
const body = await r.text()
const sha = body.trim()
if (!/[a-f0-9]{40}/.test(sha)) {
throw new Error(`Response body does not look like a SHA ('${body.slice(0, 100)}'...)`)
}
return sha
}
main()