Skip to content

Commit

Permalink
Fix diff processing
Browse files Browse the repository at this point in the history
  • Loading branch information
azz committed Feb 24, 2018
1 parent c979c4f commit 0301946
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
26 changes: 10 additions & 16 deletions source/platforms/bitbucket_server/BitBucketServerGit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,14 @@ const bitBucketServerDiffToGitJSONDSL = (diffs: BitBucketServerDiff[], commits:
}

const bitBucketServerDiffToGitStructuredDiff = (diffs: BitBucketServerDiff[]): GitStructuredDiff => {
const chunks: Chunk[] = []

for (const diff of diffs) {
for (const hunk of diff.hunks) {
chunks.push({
from: diff.source && diff.source.toString,
to: diff.destination && diff.destination.toString,
changes: hunk.segments.map(segment => ({
type: segment.type === "ADDED" ? ("add" as "add") : ("del" as "del"),
content: segment.lines.map(({ line }) => line).join(EOL),
})),
})
}
}

return { chunks }
return diffs.map(diff => ({
from: diff.source && diff.source.toString,
to: diff.destination && diff.destination.toString,
chunks: diff.hunks.map(hunk => ({
changes: hunk.segments.map(segment => ({
type: segment.type === "ADDED" ? ("add" as "add") : ("del" as "del"),
content: segment.lines.map(({ line }) => line).join(EOL),
})),
})),
}))
}
14 changes: 6 additions & 8 deletions source/platforms/git/gitJSONToGitDSL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ export interface GitJSONToGitDSLConfig {
getFullStructuredDiff?: (base: string, head: string) => Promise<GitStructuredDiff>
}

export interface GitStructuredDiff {
export type GitStructuredDiff = {
from?: string
to?: string
chunks: Chunk[]
}
}[]

export interface Chunk {
changes: Changes
from?: string
to?: string
}

export type Changes = { type: "add" | "del"; content: string }[]
Expand Down Expand Up @@ -158,11 +158,9 @@ export const gitJSONToGitDSL = (gitJSONRep: GitJSONDSL, config: GitJSONToGitDSLC
fileDiffs = await config.getFullStructuredDiff(config.baseSHA, config.headSHA)
} else {
const diff = await config.getFullDiff!(config.baseSHA, config.headSHA)
fileDiffs = { chunks: parseDiff(diff) }
}
const structuredDiff: GitStructuredDiff = {
chunks: fileDiffs.chunks.filter(diff => diff.from === filename || diff.to === filename),
fileDiffs = parseDiff(diff)
}
const structuredDiff = fileDiffs.find(diff => diff.from === filename || diff.to === filename)

if (!structuredDiff) {
return null
Expand Down

0 comments on commit 0301946

Please sign in to comment.