Skip to content

Commit

Permalink
now structuredDiffForFile is well-typed
Browse files Browse the repository at this point in the history
  • Loading branch information
berlysia committed Jan 25, 2022
1 parent 0b5865f commit dc54972
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 13 deletions.
1 change: 1 addition & 0 deletions scripts/danger-dts.ts
Expand Up @@ -14,6 +14,7 @@ const createDTS = () => {
import { Octokit as GitHub } from "@octokit/rest"
import { Gitlab } from "gitlab"
import { File } from "parse-diff"
`
const footer = ``
Expand Down
1 change: 0 additions & 1 deletion source/ambient.d.ts
@@ -1,4 +1,3 @@
declare module "parse-diff"
declare module "lodash.includes"
declare module "lodash.find"
declare module "lodash.isobject"
Expand Down
3 changes: 2 additions & 1 deletion source/danger.d.ts
Expand Up @@ -4,6 +4,7 @@

import { Octokit as GitHub } from "@octokit/rest"
import { Gitlab } from "gitlab"
import { File } from "parse-diff"

type MarkdownString = string
// TODO: extract out from BitBucket specifically, or create our own type
Expand Down Expand Up @@ -809,7 +810,7 @@ interface TextDiff {
/** Git diff sliced into chunks */
interface StructuredDiff {
/** Git diff chunks */
chunks: any[]
chunks: File["chunks"]
}

/** The results of running a JSON patch */
Expand Down
3 changes: 2 additions & 1 deletion source/dsl/GitDSL.ts
Expand Up @@ -2,6 +2,7 @@

import { GitCommit } from "./Commit"
import { Chainsmoker } from "../commands/utils/chainsmoker"
import { File } from "parse-diff"

/** All Text diff values will be this shape */
export interface TextDiff {
Expand All @@ -20,7 +21,7 @@ export interface TextDiff {
/** Git diff sliced into chunks */
export interface StructuredDiff {
/** Git diff chunks */
chunks: any[]
chunks: File["chunks"]
}

/** The results of running a JSON patch */
Expand Down
12 changes: 2 additions & 10 deletions source/platforms/git/gitJSONToGitDSL.ts
Expand Up @@ -39,17 +39,9 @@ export interface GitJSONToGitDSLConfig {
getStructuredDiffForFile?: (base: string, head: string, filename: string) => Promise<GitStructuredDiff>
}

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

export interface Chunk {
changes: Changes
}
export type GitStructuredDiff = Pick<parseDiff.File, "chunks" | "from" | "to">[]

export type Changes = { type: "add" | "del" | "normal"; content: string }[]
export type Changes = parseDiff.Change[]

export const gitJSONToGitDSL = (gitJSONRep: GitJSONDSL, config: GitJSONToGitDSLConfig): GitDSL => {
const getFullDiff: ((base: string, head: string) => Promise<string>) | null = config.getStructuredDiffForFile
Expand Down

0 comments on commit dc54972

Please sign in to comment.