Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | 4x 4x 4x 141x 4x 7x 7x 7x 7x 7x 7x 7x 4x 4x 4x 4x 5x 3x 4x 4x 4x 27x 4x 4x 2x 4x 37x 4x 4x 4x 1x 4x 3x 4x 4x 4x 4x 4x | import fs from "fs" import gitlog from "gitlog" import read from "read-data" import { isString, entries, filter, I, join, pipe, map, reject, merge, curry, chain, fork, isObject } from "f-utility" import chalk from "chalk" import { encase, encaseN2 } from "fluture" // import { trace } from "xtrace" import { CHARACTER_LITERALS, ARGV_CONFIG, IT_ONLY_WORKS_IN_GIT_REPOS, MAKE_A_GITPARTYRC_FILE, BASE_CONFIG_FILE, PARTYFILE } from "./constants" import { filterByStringPattern } from "./filters" import { canonize } from "./alias" import { colorize } from "./print" import { stripDoubleBackslash, sortByDate, macroLens, j2, binaryCallback, log, warn, preferredProp, unaryCallbackToFuture, fileOrError, fileExists } from "./utils" import { isAMergeCommit } from "./filters" import { printLegend } from "./legend" import { collapseSuccessiveSameAuthor, insertBanners } from "./grouping" import { addAnalysisPerCommit, addTimestampPerCommit, addAliasesPerCommit, convertStatusAndFilesPerCommit } from "./per-commit" import { DEFAULT_CONFIG } from "./constants" const { NEWLINE } = CHARACTER_LITERALS const gotLog = encase(gitlog) /** @method perCommit @param {Object} lookup - the legend @param {Object} x - the commit object @return {Object} an updated object */ const perCommit = curry((timezone, lookup, x) => pipe( addTimestampPerCommit(timezone), addAliasesPerCommit, macroLens(convertStatusAndFilesPerCommit, `changes`), addAnalysisPerCommit(lookup) )(x) ) /** @method partyData @param {Object} config = the configuration object @param {Object} lookup = the legend object @param {Array} data - a list of commits @return {Array} an augmented list of commits */ export const partyData = curry((config, lookup, data) => { const grab = preferredProp(lookup, config, false) const filterMergeCommits = grab(ARGV_CONFIG.alias.m) const timezone = grab(ARGV_CONFIG.alias.t) || `utc` const collapseAuthors = grab(ARGV_CONFIG.alias.a[0]) const f = grab(ARGV_CONFIG.alias.f) const hasStringFilter = f && isString(f) && f.length > 0 return pipe( sortByDate, filterMergeCommits ? reject(isAMergeCommit) : I, map(perCommit(timezone, lookup)), hasStringFilter ? filterByStringPattern(f) : I, collapseAuthors ? collapseSuccessiveSameAuthor(lookup) : I, insertBanners )(data) }) /** @method partyPrint @param {Object} config - the configuration object @param {Object} lookup - the legend object @param {Array} input - the commits @return {string} colorized and stringified commits */ export const partyPrint = curry((config, lookup, input) => pipe( map(colorize(config, lookup)), join(NEWLINE) )(input) ) /** @method prependLegend @param {Object} lookup - the legend object @param {Array} x - the commits @return {string} colorized and stringified commits */ const prependLegend = curry((lookup, x) => printLegend(lookup) + NEWLINE + x) /** @method sideEffect @param {Function} effect - function to call @param {Object} y - alias structure @return {any} anything */ export const sideEffect = curry((effect, y) => pipe( entries, map( ([k, v]) => (Array.isArray(v) ? v.map(x => effect(k, x)) : effect(k, v)) ) )(y) ) /** @method sideEffectCanonize @param {Object} x - alias structure @return {null} nothing */ /* istanbul ignore next */ export const sideEffectCanonize = sideEffect(canonize) export const generateReport = curry((config, lookup, data) => { const { aliases = {} } = lookup // TODO: replace this with something that is a more explicitly managed side-effect /* istanbul ignore next */ sideEffectCanonize(aliases) const filteredLookup = filter(z => z && z.matches, lookup) return pipe( partyData(config, filteredLookup), config.j ? j2 : pipe( partyPrint(config, filteredLookup), prependLegend(filteredLookup) ) )(data) }) export const processGitCommits = curry((config, lookup) => pipe( gotLog, map(generateReport(config, lookup)) )(config) ) // || v.filter) // filter: v.filter ? v.filter : null export const remapConfigData = map( v => isObject(v) && v.matches ? merge(v, { fn: chalk[v.color], matches: v.matches.map(stripDoubleBackslash) }) : v ) /* istanbul ignore next */ export const writeFile = binaryCallback( /* istanbul ignore next */ fs.writeFile.bind(fs), /* istanbul ignore next */ e => log(e || `Wrote to file`) ) export const reader = unaryCallbackToFuture(read.yaml) export const processData = curry((config, F) => chain( pipe( remapConfigData, processGitCommits(merge(DEFAULT_CONFIG, config)) ) )(F) ) /** @method handleKnownBadThings @param {Error} e - an error @return {undefined} */ export const handleKnownBadThings = e => { // TODO: really this function ought to be replaced Left if (e) { /* istanbul ignore next */ if (e.code && e.path && e.code === `ENOENT`) { if (e.path.substr(e.path.lastIndexOf(`/`)) === `/${PARTYFILE}`) { const x = new Error(MAKE_A_GITPARTYRC_FILE) /* istanbul ignore next */ warn(x) return x /* istanbul ignore next */ } else if (e.path === `.git/index`) { const y = new Error(IT_ONLY_WORKS_IN_GIT_REPOS) /* istanbul ignore next */ warn(y) return y } } /* istanbul ignore next */ warn(e) } } /* istanbul ignore next */ export const warnWriteOrLog = curry( /* istanbul ignore next */ ({ o }, F) => /* istanbul ignore next */ fork(handleKnownBadThings, o ? writeFile(o) : log)(F) ) /* istanbul ignore next */ /** @method processAndPrintWithConfig @param {Object} config - a configuration object @param {Object} input - hashes @return {Future} future result */ export const processAndPrintWithConfig = curry( /* istanbul ignore next */ (config, input) => /* istanbul ignore next */ pipe( // TODO: really what we want is a Future(Either) here, probably i => fileOrError(`.git/index`).and(reader(i)), processData(config), warnWriteOrLog(config) )(input) ) /** @method writeConfigFile @returns {Future} config file */ export const writeConfigFile = () => encaseN2(fs.writeFile)(PARTYFILE, BASE_CONFIG_FILE, `utf8`) /** @method ifNoConfig @param {function} x - a future returning function @return {Future} future value */ export const ifNoConfig = x => () => fileExists(PARTYFILE).or(x()) /** @method createADefaultConfigFile @return {undefined} undefined */ export const createADefaultConfigFile = ifNoConfig(writeConfigFile) |