| 49 | } |
| 50 | |
| 51 | export class ActionsLogParser { |
| 52 | private logLines: ILogLine[] |
| 53 | private logContent: string |
| 54 | private rawLogData: string |
| 55 | private lineMetaData: ILine[] |
| 56 | private logLineNumbers: number[] |
| 57 | private timestamps: string[] |
| 58 | /** |
| 59 | * This is used a prefix to the line number if we would want the line numbers |
| 60 | * to be links to dotcom logs. |
| 61 | * |
| 62 | * Example: https://github.com/desktop/desktop/runs/3840220073#step:13 |
| 63 | */ |
| 64 | private permalinkPrefix: string |
| 65 | |
| 66 | public constructor(rawLogData: string, permalinkPrefix: string) { |
| 67 | this.rawLogData = rawLogData |
| 68 | this.permalinkPrefix = permalinkPrefix |
| 69 | this.logContent = '' |
| 70 | this.lineMetaData = [] |
| 71 | this.logLines = [] |
| 72 | this.logLineNumbers = [] |
| 73 | this.timestamps = [] |
| 74 | this.updateLogLines() |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Returns the parsed lines in the form of an object with the meta data needed |
| 79 | * to build a an html element for the line. |
| 80 | * |
| 81 | * @param node |
| 82 | * @param groupExpanded |
| 83 | * @returns |
| 84 | */ |
| 85 | public getParsedLogLinesTemplateData(): ReadonlyArray<ILogLineTemplateData> { |
| 86 | return this.logLines.map(ll => this.getParsedLineTemplateData(ll)) |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Returns a line object with the meta data needed to build a an html element |
| 91 | * for the line. |
| 92 | * |
| 93 | */ |
| 94 | private getParsedLineTemplateData(node: ILogLine): ILogLineTemplateData { |
| 95 | const { lineIndex } = node |
| 96 | const logLineNumber = this.logLineNumbers[lineIndex] |
| 97 | const lineNumber = logLineNumber != null ? logLineNumber : lineIndex + 1 |
| 98 | const text = this.getNodeText(node) |
| 99 | |
| 100 | // parse() does the ANSI parsing and converts to HTML |
| 101 | const lineContent = this.parse(text) |
| 102 | |
| 103 | // The parser assigns a type to each line. Such as "debug" or "command". |
| 104 | // These change the way the line looks. See checks.scss for the css. |
| 105 | const className = `log-line-${getType(node)}` |
| 106 | |
| 107 | return { |
| 108 | className, |
nothing calls this directly
no outgoing calls
no test coverage detected