Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for format of "Keep a Changelog" #11

Merged
merged 3 commits into from
Dec 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

You need:

- a CHANGELOG with the following format:
- a CHANGELOG following the format of [keep a changelog](http://keepachangelog.com/en/1.0.0/) or a CHANGELOG with the following format:
```md
# X.Y.Z - ...

Expand Down
13 changes: 9 additions & 4 deletions github-release-from-changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,27 @@ if (tagMatches === null) {
// changelog
var body = []
var start
const changelogLines = changelog.replace(/\r\n/g, "\n").split("\n")
// determine whether the log format of http://keepachangelog.com/en/1.0.0/: check the first line and check if there is a second level heading linking to the version diff
const isKeepAChangelogFormat = (changelogLines[0] === "# Changelog") && (changelog.indexOf("\n## [" + version + "]") !== -1)
// console.log(isKeepAChangelogFormat);

// read from # version to the next # .*
changelog.split("\n").some(function(line, i) {
changelogLines.some(function(line, i) {
// start with the # version
if (!start && line.indexOf("# " + version) === 0) {
if (!start && ((line.indexOf("# " + version) === 0) || (isKeepAChangelogFormat && line.indexOf("## [") === 0))) {
start = true
}
// end with another # version
else if (start && line.indexOf("# ") === 0) {
else if (start && (line.indexOf("# ") === 0 || (isKeepAChangelogFormat && line.indexOf("## [") === 0))) {
return true
}
// between start & end, collect lines
else if (start) {
body.push(line)
}
})
body = body.join("\n")
body = body.join("\n").trim()

// prepare release data
var releaseOptions = {
Expand Down