MCPcopy
hub / github.com/danger/danger-js / diffForFile

Function diffForFile

source/platforms/git/gitJSONToGitDSL.ts:220–241  ·  view source on GitHub ↗
(filename: string)

Source from the content-addressed store, hash-verified

218 * @param filename File path for the diff
219 */
220 const diffForFile = async (filename: string) => {
221 const structuredDiff = await structuredDiffForFile(filename)
222
223 if (!structuredDiff) {
224 return null
225 }
226
227 const allLines = structuredDiff.chunks
228 .map((c: { changes: Changes }) => c.changes)
229 .reduce((a: Changes, b: Changes) => a.concat(b), [])
230
231 return {
232 before: await config.getFileContents(filename, config.repo, config.baseSHA),
233 after: await config.getFileContents(filename, config.repo, config.headSHA),
234
235 diff: allLines.map(getContent).join(os.EOL),
236
237 added: allLines.filter(byType("add")).map(getContent).join(os.EOL),
238
239 removed: allLines.filter(byType("del")).map(getContent).join(os.EOL),
240 }
241 }
242
243 return {
244 base: config.baseSHA,

Callers 1

linesOfCodeFunction · 0.85

Calls 3

structuredDiffForFileFunction · 0.85
byTypeFunction · 0.85
getFileContentsMethod · 0.65

Tested by

no test coverage detected