-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.js
69 lines (56 loc) · 1.9 KB
/
run.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
const core = require("@actions/core");
const { getKeys } = require("./gpg");
const { createGitHubClient } = require("./github");
function getExpiredIssueTitle(email) {
return `blackbox key has expired: ${email}`;
}
function getExpiringIssueTitle(email) {
return `blackbox key expiring soon: ${email}`;
}
async function findOrCreateIssuesForKeys(githubClient, keys) {
const { repoId, issues } = await githubClient.getRepoData();
const expiredKeys = keys.filter((k) => k.status === "expired");
await Promise.all(
expiredKeys.map((key) => {
const expiredTitle = getExpiredIssueTitle(key.email);
const expiringTitle = getExpiringIssueTitle(key.email);
const expiredIssue = issues.find((issue) => issue.title === expiredTitle);
const expiringIssue = issues.find(
(issue) => issue.title === expiringTitle
);
if (expiredIssue) return null;
if (expiringIssue) {
return githubClient.updateIssueTitle(
expiringIssue.node_id,
expiredTitle
);
}
return githubClient.createIssue({ repoId, title: expiredTitle });
})
);
const expiringKeys = keys.filter((k) => k.status === "expiring");
await Promise.all(
expiringKeys.map((key) => {
const expiringTitle = getExpiringIssueTitle(key.email);
const expiringIssue = issues.find(
(issue) => issue.title === expiringTitle
);
if (expiringIssue) return null;
return githubClient.createIssue({ repoId, title: expiringTitle });
})
);
}
async function run() {
try {
const githubToken = core.getInput("github-token");
const repoName = core.getInput("repo-name");
const keyringDir = core.getInput("keyring-directory");
await findOrCreateIssuesForKeys(
createGitHubClient(githubToken, repoName),
await getKeys(keyringDir)
);
} catch (e) {
core.setFailed(e.message);
}
}
module.exports = { run };