next-issue 6.6.43 → 6.6.44
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/dist/verdict.mjs +33 -6
- package/package.json +1 -1
package/dist/verdict.mjs
CHANGED
|
@@ -31,18 +31,45 @@ export function readVerdict(value) {
|
|
|
31
31
|
}
|
|
32
32
|
return { summary, findings: checked };
|
|
33
33
|
}
|
|
34
|
-
const
|
|
34
|
+
const JSON_FENCE = /```json[^\n]*\n/g;
|
|
35
|
+
const FENCE = '```';
|
|
36
|
+
function parseJson(text) {
|
|
37
|
+
try {
|
|
38
|
+
return { value: JSON.parse(text) };
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
35
44
|
export function parseVerdict(text) {
|
|
36
|
-
const
|
|
45
|
+
const fences = [...text.matchAll(JSON_FENCE)];
|
|
46
|
+
const last = fences.at(-1);
|
|
37
47
|
if (last === undefined) {
|
|
38
48
|
return undefined;
|
|
39
49
|
}
|
|
40
|
-
|
|
41
|
-
|
|
50
|
+
for (const fence of fences.toReversed()) {
|
|
51
|
+
const block = readBlock(text, fence.index + fence[0].length);
|
|
52
|
+
if (block === undefined) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (block.end < last.index) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
const verdict = readVerdict(block.value);
|
|
59
|
+
if (verdict !== undefined) {
|
|
60
|
+
return verdict;
|
|
61
|
+
}
|
|
42
62
|
}
|
|
43
|
-
|
|
44
|
-
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
function readBlock(text, start) {
|
|
66
|
+
for (let end = text.indexOf(FENCE, start); end !== -1; end = text.indexOf(FENCE, end + 1)) {
|
|
67
|
+
const parsed = parseJson(text.slice(start, end));
|
|
68
|
+
if (parsed !== undefined) {
|
|
69
|
+
return { value: parsed.value, end };
|
|
70
|
+
}
|
|
45
71
|
}
|
|
72
|
+
return undefined;
|
|
46
73
|
}
|
|
47
74
|
export function blockingFindings(verdict) {
|
|
48
75
|
return verdict.findings.filter((finding) => finding.severity === 'blocking');
|