-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
64 lines (56 loc) · 1.81 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
const core = require("@actions/core");
const github = require("@actions/github");
const {ZonedDateTime, Duration} = require("@js-joda/core");
async function run() {
try {
const token = core.getInput("token");
const repository = core.getInput("repository");
let minNumberOfDays = parseInt(core.getInput("minNumberOfDays"));
let maxNumberOfDays = parseInt(core.getInput("maxNumberOfDays"));
// Backward compatibility: if lastUpdatedBefore && lastUpdatedAfter not provided, then use days
if (!minNumberOfDays) {
minNumberOfDays = parseInt(core.getInput("days"));
maxNumberOfDays = 2 * minNumberOfDays;
}
const octokit = github.getOctokit(token);
const now = ZonedDateTime.now();
const splitRepository = repository.split("/");
if (
splitRepository.length !== 2 ||
!splitRepository[0] ||
!splitRepository[1]
) {
throw new Error(
`Invalid repository '${qualifiedRepository}'. Expected format {owner}/{repo}.`
);
}
const repo = {owner: splitRepository[0], repo: splitRepository[1]};
const pulls = await octokit.paginate(
octokit.rest.pulls.list,
{...repo, state: "open"},
(response) =>
response.data
.filter(
(pr) =>
Duration.between(
ZonedDateTime.parse(pr.updated_at),
now
).toDays() > minNumberOfDays &&
Duration.between(
ZonedDateTime.parse(pr.updated_at),
now
).toDays() <= maxNumberOfDays
)
.map((pr) => ({
ref: pr.head.ref,
sha: pr.head.sha,
title: pr.title,
url: pr.html_url,
}))
);
core.setOutput("pulls", pulls);
} catch (error) {
core.setFailed(error.message);
}
}
run();