Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: cookpete/auto-changelog
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.3.0
Choose a base ref
...
head repository: cookpete/auto-changelog
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.4.0
Choose a head ref
  • 9 commits
  • 11 files changed
  • 5 contributors

Commits on May 23, 2021

  1. Bump packages

    cookpete committed May 23, 2021
    Copy the full SHA
    9d271fc View commit details

Commits on Feb 3, 2022

  1. Copy the full SHA
    3e25b8c View commit details
  2. Add ending-version option

    Fixes #209
    cmastrandrea authored and cookpete committed Feb 3, 2022
    Copy the full SHA
    c2bb8c5 View commit details
  3. --ending-version fixes

    cookpete committed Feb 3, 2022
    Copy the full SHA
    dbd36d5 View commit details
  4. feat(commits.js): added niceDate format of commits (#206)

    * feat(commits.js): added niceDate format of commits
    
    * Tweak niceDate logic
    
    * Update test data
    
    Co-authored-by: Pete Cook <pete@cookpete.com>
    thkruz and cookpete authored Feb 3, 2022
    Copy the full SHA
    73a2524 View commit details
  5. Copy the full SHA
    66e554b View commit details
  6. Logical handling of --starting-version (#227)

    * Logical handling of --starting-version
    
    Fixes #221
    
    * Tidy up
    
    Co-authored-by: Pete Cook <pete@cookpete.com>
    webketje and cookpete authored Feb 3, 2022
    Copy the full SHA
    417354c View commit details
  7. yarn upgrade

    cookpete committed Feb 3, 2022
    Copy the full SHA
    c227823 View commit details
  8. 2.4.0

    cookpete committed Feb 3, 2022
    Copy the full SHA
    94266e6 View commit details
Showing with 1,682 additions and 1,435 deletions.
  1. +14 −0 CHANGELOG.md
  2. +1 −0 README.md
  3. +15 −15 package.json
  4. +3 −2 src/commits.js
  5. +2 −0 src/run.js
  6. +23 −5 src/tags.js
  7. +1 −1 test/commits.js
  8. +17 −0 test/data/commits-no-remote.js
  9. +17 −0 test/data/commits.js
  10. +52 −1 test/tags.js
  11. +1,537 −1,411 yarn.lock
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -4,8 +4,22 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [v2.4.0](https://github.com/cookpete/auto-changelog/compare/v2.3.0...v2.4.0)

- Logical handling of --starting-version [`#227`](https://github.com/cookpete/auto-changelog/pull/227)
- Trim commit subject [`#225`](https://github.com/cookpete/auto-changelog/pull/225)
- feat(commits.js): added niceDate format of commits [`#206`](https://github.com/cookpete/auto-changelog/pull/206)
- Logical handling of --starting-version (#227) [`#221`](https://github.com/cookpete/auto-changelog/issues/221)
- Add ending-version option [`#209`](https://github.com/cookpete/auto-changelog/issues/209)
- Do not sort tags when sorting via --append-git-tag [`#197`](https://github.com/cookpete/auto-changelog/issues/197) [`#210`](https://github.com/cookpete/auto-changelog/pull/210)
- Bump packages [`9d271fc`](https://github.com/cookpete/auto-changelog/commit/9d271fc5cad1f8ab19c4fd9210f3a78ca52faf25)
- yarn upgrade [`c227823`](https://github.com/cookpete/auto-changelog/commit/c2278230c5c1bc0b0491cf0f5da35b9e33c7384b)
- --ending-version fixes [`dbd36d5`](https://github.com/cookpete/auto-changelog/commit/dbd36d52f3ecb32d71af54be9b3167ade89301f1)

#### [v2.3.0](https://github.com/cookpete/auto-changelog/compare/v2.2.1...v2.3.0)

> 23 May 2021
- feat: add support for minor/preminor versions for custom templates [`#185`](https://github.com/cookpete/auto-changelog/pull/185)
- Feat: add sortCommits by subject and subject-desc [`#186`](https://github.com/cookpete/auto-changelog/pull/186)
- Remove --sort=-creatordate from git tag logic [`#196`](https://github.com/cookpete/auto-changelog/issues/196)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@ Options:
--tag-prefix [prefix] # prefix used in version tags, default: v
--starting-version [tag] # specify earliest version to include in changelog
--starting-date [yyyy-mm-dd] # specify earliest date to include in changelog
--ending-version [tag] # specify latest version to include in changelog
--sort-commits [property] # sort commits by property [relevance, date, date-desc, subject, subject-desc], default: relevance
--release-summary # display tagged commit message body as release summary
--unreleased-only # only output unreleased changes
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "auto-changelog",
"version": "2.3.0",
"version": "2.4.0",
"description": "Command line tool for generating a changelog from git tags and commit history",
"main": "./src/index.js",
"bin": {
@@ -43,25 +43,25 @@
],
"license": "MIT",
"dependencies": {
"commander": "^5.0.0",
"handlebars": "^4.7.3",
"node-fetch": "^2.6.0",
"commander": "^7.2.0",
"handlebars": "^4.7.7",
"node-fetch": "^2.6.1",
"parse-github-url": "^1.0.2",
"semver": "^6.3.0"
"semver": "^7.3.5"
},
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/register": "^7.9.0",
"@babel/core": "^7.14.3",
"@babel/register": "^7.13.16",
"babel-plugin-istanbul": "^6.0.0",
"babel-plugin-rewire": "^1.2.0",
"chai": "^4.2.0",
"codecov": "^3.6.5",
"cross-env": "^7.0.2",
"markdownlint-cli": "^0.22.0",
"mocha": "^7.1.1",
"nyc": "^15.0.0",
"snazzy": "^8.0.0",
"standard": "^14.3.3"
"chai": "^4.3.4",
"codecov": "^3.8.2",
"cross-env": "^7.0.3",
"markdownlint-cli": "^0.30.0",
"mocha": "^9.2.0",
"nyc": "^15.1.0",
"snazzy": "^9.0.0",
"standard": "^16.0.3"
},
"babel": {
"env": {
5 changes: 3 additions & 2 deletions src/commits.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const semver = require('semver')
const { cmd, isLink, encodeHTML, replaceText, getGitVersion } = require('./utils')
const { cmd, isLink, encodeHTML, niceDate, replaceText, getGitVersion } = require('./utils')

const COMMIT_SEPARATOR = '__AUTO_CHANGELOG_COMMIT_SEPARATOR__'
const MESSAGE_SEPARATOR = '__AUTO_CHANGELOG_MESSAGE_SEPARATOR__'
@@ -48,6 +48,7 @@ const parseCommit = (commit, options = {}) => {
author,
email,
date: new Date(date).toISOString(),
niceDate: niceDate(date),
subject: replaceText(getSubject(message), options),
message: message.trim(),
fixes: getFixes(message, author, options),
@@ -65,7 +66,7 @@ const getSubject = (message) => {
if (!message.trim()) {
return '_No commit message_'
}
return message.match(/[^\n]+/)[0]
return message.match(/[^\n]+/)[0].trim()
}

const getStats = (stats) => {
2 changes: 2 additions & 0 deletions src/run.js
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@ const getOptions = async argv => {
.option('--tag-prefix <prefix>', 'prefix used in version tags')
.option('--starting-version <tag>', 'specify earliest version to include in changelog')
.option('--starting-date <yyyy-mm-dd>', 'specify earliest date to include in changelog')
.option('--ending-version <tag>', 'specify latest version to include in changelog')
.option('--sort-commits <property>', `sort commits by property [relevance, date, date-desc], default: ${DEFAULT_OPTIONS.sortCommits}`)
.option('--release-summary', 'use tagged commit message body as release summary')
.option('--unreleased-only', 'only output unreleased changes')
@@ -58,6 +59,7 @@ const getOptions = async argv => {
.option('--stdout', 'output changelog to stdout')
.version(version)
.parse(argv)
.opts()

const pkg = await readJson(PACKAGE_FILE)
const packageOptions = pkg ? pkg[PACKAGE_OPTIONS_KEY] : null
28 changes: 23 additions & 5 deletions src/tags.js
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ const fetchTags = async (options, remote) => {
.split('\n')
.map(parseTag(options))
.filter(isValidTag(options))
.sort(sortTags)
.sort(sortTags(options))

const { latestVersion, unreleased, unreleasedOnly, getCompareLink } = options
if (latestVersion || unreleased || unreleasedOnly) {
@@ -28,18 +28,33 @@ const fetchTags = async (options, remote) => {
}

const enriched = tags.map(enrichTag(options))
return enriched.slice(0, getLimit(enriched, options))
return enriched.slice(getStartIndex(enriched, options), getEndIndex(enriched, options))
}

const getLimit = (tags, { unreleasedOnly, startingVersion, startingDate }) => {
const getStartIndex = (tags, { endingVersion }) => {
if (endingVersion) {
const index = tags.findIndex(({ tag }) => tag === endingVersion)
if (index !== -1) {
return index
}
}
return 0
}

const getEndIndex = (tags, { unreleasedOnly, startingVersion, startingDate, tagPrefix }) => {
if (unreleasedOnly) {
return 1
}
if (startingVersion) {
const index = tags.findIndex(({ tag }) => tag === startingVersion)
const semverStartingVersion = inferSemver(startingVersion.replace(tagPrefix, ''))
const index = tags.findIndex(({ tag }) => {
return tag === startingVersion || tag === semverStartingVersion
})
if (index !== -1) {
return index + 1
}
// Fall back to nearest version lower than startingVersion
return tags.findIndex(({ version }) => semver.lt(version, semverStartingVersion))
}
if (startingDate) {
return tags.filter(t => t.isoDate >= startingDate).length
@@ -87,7 +102,10 @@ const isValidTag = ({ tagPattern }) => ({ tag, version }) => {
return semver.valid(version)
}

const sortTags = ({ version: a }, { version: b }) => {
const sortTags = ({ appendGitTag }) => ({ version: a }, { version: b }) => {
if (/--sort/.test(appendGitTag)) {
return 0
}
if (semver.valid(a) && semver.valid(b)) {
return semver.rcompare(a, b)
}
2 changes: 1 addition & 1 deletion test/commits.js
Original file line number Diff line number Diff line change
@@ -311,7 +311,7 @@ describe('getMerge', () => {

describe('getSubject', () => {
it('returns commit subject', () => {
const message = 'Commit message\n\nCloses ABC-1234'
const message = ' Commit message\n\nCloses ABC-1234'
expect(getSubject(message)).to.equal('Commit message')
})

17 changes: 17 additions & 0 deletions test/data/commits-no-remote.js
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ module.exports = [
"author": "Example Author",
"email": "email@example.com",
"date": "2015-12-29T21:57:19.000Z",
"niceDate": "29 December 2015",
"subject": "Unreleased commit",
"message": "Unreleased commit\n\nFixes #6",
"fixes": [
@@ -27,6 +28,7 @@ module.exports = [
"author": "Example Author",
"email": "email@example.com",
"date": "2015-12-15T12:03:09.000Z",
"niceDate": "15 December 2015",
"subject": "1.0.0",
"message": "1.0.0\n\nThis is my major release description.\n\n- And a bullet point",
"fixes": null,
@@ -43,6 +45,7 @@ module.exports = [
"author": "Example Author",
"email": "email@example.com",
"date": "2015-12-29T21:57:19.000Z",
"niceDate": "29 December 2015",
"subject": "Some breaking change",
"message": "Some breaking change",
"fixes": null,
@@ -59,6 +62,7 @@ module.exports = [
"author": "Example Author",
"email": "email@example.com",
"date": "2015-12-29T21:19:17.000Z",
"niceDate": "29 December 2015",
"subject": "0.1.0",
"message": "0.1.0",
"fixes": null,
@@ -75,6 +79,7 @@ module.exports = [
"author": "Example Author",
"email": "email@example.com",
"date": "2015-12-29T21:19:19.000Z",
"niceDate": "29 December 2015",
"subject": "Another commit that fixes nothing but with less changes",
"message": "Another commit that fixes nothing but with less changes",
"fixes": null,
@@ -91,6 +96,7 @@ module.exports = [
"author": "Example Author",
"email": "email@example.com",
"date": "2015-12-29T21:18:19.000Z",
"niceDate": "29 December 2015",
"subject": "Commit that fixes nothing with `backticks` and &lt;html&gt;",
"message": "Commit that fixes nothing with `backticks` and &lt;html&gt;",
"fixes": null,
@@ -107,6 +113,7 @@ module.exports = [
"author": "Example Author",
"email": "email@example.com",
"date": "2015-12-28T21:17:17.000Z",
"niceDate": "28 December 2015",
"subject": "0.0.2",
"message": "0.0.2",
"fixes": null,
@@ -123,6 +130,7 @@ module.exports = [
"author": "Example Author",
"email": "email@example.com",
"date": "2015-12-24T20:29:22.000Z",
"niceDate": "24 December 2015",
"subject": "Merge pull request #5 from repo/branch",
"message": "Merge pull request #5 from repo/branch\n\nShould not parse #4 in PR title",
"fixes": null,
@@ -139,6 +147,7 @@ module.exports = [
"author": "Example Author",
"email": "email@example.com",
"date": "2015-12-24T20:29:22.000Z",
"niceDate": "24 December 2015",
"subject": "Merge pull request #5 from repo/branch",
"message": "Merge pull request #5 from repo/branch\n\nShould not parse #4 in PR title",
"fixes": null,
@@ -153,6 +162,7 @@ module.exports = [
"author": "Example Author",
"email": "email@example.com",
"date": "2015-12-29T11:35:54.000Z",
"niceDate": "29 December 2015",
"subject": "Merge remote-tracking branch 'random-branch' into master",
"message": "Merge remote-tracking branch 'random-branch' into master",
"fixes": null,
@@ -169,6 +179,7 @@ module.exports = [
"author": "Example Author",
"email": "email@example.com",
"date": "2015-12-28T11:35:54.000Z",
"niceDate": "28 December 2015",
"subject": "Commit 4 fixes #4 in the subject",
"message": "Commit 4 fixes #4 in the subject\n\nWith some extra notes here",
"fixes": [
@@ -191,6 +202,7 @@ module.exports = [
"author": "Example Author",
"email": "email@example.com",
"date": "2015-12-15T12:03:09.000Z",
"niceDate": "15 December 2015",
"subject": "0.0.1",
"message": "0.0.1",
"fixes": null,
@@ -207,6 +219,7 @@ module.exports = [
"author": "Example Author",
"email": "email@example.com",
"date": "2015-12-15T11:37:05.000Z",
"niceDate": "15 December 2015",
"subject": "Merge pull request #3 from repo/branch",
"message": "Merge pull request #3 from repo/branch\n\nThird commit with same name as PR",
"fixes": null,
@@ -223,6 +236,7 @@ module.exports = [
"author": "Example Author",
"email": "email@example.com",
"date": "2015-12-15T11:37:05.000Z",
"niceDate": "15 December 2015",
"subject": "Merge pull request #3 from repo/branch",
"message": "Merge pull request #3 from repo/branch\n\nThird commit with same name as PR",
"fixes": null,
@@ -237,6 +251,7 @@ module.exports = [
"author": "Example Author",
"email": "email@example.com",
"date": "2015-12-15T11:31:06.000Z",
"niceDate": "15 December 2015",
"subject": "Third commit with same name as PR",
"message": "Third commit with same name as PR",
"fixes": null,
@@ -253,6 +268,7 @@ module.exports = [
"author": "Example Author",
"email": "email@example.com",
"date": "2015-12-15T11:31:06.000Z",
"niceDate": "15 December 2015",
"subject": "Second commit",
"message": "Second commit\n\nResolves #1 and fixes https://github.com/user/repo/issues/2",
"fixes": [
@@ -280,6 +296,7 @@ module.exports = [
"author": "Example Author",
"email": "email@example.com",
"date": "2015-12-14T17:06:12.000Z",
"niceDate": "14 December 2015",
"subject": "First commit",
"message": "First commit",
"fixes": null,
Loading