-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.ts
62 lines (56 loc) · 1.67 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
57
58
59
60
61
62
import * as core from '@actions/core'
import * as github from '@actions/github'
const token: string = core.getInput('token')
const labels: string[] = JSON.parse(core.getInput('labels'))
const skipSec: Number = parseInt(core.getInput('skip_hour')) * 60 * 60
const repoOwner: string = github.context.repo.owner
const repo: string = github.context.repo.repo
function pullRequests(repoOwner:string, repo:string ) {
let client = github.getOctokit(core.getInput('token'))
let resp = client.rest.pulls.list({
owner: repoOwner,
repo: repo,
}).catch(
e => {
core.setFailed(e.message)
}
)
return resp
}
function filterLabel(labels ,target: string[]):boolean{
let labelname = labels.map((label) => {
return label.name
})
let filterdLabels = labelname.filter(
label => target.indexOf(label) != -1
)
if ( filterdLabels.length == target.length) {
return true
} else {
return false
}
}
function filterTime(pull ,target: number):boolean{
const createdAt = Date.parse(pull.created_at)
const gapSec = Math.round((target - createdAt) / 1000)
if ( gapSec > skipSec ) {
return true
}
return false
}
function setOutput(pull){
let output = ''
for (const p of pull) {
output = output + p.title + "\\n" + p.html_url + "\\n---\\n"
}
output = output.slice(0,-7) //最後の"\\n---\\n"を削除
core.setOutput('pulls', output)
}
const now = Date.now()
const prom = pullRequests(repoOwner,repo)
prom.then((pulls: any) => {
let claim = pulls.data.filter(
p => filterLabel(p.labels, labels) && filterTime(p ,now)
)
setOutput(claim)
})