-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
56 lines (50 loc) · 1.6 KB
/
index.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
51
52
53
54
55
56
import * as core from '@actions/core'
import * as github from '@actions/github'
import Octokit = require('@octokit/rest')
const token: string = core.getInput('token')
const base: string = core.getInput('base')
const labels: string[] = JSON.parse(core.getInput('labels'))
const repoOwner: string = github.context.repo.owner
const repo: string = github.context.repo.repo
function pullRequests(repoOwner:string, repo:string ):Promise<Octokit.Response<Octokit.PullsListResponse>> {
let pr = new github.GitHub(token)
let resp = pr.pulls.list({
owner: repoOwner,
repo: repo,
base: base,
state: open,
}).catch(
e => {
core.debug("::debug::" + e.message)
}
) as Promise<Octokit.Response<Octokit.PullsListResponse>>
return resp
}
function filterLabel(labels: Octokit.PullsListResponseItemLabelsItem[],target: string[]):boolean{
let labelNames = labels.map((label) => {
return label.name
})
core.debug("::debug::" + "Found PR with label names: " + labelNames)
for (const label of target) {
if (!labelNames.includes(label)) {
return false;
}
}
return true;
}
function setOutput(pull:Octokit.PullsListResponseItem[]){
let output = ''
for (const p of pull) {
output = output + p.head.ref + " "
}
core.debug("::debug::" + "Found PRs: " + output)
core.setOutput('pulls', output)
}
const now = Date.now()
const prom = pullRequests(repoOwner,repo)
prom.then((pulls) => {
let claim = pulls.data.filter(
p => filterLabel(p.labels, labels)
)
setOutput(claim)
})