-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
79 lines (67 loc) · 2.01 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* Github dependencies
*/
const core = require("@actions/core");
const github = require("@actions/github");
/**
* Custom dependencies
*/
const WordPressPlugin = require("./classes/wordpress-plugin");
const issueAlreadyExists = require("./helpers/github-issue-exists");
const getRandomAssignee = require("./helpers/get-random-assignee");
const getSupportTemplate = require("./templates/create-new-support");
/**
* External dependencies
*/
const { isEmpty } = require("lodash");
/**
* Main action.
*/
async function main() {
try {
const token = core.getInput("github-token"); // github token.
const pluginSlug = core.getInput("plugin-slug");
const possibleAssignees = core.getInput("random-assignees");
const repo = core.getInput("repo-name");
const owner = "CakeWP"; // TODO: currently hardcoded.
const octokit = github.getOctokit(token);
const plugin = new WordPressPlugin(pluginSlug);
const unresolvedSupports = await plugin.getUnresolvedPluginSupport();
if (isEmpty(unresolvedSupports)) {
core.setOutput(
"status",
"👏 No unresolved support found on the Wordpress Repository."
);
return true;
}
// Creating a new issue for each unresolved support.
for (const support of unresolvedSupports) {
const issueTitle = support.title;
const issueExists = await issueAlreadyExists(
octokit,
issueTitle,
owner,
repo
);
if (issueExists) {
continue;
}
const supportDetails = await plugin.getSupportDetails(
support.supportLink
);
// Creating a new issue.
const createdIssue = await octokit.rest.issues.create({
owner,
title: issueTitle,
labels: ["wordpress-support", "needs-testing"],
repo,
assignee: getRandomAssignee(possibleAssignees),
body: getSupportTemplate(support, supportDetails, pluginSlug),
});
}
} catch (error) {
console.error(error);
core.setFailed(error.message);
}
}
main();