forked from DavidAnson/markdownlint-cli2-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
markdownlint-cli2-action.js
69 lines (64 loc) · 1.41 KB
/
markdownlint-cli2-action.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
// @ts-check
"use strict";
const core = require("@actions/core");
const {"main": markdownlintCli2} = require("markdownlint-cli2");
const logMessage = core.info;
const logError = (error) => {
// eslint-disable-next-line init-declarations
let annotation;
const match = error.match(/^([^:]+):(\d+)(?::(\d+))?\s(\S+)\s(.+)$/u);
if (match) {
const [
,
file,
startLineString,
startColumnString,
,
title
] = match;
const startLine = Number(startLineString);
annotation = {
title,
file,
startLine
};
if (startColumnString) {
// @ts-ignore
annotation.startColumn = Number(startColumnString);
}
}
core.error(error, annotation);
};
const argv =
core.getInput("globs").
split("\n").
filter(String);
const parameters = {
argv,
logMessage,
logError
};
let invoke = true;
const command = core.getInput("command");
switch (command) {
case "":
// Default behavior
break;
case "config":
parameters.name = "markdownlint-cli2-config";
break;
case "fix":
parameters.name = "markdownlint-cli2-fix";
parameters.fixDefault = true;
break;
default:
core.setFailed(`Unsupported command: ${command}`);
invoke = false;
break;
}
if (invoke) {
markdownlintCli2(parameters).then(
(code) => code && core.setFailed(`Failed with exit code: ${code}`),
(error) => core.setFailed(`Failed due to error: ${error}`)
);
}