-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlib.js
71 lines (63 loc) · 1.97 KB
/
lib.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
// content of context: https://developer.github.com/v3/activity/events/types/
const github = require('@actions/github');
const getIssueNumber = () => {
const issue = github.context.payload.issue;
if (!issue) {
throw new Error("No issue provided");
}
return issue.number;
};
module.exports.getIssueNumber = getIssueNumber;
const getIssueFromContext = async (token) => {
let octocat = new github.GitHub(token);
const issueNum = getIssueNumber();
const repo = github.context.repo;
const issue = await octocat.issues.get({
owner: repo.owner,
repo: repo.repo,
issue_number: issueNum,
});
return issue;
};
module.exports.getIssueFromContext = getIssueFromContext;
const getIssueCommentFromContext = () => {
const comment = github.context.payload.comment;
if (!comment) {
throw new Error("No issue provided");
}
return comment;
}
module.exports.getIssueCommentFromContext = getIssueCommentFromContext;
const checkKeywords = (keywords, body) => {
const lowerBody = body.toLowerCase();
for(let k of keywords) {
if (lowerBody.toLowerCase().includes(k.toLowerCase())){
return true;
}
}
return false;
};
module.exports.checkKeywords = checkKeywords;
const createNewIssue = async (token, owner, repoName, title, body, assignees, labels, fromIssue) => {
const octokit = new github.GitHub(token);
if (!fromIssue) {
throw new Error('fromIssue is not provided')
}
if (typeof body === 'string' && body !== '') {
body = body + `\n\ncopiedFrom: ${fromIssue}`;
}else {
body = `copiedFrom: ${fromIssue}`
}
const res = await octokit.issues.create(
{
owner: owner,
repo: repoName,
title: title,
body: body,
assignees: assignees,
labels: labels,
}
);
return [res.id, res.number].join(':');
};
module.exports.createNewIssue = createNewIssue;