-
-
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.
✨ Generate changelog for the next release (#8)
- Loading branch information
1 parent
c177349
commit 2d783e4
Showing
7 changed files
with
139 additions
and
34 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,48 @@ | ||
const gitRawCommits = require('git-raw-commits') | ||
const gitSemverTags = require('git-semver-tags') | ||
const through = require('through2') | ||
const concat = require('concat-stream') | ||
const { promisify } = require('util') | ||
|
||
const { parseCommit } = require('./parser') | ||
|
||
const gitSemverTagsAsync = promisify(gitSemverTags) | ||
|
||
const COMMIT_FORMAT = '%n%H%n%cI%n%s%n%b' | ||
|
||
function changelog() { | ||
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(JSON.stringify(data)) | ||
resolve(data) | ||
})) | ||
}) | ||
} | ||
|
||
async function generateChangelog() { | ||
let previousTag = '' | ||
const result = {} | ||
const tags = await gitSemverTagsAsync() | ||
|
||
if (tags.length > 0) { | ||
await Promise.all(tags.map(async tag => { | ||
const commits = await getCommits(previousTag, tag) | ||
|
||
result[tag] = { commits } | ||
previousTag = tag | ||
})) | ||
} | ||
|
||
result.next = { commits: await getCommits(previousTag) } | ||
|
||
return result | ||
} | ||
|
||
module.exports = { | ||
changelog, | ||
generateChangelog, | ||
} |
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
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