MCPcopy Create free account
hub / github.com/code-pushup/cli / parseDiff

Function parseDiff

packages/ci/src/lib/git.ts:109–133  ·  view source on GitHub ↗
(diff: string)

Source from the content-addressed store, hash-verified

107}
108
109function parseDiff(diff: string): LineChange[] {
110 const changeSummaries = diff.match(/@@ [ \d,+-]+ @@/g);
111 if (changeSummaries == null) {
112 return [];
113 }
114 return changeSummaries
115 .map(summary => summary.match(/^@@ -(\d+|\d+,\d+) \+(\d+|\d+,\d+) @@$/))
116 .filter((matches): matches is RegExpMatchArray => matches != null)
117 .map((matches): LineChange => {
118 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
119 const [prevLine = '', prevAdded = '1'] = matches[1]!.split(',');
120 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
121 const [currLine = '', currAdded = '1'] = matches[2]!.split(',');
122 return {
123 prev: {
124 line: Number.parseInt(prevLine, 10),
125 count: Number.parseInt(prevAdded, 10),
126 },
127 curr: {
128 line: Number.parseInt(currLine, 10),
129 count: Number.parseInt(currAdded, 10),
130 },
131 };
132 });
133}
134
135export function isFileChanged(
136 changedFiles: ChangedFiles,

Callers 1

listChangedFilesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected