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

Function structuredDiffForFile

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

Source from the content-addressed store, hash-verified

192 * @param filename File path for the diff
193 */
194 const structuredDiffForFile = async (filename: string): Promise<StructuredDiff | null> => {
195 let fileDiffs: GitStructuredDiff
196
197 if (config.getStructuredDiffForFile) {
198 fileDiffs = await config.getStructuredDiffForFile(config.baseSHA, config.headSHA, filename)
199 } else {
200 const diff = await getFullDiff!(config.baseSHA, config.headSHA)
201 fileDiffs = parseDiff(diff)
202 }
203 const structuredDiff = fileDiffs.find((diff) => diff.from === filename || diff.to === filename)
204 if (structuredDiff !== undefined && structuredDiff.chunks !== undefined) {
205 return {
206 chunks: structuredDiff.chunks,
207 // '/dev/null' will be in the 'from' path if the file is new.
208 fromPath: structuredDiff.from === "/dev/null" ? undefined : structuredDiff.from,
209 }
210 } else {
211 return null
212 }
213 }
214
215 /**
216 * Gets the git-style diff for a single file.

Callers 1

diffForFileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected