Skip to content

Commit

Permalink
add path pattern filter option to linesOfCode
Browse files Browse the repository at this point in the history
  • Loading branch information
MelvinVermeer committed Dec 23, 2020
1 parent f502880 commit fe53d94
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion source/dsl/GitDSL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,5 @@ export interface GitDSL extends GitJSONDSL {
/**
* Offers the overall lines of code added/removed in the diff
*/
linesOfCode(): Promise<number | null>
linesOfCode(pattern?: string): Promise<number | null>
}
12 changes: 8 additions & 4 deletions source/platforms/git/gitJSONToGitDSL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import * as jsonDiff from "fast-json-patch"
import jsonpointer from "jsonpointer"
import JSON5 from "json5"

import micromatch from "micromatch"

import { GitDSL, JSONPatchOperation, GitJSONDSL, StructuredDiff } from "../../dsl/GitDSL"
import chainsmoker from "../../commands/utils/chainsmoker"

Expand Down Expand Up @@ -155,11 +157,13 @@ export const gitJSONToGitDSL = (gitJSONRep: GitJSONDSL, config: GitJSONToGitDSLC
}, Object.create(null))
}

const linesOfCode = async () => {
const linesOfCode = async (pattern?: string) => {
const isPatternMatch = (path: string) => pattern === undefined || micromatch.isMatch(path, pattern)

const [createdFilesDiffs, modifiedFilesDiffs, deletedFilesDiffs] = await Promise.all([
Promise.all(gitJSONRep.created_files.map(path => diffForFile(path))),
Promise.all(gitJSONRep.modified_files.map(path => diffForFile(path))),
Promise.all(gitJSONRep.deleted_files.map(path => diffForFile(path))),
Promise.all(gitJSONRep.created_files.filter(isPatternMatch).map(path => diffForFile(path))),
Promise.all(gitJSONRep.modified_files.filter(isPatternMatch).map(path => diffForFile(path))),
Promise.all(gitJSONRep.deleted_files.filter(isPatternMatch).map(path => diffForFile(path))),
])

let additions = createdFilesDiffs
Expand Down

0 comments on commit fe53d94

Please sign in to comment.