| | 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) { |
| | |
| | |
| | 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() |
| |
|