-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Make core independent from the git client. (#171)
- Loading branch information
1 parent
990ee45
commit 4094bb9
Showing
4 changed files
with
81 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const gitRawCommits = require('git-raw-commits') | ||
const splitLines = require('split-lines') | ||
const { promisify } = require('util') | ||
const gitSemverTags = require('git-semver-tags') | ||
const through = require('through2') | ||
const concat = require('concat-stream') | ||
|
||
const COMMIT_FORMAT = '%n%H%n%an%n%cI%n%s%n%b' | ||
|
||
function parseCommit(commit) { | ||
const lines = splitLines(commit) | ||
const [hash, author, date, subject, ...body] = lines.splice( | ||
1, | ||
lines.length - 2 | ||
) | ||
return { | ||
hash, author, date, subject, body, | ||
} | ||
} | ||
|
||
function getCommits(from, to) { | ||
return new Promise(resolve => { | ||
gitRawCommits({ | ||
format: COMMIT_FORMAT, | ||
from, | ||
to, | ||
}) | ||
.pipe( | ||
through.obj((data, enc, next) => { | ||
next(null, parseCommit(data.toString())) | ||
}) | ||
) | ||
.pipe( | ||
concat(data => { | ||
resolve(data) | ||
}) | ||
) | ||
}) | ||
} | ||
|
||
const getTags = promisify(gitSemverTags) | ||
|
||
module.exports = { | ||
getTags, | ||
getCommits, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters