Skip to content

Commit

Permalink
Add support for format of "Keep a Changelog" (#11)
Browse files Browse the repository at this point in the history
* Add support for format of "Keep a Changelog"

* Advertise support of "KeepAChangelog" to README.md

* Add support for Windows line endings
  • Loading branch information
koppor authored and MoOx committed Dec 6, 2017
1 parent 874c402 commit cf50e4e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,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

0 comments on commit cf50e4e

Please sign in to comment.