Skip to content

Commit

Permalink
Add and use status on GitHubFile
Browse files Browse the repository at this point in the history
  • Loading branch information
szweier committed May 30, 2024
1 parent bb0f4c2 commit 6883bcf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 6 additions & 4 deletions source/platforms/git/diffToGitJSONDSL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import { GitJSONDSL } from "../../dsl/GitDSL"
*/

export const diffToGitJSONDSL = (diff: string, commits: GitCommit[]): GitJSONDSL => {
const fileDiffs: any[] = parseDiff(diff)
const fileDiffs: parseDiff.File[] = parseDiff(diff)

const addedDiffs = fileDiffs.filter((diff: any) => diff["new"])
const removedDiffs = fileDiffs.filter((diff: any) => diff["deleted"])
const modifiedDiffs = fileDiffs.filter((diff: any) => !includes(addedDiffs, diff) && !includes(removedDiffs, diff))
const addedDiffs = fileDiffs.filter((diff: parseDiff.File) => diff.new == true) as any[]
const removedDiffs = fileDiffs.filter((diff: parseDiff.File) => diff.deleted == true) as any[]
const modifiedDiffs = fileDiffs.filter(
(diff: any) => !includes(addedDiffs, diff) && !includes(removedDiffs, diff)
) as any[]

return {
// Work around for danger/danger-js#807
Expand Down
10 changes: 10 additions & 0 deletions source/platforms/github/GitHubAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const limit = pLimit(25)
export interface GitHubFile {
filename: string
patch: string
status: string
}

// Note that there are parts of this class which don't seem to be
Expand Down Expand Up @@ -373,8 +374,17 @@ export class GitHubAPI {
// This is a hack to get the file patch into a format that parse-diff accepts
// as the GitHub API for listing pull request files is missing file names in the patch.
function prefixedPatch(file: GitHubFile): string {
let fileMode = ""
if (file.status == "added") {
fileMode = "new file mode"
} else if (file.status == "removed") {
fileMode = "deleted file mode"
} else if (file.status == "modified") {
fileMode = "modified file mode"
}
return `
diff --git a/${file.filename} b/${file.filename}
${fileMode} 0
--- a/${file.filename}
+++ b/${file.filename}
${file.patch}
Expand Down

0 comments on commit 6883bcf

Please sign in to comment.