MCPcopy Index your code
hub / github.com/desktop/desktop / parse

Method parse

app/src/lib/progress/git.ts:215–246  ·  view source on GitHub ↗

* Parse the given line of output from Git, returns either an `IGitProgress` * instance if the line could successfully be parsed as a Git progress * event whose title was registered with this parser or an `IGitOutput` * instance if the line couldn't be parsed or if the title wasn't * regi

(line: string)

Source from the content-addressed store, hash-verified

213 * registered with the parser.
214 */
215 public parse(line: string): IGitProgress | IGitOutput {
216 // In case we're parsing hook output or similar we want to
217 // strip out any control characters that may be present. IGitProgress
218 // is supposed to be readable text that can be used in tooltips and such.
219 const text = stripVTControlCharacters(line)
220 const progress = parse(text)
221
222 if (!progress) {
223 return { kind: 'context', text, percent: this.lastPercent }
224 }
225
226 let percent = 0
227
228 for (let i = 0; i < this.steps.length; i++) {
229 const step = this.steps[i]
230
231 if (i >= this.stepIndex && progress.title === step.title) {
232 if (progress.total) {
233 percent += step.weight * (progress.value / progress.total)
234 }
235
236 this.stepIndex = i
237 this.lastPercent = percent
238
239 return { kind: 'progress', percent, details: progress }
240 } else {
241 percent += step.weight
242 }
243 }
244
245 return { kind: 'context', text, percent: this.lastPercent }
246 }
247}
248
249const percentRe = /^(\d{1,3})% \((\d+)\/(\d+)\)$/

Callers

nothing calls this directly

Calls 1

parseFunction · 0.70

Tested by

no test coverage detected