-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (54 loc) · 1.67 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
"use strict";
exports.__esModule = true;
var core = require("@actions/core");
var github = require("@actions/github");
var token = core.getInput('token');
var labels = JSON.parse(core.getInput('labels'));
var skipSec = parseInt(core.getInput('skip_hour')) * 60 * 60;
var repoOwner = github.context.repo.owner;
var repo = github.context.repo.repo;
function pullRequests(repoOwner, repo) {
var pr = new github.GitHub(token);
var resp = pr.pulls.list({
owner: repoOwner,
repo: repo
})["catch"](function (e) {
console.log(e.message);
});
return resp;
}
function filterLabel(labels, target) {
var labelname = labels.map(function (label) {
return label.name;
});
var filterdLabels = labelname.filter(function (label) { return target.indexOf(label) != -1; });
if (filterdLabels.length == target.length) {
return true;
}
else {
return false;
}
}
function filterTime(pull, target) {
var createdAt = Date.parse(pull.created_at);
var gapSec = Math.round((target - createdAt) / 1000);
if (gapSec > skipSec) {
return true;
}
return false;
}
function setOutput(pull) {
var output = '';
for (var _i = 0, pull_1 = pull; _i < pull_1.length; _i++) {
var p = pull_1[_i];
output = output + p.title + "\\n" + p.html_url + "\\n---\\n";
}
output = output.slice(0, -7); //最後の"\\n---\\n"を削除
core.setOutput('pulls', output);
}
var now = Date.now();
var prom = pullRequests(repoOwner, repo);
prom.then(function (pulls) {
var claim = pulls.data.filter(function (p) { return filterLabel(p.labels, labels) && filterTime(p, now); });
setOutput(claim);
});