Skip to content

Commit

Permalink
(refactor): split out a gexec func to DRY up a bit
Browse files Browse the repository at this point in the history
- the gitexec.exec function is always called on process.cwd() and
  always uses split2() as its first pipe
  - and it should be used as such too
  - and all the piping can get a bit confusing / tunnel-visiony
  - so handle those two automatically in a separate func
  • Loading branch information
agilgur5 committed Jul 22, 2019
1 parent 7932463 commit 3540a26
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions changelog-maker.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ function onCommitList (list) {
})}) // eslint-disable-line brace-style, block-spacing
}

// simple wrapper around gitexec.exec for normal DRY usage
function gexec (cmd) {
return gitexec.exec(process.cwd(), cmd)
.pipe(split2())
}

// convert a Stream into a ListStream, then List, then Promisify that List
function streamToPromList (stream) {
return new Promise((resolve, reject) => {
Expand All @@ -140,20 +146,17 @@ function getRefs () {
}

return Promise.all([
streamToPromList(gitexec.exec(process.cwd(), startRefCmd)
.pipe(split2()))
streamToPromList(gexec(startRefCmd))
.then((list) => list.join('\n')),
streamToPromList(gitexec.exec(process.cwd(), endRefCmd)
.pipe(split2()))
streamToPromList(gexec(endRefCmd))
.then((list) => list.join('\n'))
])
}

// print the changelog from start ref to end ref
function printChangelog (startRef, endRef) {
const logCmd = `git log --pretty=full ${startRef}...${endRef}`
return streamToPromList(gitexec.exec(process.cwd(), logCmd)
.pipe(split2())
return streamToPromList(gexec(logCmd)
.pipe(commitStream(ghId.user, ghId.repo)))
.then(onCommitList)
}
Expand Down

0 comments on commit 3540a26

Please sign in to comment.