-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
index.js
74 lines (65 loc) · 1.95 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
'use strict'
const core = require('@actions/core')
const github = require('@actions/github')
const main = async () => {
const token = core.getInput('github-token')
const branch = core.getInput('branch')
const base = core.getInput('base')
const author = core.getInput('author')
const state = core.getInput('state')
const sort = core.getInput('sort')
const direction = core.getInput('direction')
const repoString = core.getInput('repo')
const labels = core.getInput('labels')
let repoObject
if (repoString) {
const [owner, repo] = repoString.split('/')
repoObject = { owner, repo }
} else {
repoObject = github.context.repo
}
const query = {
...repoObject,
state
}
if (branch) {
query.head =
branch.indexOf(':') === -1
? `${github.context.repo.owner}:${branch}`
: branch
}
if (base) {
query.base = base
}
if (sort) {
query.sort = sort
}
if (direction) {
query.direction = direction
}
const octokit = github.getOctokit(token)
const res = await octokit.rest.pulls.list(query)
let prs = res.data
if (author) {
prs = prs.filter(pr => pr.user.login === author)
}
if (labels) {
const labelNames = labels.split(',')
prs = prs.filter(pr => {
const prLabelNames = pr.labels.map(label => label.name)
return labelNames.every(label => prLabelNames.includes(label))
})
}
const pr = prs.length && prs[0]
core.debug(`pr: ${JSON.stringify(pr, null, 2)}`)
core.setOutput('number', pr ? pr.number : '')
core.setOutput('title', pr ? pr.title : '')
core.setOutput('url', pr ? pr.url : '')
core.setOutput('head-ref', pr ? pr.head.ref : '')
core.setOutput('head-sha', pr ? pr.head.sha : '')
core.setOutput('base-ref', pr ? pr.base.ref : '')
core.setOutput('base-sha', pr ? pr.base.sha : '')
core.setOutput('base-repo', pr ? pr.base.repo.full_name : '')
core.setOutput('state', pr ? pr.state : '')
}
main().catch(err => core.setFailed(err.message))