-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
53 lines (41 loc) · 1.6 KB
/
index.ts
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
import * as core from "@actions/core";
import * as github from "@actions/github";
async function run() {
try {
core.debug("Starting PR Descrption length check");
const description = getPullRequestDescription();
const minLength = getMinimumLength();
core.debug(description);
core.debug(String(minLength));
const descriptionLength = description.length;
if (descriptionLength < minLength) {
const failureMessage = (minLength == 1)? "Pull Request Description must be provided": `Pull Request Description Must be at least ${minLength} characters long`;
core.error(failureMessage);
core.setFailed(failureMessage);
return;
}
core.info("Description Passed");
} catch (error) {
core.setFailed(error.message);
}
}
export function getMinimumLength() {
let length = 1;
const minimumLength = core.getInput("minLength", { required: false }).trim();
if (minimumLength && /^(\d+)$/.test(minimumLength)) {
length = Number(minimumLength);
}
if (minimumLength && !/^(\d+)$/.test(minimumLength)) {
throw new Error("minLength must be a positive number");
}
return length;
}
export function getPullRequestDescription() {
let pull_request = github.context.payload.pull_request;
core.debug(`Pull Request: ${JSON.stringify(github.context.payload.pull_request)}`);
if (pull_request == undefined || pull_request.body == undefined) {
throw new Error("This action should only be run with Pull Request Events");
}
return pull_request.body;
}
run()