-
Notifications
You must be signed in to change notification settings - Fork 61.6k
/
Copy pathfind-past-built-pr.ts
50 lines (41 loc) · 1.27 KB
/
find-past-built-pr.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import got from 'got'
import { setOutput } from '@actions/core'
import github from './github.js'
import { getActionContext } from './action-context.js'
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 = 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 got('https://docs.github.com/_build')
const sha = r.body.trim()
if (!/[a-f0-9]{40}/.test(sha)) {
throw new Error(`Response body does not look like a SHA ('${r.body.slice(0, 100)}'...)`)
}
return sha
}
main()