-
Notifications
You must be signed in to change notification settings - Fork 178
Expand file tree
/
Copy pathmodel.ts
More file actions
92 lines (74 loc) · 2.03 KB
/
model.ts
File metadata and controls
92 lines (74 loc) · 2.03 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// eslint-disable-next-line no-control-regex
const ansiColorRegex = /\u001b\[(\d+;)*\d+m/gm;
const groupMarker = "##[group]";
import {Parser, IStyle} from "./parser";
export interface LogSection {
start: number;
end: number;
name?: string;
}
export interface LogStyleInfo {
line: number;
content: string;
style?: IStyle;
}
export interface LogInfo {
updatedLogLines: string[];
sections: LogSection[];
styleFormats: LogStyleInfo[];
}
export function parseLog(log: string): LogInfo {
let firstSection: LogSection | null = {
name: "Setup",
start: 0,
end: 1
};
// Assume there is always the setup section
const sections: LogSection[] = [firstSection];
let currentRange: LogSection | null = null;
const parser = new Parser();
const styleInfo: LogStyleInfo[] = [];
const lines = log.split(/\n|\r/).filter(l => !!l);
let lineIdx = 0;
for (const line of lines) {
// Groups
const groupMarkerStart = line.indexOf(groupMarker);
if (groupMarkerStart !== -1) {
// If this is the first group marker we encounter, the previous range was the job setup
if (firstSection) {
firstSection.end = lineIdx - 1;
firstSection = null;
}
if (currentRange) {
currentRange.end = lineIdx - 1;
sections.push(currentRange);
}
const name = line.substring(groupMarkerStart + groupMarker.length);
currentRange = {
name,
start: lineIdx,
end: lineIdx + 1
};
}
const stateFragments = parser.getStates(line);
for (const state of stateFragments) {
styleInfo.push({
line: lineIdx,
content: state.output,
style: state.style
});
}
// Remove all other commands and codes from the output, we don't support those
lines[lineIdx] = line.replace(ansiColorRegex, "");
++lineIdx;
}
if (currentRange) {
currentRange.end = lineIdx - 1;
sections.push(currentRange);
}
return {
updatedLogLines: lines,
sections: sections,
styleFormats: styleInfo
};
}