@security-alert/sarif-to-markdown 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/sarif-to-markdown.d.ts +8 -0
- package/lib/sarif-to-markdown.js +53 -19
- package/lib/sarif-to-markdown.js.map +1 -1
- package/module/sarif-to-markdown.d.ts +8 -0
- package/module/sarif-to-markdown.js +51 -18
- package/module/sarif-to-markdown.js.map +1 -1
- package/package.json +6 -14
- package/lib/sarif-formatter.d.ts +0 -24
- package/lib/sarif-formatter.js +0 -56
- package/lib/sarif-formatter.js.map +0 -1
|
@@ -25,6 +25,14 @@ export declare type sarifFormatterOptions = {
|
|
|
25
25
|
* Base path
|
|
26
26
|
*/
|
|
27
27
|
sourceRoot: string;
|
|
28
|
+
/**
|
|
29
|
+
* Details of the rules in the comment or not, this might make the comment too big for Github
|
|
30
|
+
*/
|
|
31
|
+
details?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Should the markdown include suppressed findings, defaults to true
|
|
34
|
+
*/
|
|
35
|
+
suppressedResults?: boolean;
|
|
28
36
|
};
|
|
29
37
|
declare type sarifToMarkdownResult = {
|
|
30
38
|
title?: string;
|
package/lib/sarif-to-markdown.js
CHANGED
|
@@ -19,7 +19,7 @@ function escapeMarkdown(strings) {
|
|
|
19
19
|
return strings.reduce(function (result, str, i) {
|
|
20
20
|
var value = values[i - 1];
|
|
21
21
|
if (typeof value === "string") {
|
|
22
|
-
return result + markdown_escape_1.default(value) + str;
|
|
22
|
+
return result + (0, markdown_escape_1.default)(value) + str;
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
25
25
|
return result + String(value) + str;
|
|
@@ -43,16 +43,19 @@ var createCodeURL = function (result, options) {
|
|
|
43
43
|
if (!physicalLocation.region) {
|
|
44
44
|
return [];
|
|
45
45
|
}
|
|
46
|
-
var lineNumber = physicalLocation.region.endLine !== undefined
|
|
47
|
-
|
|
46
|
+
var lineNumber = physicalLocation.region.endLine !== undefined
|
|
47
|
+
? "L".concat(physicalLocation.region.startLine, "-").concat(physicalLocation.region.endLine)
|
|
48
|
+
: "L".concat(physicalLocation.region.startLine);
|
|
49
|
+
return (0, url_join_1.default)(githubHost, options.owner, options.repo, "blob/".concat(options.branch), options.sourceRoot, "".concat(physicalLocation.artifactLocation.uri, "#").concat(lineNumber));
|
|
48
50
|
});
|
|
49
51
|
};
|
|
50
|
-
|
|
52
|
+
var sarifToMarkdown = function (options) {
|
|
53
|
+
var suppressedResultsFlag = options.suppressedResults !== undefined ? options.suppressedResults : true;
|
|
51
54
|
return function (sarifLog) {
|
|
52
55
|
return sarifLog.runs.map(function (run) {
|
|
53
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
54
|
-
var title = options.title ? "# "
|
|
55
|
-
var toolInfo = "\n## Tool information\n- Name: "
|
|
56
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
57
|
+
var title = options.title ? "# ".concat(options.title, "\n") : "# Report";
|
|
58
|
+
var toolInfo = "\n## Tool information\n- Name: ".concat((_a = run.tool.driver) === null || _a === void 0 ? void 0 : _a.name, "\n- Organization: ").concat((_b = run.tool.driver) === null || _b === void 0 ? void 0 : _b.organization, "\n- Version: ").concat((_c = run.tool.driver) === null || _c === void 0 ? void 0 : _c.semanticVersion, "\n");
|
|
56
59
|
// # tool section
|
|
57
60
|
// Rule info
|
|
58
61
|
// Vulnerability info
|
|
@@ -61,14 +64,13 @@ exports.sarifToMarkdown = function (options) {
|
|
|
61
64
|
/**
|
|
62
65
|
* # Rule Info
|
|
63
66
|
*/
|
|
64
|
-
var ruleInfo = escapeMarkdown(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n## Rules information\n<!-- Rule Info -->\n<details><summary>Rules details</summary>\n\n", "\n "], ["\n## Rules information\n<!-- Rule Info -->\n<details><summary>Rules details</summary>\n\n",
|
|
65
|
-
"\n "])), (_e = (_d = run.tool.driver) === null || _d === void 0 ? void 0 : _d.rules) === null || _e === void 0 ? void 0 : _e.map(function (rule) {
|
|
67
|
+
var ruleInfo = escapeMarkdown(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n## Rules information\n<!-- Rule Info -->\n<details><summary>Rules details</summary>\n\n", "\n "], ["\n## Rules information\n<!-- Rule Info -->\n<details><summary>Rules details</summary>\n\n", "\n "])), (_e = (_d = run.tool.driver) === null || _d === void 0 ? void 0 : _d.rules) === null || _e === void 0 ? void 0 : _e.map(function (rule) {
|
|
66
68
|
var _a, _b;
|
|
67
69
|
var severity = rule.properties ? (_a = rule.properties) === null || _a === void 0 ? void 0 : _a["problem.severity"] : "";
|
|
68
70
|
// rule description
|
|
69
|
-
return "- "
|
|
71
|
+
return "- ".concat(rule.id, " [").concat(severity, "]\n\n> ").concat((_b = rule.shortDescription) === null || _b === void 0 ? void 0 : _b.text);
|
|
70
72
|
}));
|
|
71
|
-
var ruleDetails = "<details><summary>Details</summary>\n<pre>"
|
|
73
|
+
var ruleDetails = "<details><summary>Details</summary>\n<pre>".concat(JSON.stringify(run.tool, null, 4), "</pre></details>\n");
|
|
72
74
|
/* Results
|
|
73
75
|
- rule id
|
|
74
76
|
- message
|
|
@@ -76,19 +78,51 @@ exports.sarifToMarkdown = function (options) {
|
|
|
76
78
|
|
|
77
79
|
If pass the scan, results is empty array
|
|
78
80
|
*/
|
|
79
|
-
var results = run.results && run.results.length > 0
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
var results = run.results && run.results.length > 0
|
|
82
|
+
? "\n## Results\n\n".concat((_f = run.results) === null || _f === void 0 ? void 0 : _f.map(function (result) {
|
|
83
|
+
return result.suppressions
|
|
84
|
+
? ""
|
|
85
|
+
: "- **".concat(result.ruleId, "**: ").concat((0, markdown_escape_1.default)(result.message.text)) +
|
|
86
|
+
"\n\n" +
|
|
87
|
+
createCodeURL(result, options).join("\n") +
|
|
88
|
+
"\n";
|
|
89
|
+
}).join("\n"), "\n")
|
|
85
90
|
: "\n## Results\n\nNo Error\n\n";
|
|
91
|
+
// careful, double ternary... first check if we should include suppressedresults (return empty string)
|
|
92
|
+
// then check if there are results, if none, return default string
|
|
93
|
+
var suppressedResultsText = suppressedResultsFlag
|
|
94
|
+
? run.results && run.results.length > 0
|
|
95
|
+
? "\n## Suppressed results\n\n".concat((_g = run.results) === null || _g === void 0 ? void 0 : _g.map(function (result) {
|
|
96
|
+
return result.suppressions
|
|
97
|
+
? "- **".concat(result.ruleId, "**: ").concat((0, markdown_escape_1.default)(result.message.text)) +
|
|
98
|
+
"\n\n" +
|
|
99
|
+
createCodeURL(result, options).join("\n") +
|
|
100
|
+
"\n"
|
|
101
|
+
: "";
|
|
102
|
+
}).join("\n"), "\n")
|
|
103
|
+
: "\n## Results\n\nNo suppressed issues\n\n"
|
|
104
|
+
: "";
|
|
105
|
+
if (options.details) {
|
|
106
|
+
return {
|
|
107
|
+
body: title +
|
|
108
|
+
results +
|
|
109
|
+
"\n" +
|
|
110
|
+
suppressedResultsText +
|
|
111
|
+
"\n" +
|
|
112
|
+
ruleInfo +
|
|
113
|
+
"\n" +
|
|
114
|
+
ruleDetails +
|
|
115
|
+
toolInfo,
|
|
116
|
+
hasMessages: ((_h = run.results) === null || _h === void 0 ? void 0 : _h.length) !== 0
|
|
117
|
+
};
|
|
118
|
+
}
|
|
86
119
|
return {
|
|
87
|
-
body: title + results + "\n" +
|
|
88
|
-
hasMessages: ((
|
|
120
|
+
body: title + results + "\n" + suppressedResultsText + "\n" + ruleInfo + "\n" + toolInfo,
|
|
121
|
+
hasMessages: ((_j = run.results) === null || _j === void 0 ? void 0 : _j.length) !== 0
|
|
89
122
|
};
|
|
90
123
|
});
|
|
91
124
|
};
|
|
92
125
|
};
|
|
126
|
+
exports.sarifToMarkdown = sarifToMarkdown;
|
|
93
127
|
var templateObject_1;
|
|
94
128
|
//# sourceMappingURL=sarif-to-markdown.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sarif-to-markdown.js","sourceRoot":"","sources":["../src/sarif-to-markdown.ts"],"names":[],"mappings":";;;;;;;;;;AACA,aAAa;AACb,
|
|
1
|
+
{"version":3,"file":"sarif-to-markdown.js","sourceRoot":"","sources":["../src/sarif-to-markdown.ts"],"names":[],"mappings":";;;;;;;;;;AACA,aAAa;AACb,oEAAqC;AACrC,sDAA+B;AAE/B,SAAS,cAAc,CAAC,OAA6B;IAAE,gBAAgB;SAAhB,UAAgB,EAAhB,qBAAgB,EAAhB,IAAgB;QAAhB,+BAAgB;;IACnE,OAAO,OAAO,CAAC,MAAM,CAAC,UAAC,MAAM,EAAE,GAAG,EAAE,CAAC;QACjC,IAAM,KAAK,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAC5B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC3B,OAAO,MAAM,GAAG,IAAA,yBAAM,EAAC,KAAK,CAAC,GAAG,GAAG,CAAC;SACvC;aAAM;YACH,OAAO,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC;SACvC;IACL,CAAC,CAAC,CAAC;AACP,CAAC;AAED,IAAM,aAAa,GAAG,UAAC,MAAc,EAAE,OAA8B;;IACjE,IAAM,UAAU,GAAG,MAAA,OAAO,CAAC,UAAU,mCAAI,oBAAoB,CAAC;IAC9D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE;QAClC,OAAO,EAAE,CAAC;KACb;IACD,OAAO,MAAA,MAAM,CAAC,SAAS,0CAAE,OAAO,CAAC,UAAC,QAAa;QAC3C,IAAI,CAAC,QAAQ,CAAC,gBAAgB,EAAE;YAC5B,OAAO,EAAE,CAAC;SACb;QACD,IAAM,gBAAgB,GAAG,QAAQ,CAAC,gBAAgB,CAAC;QACnD,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,EAAE;YACpC,OAAO,EAAE,CAAC;SACb;QACD,IAAI,CAAC,gBAAgB,CAAC,MAAM,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C,qCAGpB,MAAA,GAAG,CAAC,OAAO,0CACP,GAAG,CAAC,UAAC,MAAW;wBACd,OAAO,MAAM,CAAC,YAAY;4BACtB,CAAC,CAAC,cAAO,MAAM,CAAC,MAAM,iBAAO,IAAA,yBAAM,EAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAE;gCACpD,MAAM;gCACN,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;gCACzC,IAAI;4BACV,CAAC,CAAC,EAAE,CAAC;oBACb,CAAC,EACA,IAAI,CAAC,IAAI,CAAC,OACd;oBACmB,CAAC,CAAC,0CAKrB;gBACe,CAAC,CAAC,EAAE,CAAC;YAET,IAAI,OAAO,CAAC,OAAO,EAAE;gBACjB,OAAO;oBACH,IAAI,EACA,KAAK;wBACL,OAAO;wBACP,IAAI;wBACJ,qBAAqB;wBACrB,IAAI;wBACJ,QAAQ;wBACR,IAAI;wBACJ,WAAW;wBACX,QAAQ;oBACZ,WAAW,EAAE,CAAA,MAAA,GAAG,CAAC,OAAO,0CAAE,MAAM,MAAK,CAAC;iBACzC,CAAC;aACL;YACD,OAAO;gBACH,IAAI,EAAE,KAAK,GAAG,OAAO,GAAG,IAAI,GAAG,qBAAqB,GAAG,IAAI,GAAG,QAAQ,GAAG,IAAI,GAAG,QAAQ;gBACxF,WAAW,EAAE,CAAA,MAAA,GAAG,CAAC,OAAO,0CAAE,MAAM,MAAK,CAAC;aACzC,CAAC;QACN,CAAC,CAAC,CAAC;IACP,CAAC,CAAC;AACN,CAAC,CAAC;AAnHW,QAAA,eAAe,mBAmH1B"}
|
|
@@ -25,6 +25,14 @@ export declare type sarifFormatterOptions = {
|
|
|
25
25
|
* Base path
|
|
26
26
|
*/
|
|
27
27
|
sourceRoot: string;
|
|
28
|
+
/**
|
|
29
|
+
* Details of the rules in the comment or not, this might make the comment too big for Github
|
|
30
|
+
*/
|
|
31
|
+
details?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Should the markdown include suppressed findings, defaults to true
|
|
34
|
+
*/
|
|
35
|
+
suppressedResults?: boolean;
|
|
28
36
|
};
|
|
29
37
|
declare type sarifToMarkdownResult = {
|
|
30
38
|
title?: string;
|
|
@@ -3,7 +3,7 @@ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cook
|
|
|
3
3
|
return cooked;
|
|
4
4
|
};
|
|
5
5
|
// @ts-ignore
|
|
6
|
-
import escape from
|
|
6
|
+
import escape from "markdown-escape";
|
|
7
7
|
import urlJoin from "url-join";
|
|
8
8
|
function escapeMarkdown(strings) {
|
|
9
9
|
var values = [];
|
|
@@ -37,16 +37,19 @@ var createCodeURL = function (result, options) {
|
|
|
37
37
|
if (!physicalLocation.region) {
|
|
38
38
|
return [];
|
|
39
39
|
}
|
|
40
|
-
var lineNumber = physicalLocation.region.endLine !== undefined
|
|
41
|
-
|
|
40
|
+
var lineNumber = physicalLocation.region.endLine !== undefined
|
|
41
|
+
? "L".concat(physicalLocation.region.startLine, "-").concat(physicalLocation.region.endLine)
|
|
42
|
+
: "L".concat(physicalLocation.region.startLine);
|
|
43
|
+
return urlJoin(githubHost, options.owner, options.repo, "blob/".concat(options.branch), options.sourceRoot, "".concat(physicalLocation.artifactLocation.uri, "#").concat(lineNumber));
|
|
42
44
|
});
|
|
43
45
|
};
|
|
44
46
|
export var sarifToMarkdown = function (options) {
|
|
47
|
+
var suppressedResultsFlag = options.suppressedResults !== undefined ? options.suppressedResults : true;
|
|
45
48
|
return function (sarifLog) {
|
|
46
49
|
return sarifLog.runs.map(function (run) {
|
|
47
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
48
|
-
var title = options.title ? "# "
|
|
49
|
-
var toolInfo = "\n## Tool information\n- Name: "
|
|
50
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
51
|
+
var title = options.title ? "# ".concat(options.title, "\n") : "# Report";
|
|
52
|
+
var toolInfo = "\n## Tool information\n- Name: ".concat((_a = run.tool.driver) === null || _a === void 0 ? void 0 : _a.name, "\n- Organization: ").concat((_b = run.tool.driver) === null || _b === void 0 ? void 0 : _b.organization, "\n- Version: ").concat((_c = run.tool.driver) === null || _c === void 0 ? void 0 : _c.semanticVersion, "\n");
|
|
50
53
|
// # tool section
|
|
51
54
|
// Rule info
|
|
52
55
|
// Vulnerability info
|
|
@@ -55,14 +58,13 @@ export var sarifToMarkdown = function (options) {
|
|
|
55
58
|
/**
|
|
56
59
|
* # Rule Info
|
|
57
60
|
*/
|
|
58
|
-
var ruleInfo = escapeMarkdown(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n## Rules information\n<!-- Rule Info -->\n<details><summary>Rules details</summary>\n\n", "\n "], ["\n## Rules information\n<!-- Rule Info -->\n<details><summary>Rules details</summary>\n\n",
|
|
59
|
-
"\n "])), (_e = (_d = run.tool.driver) === null || _d === void 0 ? void 0 : _d.rules) === null || _e === void 0 ? void 0 : _e.map(function (rule) {
|
|
61
|
+
var ruleInfo = escapeMarkdown(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n## Rules information\n<!-- Rule Info -->\n<details><summary>Rules details</summary>\n\n", "\n "], ["\n## Rules information\n<!-- Rule Info -->\n<details><summary>Rules details</summary>\n\n", "\n "])), (_e = (_d = run.tool.driver) === null || _d === void 0 ? void 0 : _d.rules) === null || _e === void 0 ? void 0 : _e.map(function (rule) {
|
|
60
62
|
var _a, _b;
|
|
61
63
|
var severity = rule.properties ? (_a = rule.properties) === null || _a === void 0 ? void 0 : _a["problem.severity"] : "";
|
|
62
64
|
// rule description
|
|
63
|
-
return "- "
|
|
65
|
+
return "- ".concat(rule.id, " [").concat(severity, "]\n\n> ").concat((_b = rule.shortDescription) === null || _b === void 0 ? void 0 : _b.text);
|
|
64
66
|
}));
|
|
65
|
-
var ruleDetails = "<details><summary>Details</summary>\n<pre>"
|
|
67
|
+
var ruleDetails = "<details><summary>Details</summary>\n<pre>".concat(JSON.stringify(run.tool, null, 4), "</pre></details>\n");
|
|
66
68
|
/* Results
|
|
67
69
|
- rule id
|
|
68
70
|
- message
|
|
@@ -70,16 +72,47 @@ export var sarifToMarkdown = function (options) {
|
|
|
70
72
|
|
|
71
73
|
If pass the scan, results is empty array
|
|
72
74
|
*/
|
|
73
|
-
var results = run.results && run.results.length > 0
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
var results = run.results && run.results.length > 0
|
|
76
|
+
? "\n## Results\n\n".concat((_f = run.results) === null || _f === void 0 ? void 0 : _f.map(function (result) {
|
|
77
|
+
return result.suppressions
|
|
78
|
+
? ""
|
|
79
|
+
: "- **".concat(result.ruleId, "**: ").concat(escape(result.message.text)) +
|
|
80
|
+
"\n\n" +
|
|
81
|
+
createCodeURL(result, options).join("\n") +
|
|
82
|
+
"\n";
|
|
83
|
+
}).join("\n"), "\n")
|
|
79
84
|
: "\n## Results\n\nNo Error\n\n";
|
|
85
|
+
// careful, double ternary... first check if we should include suppressedresults (return empty string)
|
|
86
|
+
// then check if there are results, if none, return default string
|
|
87
|
+
var suppressedResultsText = suppressedResultsFlag
|
|
88
|
+
? run.results && run.results.length > 0
|
|
89
|
+
? "\n## Suppressed results\n\n".concat((_g = run.results) === null || _g === void 0 ? void 0 : _g.map(function (result) {
|
|
90
|
+
return result.suppressions
|
|
91
|
+
? "- **".concat(result.ruleId, "**: ").concat(escape(result.message.text)) +
|
|
92
|
+
"\n\n" +
|
|
93
|
+
createCodeURL(result, options).join("\n") +
|
|
94
|
+
"\n"
|
|
95
|
+
: "";
|
|
96
|
+
}).join("\n"), "\n")
|
|
97
|
+
: "\n## Results\n\nNo suppressed issues\n\n"
|
|
98
|
+
: "";
|
|
99
|
+
if (options.details) {
|
|
100
|
+
return {
|
|
101
|
+
body: title +
|
|
102
|
+
results +
|
|
103
|
+
"\n" +
|
|
104
|
+
suppressedResultsText +
|
|
105
|
+
"\n" +
|
|
106
|
+
ruleInfo +
|
|
107
|
+
"\n" +
|
|
108
|
+
ruleDetails +
|
|
109
|
+
toolInfo,
|
|
110
|
+
hasMessages: ((_h = run.results) === null || _h === void 0 ? void 0 : _h.length) !== 0
|
|
111
|
+
};
|
|
112
|
+
}
|
|
80
113
|
return {
|
|
81
|
-
body: title + results + "\n" +
|
|
82
|
-
hasMessages: ((
|
|
114
|
+
body: title + results + "\n" + suppressedResultsText + "\n" + ruleInfo + "\n" + toolInfo,
|
|
115
|
+
hasMessages: ((_j = run.results) === null || _j === void 0 ? void 0 : _j.length) !== 0
|
|
83
116
|
};
|
|
84
117
|
});
|
|
85
118
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sarif-to-markdown.js","sourceRoot":"","sources":["../src/sarif-to-markdown.ts"],"names":[],"mappings":";;;;AACA,aAAa;AACb,OAAO,MAAM,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"sarif-to-markdown.js","sourceRoot":"","sources":["../src/sarif-to-markdown.ts"],"names":[],"mappings":";;;;AACA,aAAa;AACb,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,OAAO,MAAM,UAAU,CAAC;AAE/B,SAAS,cAAc,CAAC,OAA6B;IAAE,gBAAgB;SAAhB,UAAgB,EAAhB,qBAAgB,EAAhB,IAAgB;QAAhB,+BAAgB;;IACnE,OAAO,OAAO,CAAC,MAAM,CAAC,UAAC,MAAM,EAAE,GAAG,EAAE,CAAC;QACjC,IAAM,KAAK,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAC5B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC3B,OAAO,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC;SACvC;aAAM;YACH,OAAO,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC;SACvC;IACL,CAAC,CAAC,CAAC;AACP,CAAC;AAED,IAAM,aAAa,GAAG,UAAC,MAAc,EAAE,OAA8B;;IACjE,IAAM,UAAU,GAAG,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AG,IAAI,GAAG,QAAQ,GAAG,IAAI,GAAG,QAAQ;gBACxF,WAAW,EAAE,CAAA,MAAA,GAAG,CAAC,OAAO,0CAAE,MAAM,MAAK,CAAC;aACzC,CAAC;QACN,CAAC,CAAC,CAAC;IACP,CAAC,CAAC;AACN,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@security-alert/sarif-to-markdown",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Convert Sarif format to body text",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sarif",
|
|
@@ -33,18 +33,11 @@
|
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "tsc -p . && tsc --project ./tsconfig.module.json",
|
|
35
35
|
"clean": "rimraf lib/ module/",
|
|
36
|
-
"prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"",
|
|
37
36
|
"prepublish": "npm run --if-present build",
|
|
38
37
|
"test": "mocha \"test/**/*.ts\"",
|
|
39
38
|
"updateSnapshot": "UPDATE_SNAPSHOT=1 npm test",
|
|
40
39
|
"watch": "tsc -p . --watch"
|
|
41
40
|
},
|
|
42
|
-
"prettier": {
|
|
43
|
-
"printWidth": 120,
|
|
44
|
-
"singleQuote": false,
|
|
45
|
-
"tabWidth": 4,
|
|
46
|
-
"trailingComma": "none"
|
|
47
|
-
},
|
|
48
41
|
"dependencies": {
|
|
49
42
|
"@types/sarif": "^2.1.2",
|
|
50
43
|
"markdown-escape": "^1.1.0",
|
|
@@ -54,15 +47,14 @@
|
|
|
54
47
|
"@types/mocha": "^8.0.1",
|
|
55
48
|
"@types/node": "^14.0.27",
|
|
56
49
|
"@types/url-join": "^4.0.0",
|
|
57
|
-
"mocha": "^
|
|
58
|
-
"prettier": "^2.0.5",
|
|
50
|
+
"mocha": "^9.2.2",
|
|
59
51
|
"rimraf": "^3.0.2",
|
|
60
|
-
"ts-node": "^
|
|
61
|
-
"ts-node-test-register": "^
|
|
62
|
-
"typescript": "^
|
|
52
|
+
"ts-node": "^10.7.0",
|
|
53
|
+
"ts-node-test-register": "^10.0.0",
|
|
54
|
+
"typescript": "^4.6.3"
|
|
63
55
|
},
|
|
64
56
|
"publishConfig": {
|
|
65
57
|
"access": "public"
|
|
66
58
|
},
|
|
67
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "6788f5c379dc9daa8cfeb6556d1cce93401df21e"
|
|
68
60
|
}
|
package/lib/sarif-formatter.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { Log } from "sarif";
|
|
2
|
-
export declare type sarifFormatterResult = {
|
|
3
|
-
title: string;
|
|
4
|
-
body: string;
|
|
5
|
-
};
|
|
6
|
-
export declare type sarifFormatterOptions = {
|
|
7
|
-
githubHost?: string;
|
|
8
|
-
/**
|
|
9
|
-
* GitHub Owner
|
|
10
|
-
*/
|
|
11
|
-
owner: string;
|
|
12
|
-
/**
|
|
13
|
-
* GitHub Repo
|
|
14
|
-
*/
|
|
15
|
-
repo: string;
|
|
16
|
-
/**
|
|
17
|
-
* Base path
|
|
18
|
-
*/
|
|
19
|
-
sourceRoot: string;
|
|
20
|
-
};
|
|
21
|
-
export declare const sarifFormatter: (options: sarifFormatterOptions) => (sarifLog: Log) => {
|
|
22
|
-
title: string;
|
|
23
|
-
body: string;
|
|
24
|
-
}[];
|
package/lib/sarif-formatter.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
3
|
-
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
4
|
-
return cooked;
|
|
5
|
-
};
|
|
6
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
-
};
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.sarifFormatter = void 0;
|
|
11
|
-
// @ts-ignore
|
|
12
|
-
var markdown_escape_1 = __importDefault(require("markdown-escape"));
|
|
13
|
-
function escapeMarkdown(strings) {
|
|
14
|
-
var values = [];
|
|
15
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
16
|
-
values[_i - 1] = arguments[_i];
|
|
17
|
-
}
|
|
18
|
-
return strings.reduce(function (result, str, i) {
|
|
19
|
-
var value = values[i - 1];
|
|
20
|
-
if (typeof value === "string") {
|
|
21
|
-
return result + markdown_escape_1.default(value) + str;
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
return result + String(value) + str;
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
var createCodeURL = function (result, options) {
|
|
29
|
-
return options.githubHost + "/" + ;
|
|
30
|
-
};
|
|
31
|
-
exports.sarifFormatter = function (options) {
|
|
32
|
-
return function (sarifLog) {
|
|
33
|
-
return sarifLog.runs.map(function (run) {
|
|
34
|
-
var _a, _b, _c;
|
|
35
|
-
// # tool section
|
|
36
|
-
// Rule info
|
|
37
|
-
// Vulnerability info
|
|
38
|
-
// ## Results
|
|
39
|
-
// Result(s)
|
|
40
|
-
var rule = escapeMarkdown(templateObject_2 || (templateObject_2 = __makeTemplateObject(["# ", "\n<!-- Rule Info -->\n", "\n \n<details><summary>Details</summary>\n<pre>", "</pre></details>\n\n<!-- Results \n\n- rule id\n- message\n- vulnerability location\n\n-->\n\n", "\n"], ["\\\n# ", "\n<!-- Rule Info -->\n",
|
|
41
|
-
"\n \n<details><summary>Details</summary>\n<pre>", "</pre></details>\n\n<!-- Results \n\n- rule id\n- message\n- vulnerability location\n\n-->\n\n",
|
|
42
|
-
"\n"])), run.tool.driver.name, (_b = (_a = run.tool.driver) === null || _a === void 0 ? void 0 : _a.rules) === null || _b === void 0 ? void 0 : _b.map(function (rule) {
|
|
43
|
-
// rule description
|
|
44
|
-
return "**" + rule.id + "**\n\n> " + rule.shortDescription;
|
|
45
|
-
}), JSON.stringify(run.tool, null, 4), (_c = run.results) === null || _c === void 0 ? void 0 : _c.map(function (result) {
|
|
46
|
-
return escapeMarkdown(templateObject_1 || (templateObject_1 = __makeTemplateObject(["**", "**: ", "\n\n\n"], ["**", "**: ", "\n\n\n"])), result.ruleId, result.message);
|
|
47
|
-
}));
|
|
48
|
-
return {
|
|
49
|
-
title: "",
|
|
50
|
-
body: ""
|
|
51
|
-
};
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
var templateObject_1, templateObject_2;
|
|
56
|
-
//# sourceMappingURL=sarif-to-markdown.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sarif-to-markdown.js","sourceRoot":"","sources":["../src/sarif-to-markdown.ts"],"names":[],"mappings":";;;;;;;;;;AACA,aAAa;AACb,oEAAoC;AAGpC,SAAS,cAAc,CAAC,OAA6B;IAAE,gBAAgB;SAAhB,UAAgB,EAAhB,qBAAgB,EAAhB,IAAgB;QAAhB,+BAAgB;;IACnE,OAAO,OAAO,CAAC,MAAM,CAAC,UAAC,MAAM,EAAE,GAAG,EAAE,CAAC;QACjC,IAAM,KAAK,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAC5B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC3B,OAAO,MAAM,GAAG,yBAAM,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC;SACvC;aAAM;YACH,OAAO,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC;SACvC;IACL,CAAC,CAAC,CAAC;AACP,CAAC;AAED,IAAM,aAAa,GAAG,UAAC,MAAc,EAAE,OAA8B;IACjE,OAAU,OAAO,CAAC,UAAU,SAAM,CAAA;AAEtC,CAAC,CAAA;AAsBY,QAAA,cAAc,GAAG,UAAC,OAA8B;IACzD,OAAO,UAAC,QAAa;QACjB,OAAO,QAAQ,CA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