import { assocObj } from "@thi.ng/transducers/assoc-obj" ; import { comp } from "@thi.ng/transducers/comp" ; import { filter } from "@thi.ng/transducers/filter" ; import { iterator } from "@thi.ng/transducers/iterator" ; import { map } from "@thi.ng/transducers/map" ; import { mapcat } from "@thi.ng/transducers/mapcat" ; import { partitionBy } from "@thi.ng/transducers/partition-by" ; import { transduce } from "@thi.ng/transducers/transduce" ; import { zip } from "@thi.ng/transducers/zip" ; import { execSync } from "child_process" ; import { resolve } from "path" ; import type { Commit } from "../common/api" ; param repoPath const gitLog = ( repoPath ) => execSync ( `git log --pretty=format:"%ad~~%an~~%h~~%s" --shortstat --date=iso-strict` , { cwd : resolve ( repoPath ) } ) . toString ( ) . trim ( ) ; param log const parseLog = ( [ log ] ) : Partial < Commit > => { const [ date , author , sha , msg ] = log . split ( "~~" ) ; return { date , author , sha , msg } ; } ; param log const parseStats = ( [ _ , stats ] ) : Partial < Commit > | null => stats ? transduce ( map ( ( [ k , v ] ) => < [ string , number ] > [ k , parseInt ( v ) ] ) , assocObj ( ) , zip ( [ "files" , "add" , "del" ] , stats . split ( "," ) ) ) : null ; param repoPath export const repoCommits = ( repoPath ) => iterator ( comp ( map ( gitLog ) , mapcat ( ( x ) => x . split ( "\n" ) ) , partitionBy ( ( x ) => x . indexOf ( "~~Merge " ) !== - 1 ? Math . random ( ) : x . length > 0 ? 1 : 0 ) , filter ( ( x ) => x [ 0 ] . length > 0 ) , map ( ( commit ) => < Commit > { ... parseLog ( commit ) , ... parseStats ( commit ) , } ) ) , [ repoPath ] ) ;