forked from juliangruber/find-pull-request-action
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
33 lines (26 loc) · 808 Bytes
/
index.js
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
'use strict'
const core = require('@actions/core')
const { GitHub, context } = require('@actions/github')
const main = async () => {
const token = core.getInput('github-token')
const branch = core.getInput('branch')
const base = core.getInput('base')
const query = {
...context.repo,
state: 'open'
}
if (branch) {
query.head =
branch.indexOf(':') === -1 ? `${context.repo.owner}:${branch}` : branch
}
if (base) {
query.base = base
}
const octokit = new GitHub(token)
const res = await octokit.pulls.list(query)
const pr = res.data.length && res.data[0]
core.debug(`pr: ${JSON.stringify(pr, null, 2)}`)
core.setOutput('number', pr ? pr.number : '')
core.setOutput('head-sha', pr ? pr.head.sha : '')
}
main().catch(err => core.setFailed(err.message))