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: v1.0.3
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: v1.1.0
Choose a head ref
  • 16 commits
  • 20 files changed
  • 2 contributors

Commits on Nov 7, 2017

  1. Tidy options logic

    cookpete committed Nov 7, 2017
    Copy the full SHA
    34fcfaa View commit details
  2. Copy the full SHA
    9d2bd33 View commit details
  3. Tweak origin properties

    cookpete committed Nov 7, 2017
    Copy the full SHA
    9b956d5 View commit details
  4. Add origin tests

    cookpete committed Nov 7, 2017
    Copy the full SHA
    f50dced View commit details
  5. Copy the full SHA
    ba6c97c View commit details
  6. Update clean script

    cookpete committed Nov 7, 2017
    Copy the full SHA
    b2dc7bb View commit details
  7. Refactor run logic

    cookpete committed Nov 7, 2017
    Copy the full SHA
    3892183 View commit details
  8. Add run tests

    cookpete committed Nov 7, 2017
    Copy the full SHA
    a6ae95e View commit details
  9. Copy the full SHA
    f8b98b5 View commit details
  10. Copy the full SHA
    efd2986 View commit details
  11. Copy the full SHA
    436649e View commit details
  12. Copy the full SHA
    cb08984 View commit details
  13. Add util tests

    cookpete committed Nov 7, 2017
    Copy the full SHA
    0c5a093 View commit details

Commits on Nov 8, 2017

  1. Copy the full SHA
    ddcffe0 View commit details

Commits on Nov 9, 2017

  1. Support modifying commit limit with --commit-limit (#12)

    * Support modifying commit limit with --commit-limit
    
    * Tidy up commit limit logic
    eliperelman authored and cookpete committed Nov 9, 2017
    Copy the full SHA
    f970076 View commit details
  2. 1.1.0

    cookpete committed Nov 9, 2017
    4
    Copy the full SHA
    7086b70 View commit details
Showing with 322 additions and 117 deletions.
  1. +1 −1 .gitignore
  2. +17 −10 CHANGELOG.md
  3. +13 −5 README.md
  4. +5 −3 package.json
  5. +28 −0 scripts/generate-test-data.js
  6. +7 −7 src/commits.js
  7. +9 −1 src/index.js
  8. +3 −3 src/origin.js
  9. +11 −8 src/releases.js
  10. +29 −18 src/run.js
  11. +0 −10 src/template.js
  12. +9 −3 src/utils.js
  13. +2 −2 templates/compact.hbs
  14. +2 −2 templates/keepachangelog.hbs
  15. +22 −38 test/commits.js
  16. +14 −0 test/data/origins.js
  17. +56 −0 test/origin.js
  18. +6 −6 test/releases.js
  19. +47 −0 test/run.js
  20. +41 −0 test/utils.js
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules
npm-debug.log
/lib
/coverage
/test/coverage
27 changes: 17 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -3,11 +3,18 @@ All notable changes to this project will be documented in this file.

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

#### [v1.1.0](https://github.com/CookPete/auto-changelog/compare/v1.0.3...v1.1.0)
> 9 November 2017
- Support modifying commit limit with --commit-limit [`#12`](https://github.com/CookPete/auto-changelog/pull/12)
- Add util tests [`0c5a093`](https://github.com/CookPete/auto-changelog/commit/0c5a0936b9b84d2d417710ab82d282ebde598f97)
- Fix multiple issue URL parsing [`ddcffe0`](https://github.com/CookPete/auto-changelog/commit/ddcffe08fa2133547f37e9e896982531591cd852)
- Tweak removeIndentation util [`cb08984`](https://github.com/CookPete/auto-changelog/commit/cb08984453989ab0307020475525e114100d968f)

#### [v1.0.3](https://github.com/CookPete/auto-changelog/compare/v1.0.2...v1.0.3)
> 7 November 2017
- Fix pull request URL [`3f6daaa`](https://github.com/CookPete/auto-changelog/commit/3f6daaa35b3da08bafec0ef9229cb4b09bc1c9cb)
- Bump packages [`510c798`](https://github.com/CookPete/auto-changelog/commit/510c798fe6bb688234bb8b4eb3885055a47ee2bb)
- Fix version script [`f849dac`](https://github.com/CookPete/auto-changelog/commit/f849dac557b2c24512c553d9fccb93e1455a8c2e)
- Limit origin protocol to http or https [`51d3832`](https://github.com/CookPete/auto-changelog/commit/51d3832f02209b56499f209f822b442e601ef1a5)

#### [v1.0.2](https://github.com/CookPete/auto-changelog/compare/v1.0.1...v1.0.2)
> 31 October 2017
@@ -24,7 +31,7 @@ Generated by [auto-changelog](https://github.com/CookPete/auto-changelog).
- Update dependencies to enable Greenkeeper 🌴 [`#10`](https://github.com/CookPete/auto-changelog/pull/10)
- Refactor codebase [`dab29fb`](https://github.com/CookPete/auto-changelog/commit/dab29fb3a030ffe2799075ef46c70c734d8d2b89)
- Add greenkeeper-lockfile support [`126c6fb`](https://github.com/CookPete/auto-changelog/commit/126c6fbd054c16624ab39cbb51a2eab99bc832c6)
- Tweak readme badges [`bf73f55`](https://github.com/CookPete/auto-changelog/commit/bf73f555422ef5338455182b9649badc122bdadf)
- Remove dependency status badges [`bd072be`](https://github.com/CookPete/auto-changelog/commit/bd072bef982f4fe0d309c4f24a028b9e8db1513d)

#### [v0.3.6](https://github.com/CookPete/auto-changelog/compare/v0.3.5...v0.3.6)
> 23 October 2017
@@ -37,9 +44,9 @@ Generated by [auto-changelog](https://github.com/CookPete/auto-changelog).

#### [v0.3.4](https://github.com/CookPete/auto-changelog/compare/v0.3.3...v0.3.4)
> 5 October 2017
- Add code coverage [`786af11`](https://github.com/CookPete/auto-changelog/commit/786af11c841fe158fbb8eb3d6a0e2c0ee8b1a93a)
- Use async/await instead of promises [`dff4653`](https://github.com/CookPete/auto-changelog/commit/dff465371252ce6ab4cd05e49d4c41fd8d3bb37a)
- Remove need for array.find polyfill [`78a1cb8`](https://github.com/CookPete/auto-changelog/commit/78a1cb8ac9327ecb0efadffed037f90191bdce5a)
- Tweak version script [`152b85f`](https://github.com/CookPete/auto-changelog/commit/152b85f967d74a0f81cccac8ce6f5d5831f4d91b)

#### [v0.3.3](https://github.com/CookPete/auto-changelog/compare/v0.3.2...v0.3.3)
> 24 September 2017
@@ -55,14 +62,14 @@ Generated by [auto-changelog](https://github.com/CookPete/auto-changelog).
> 9 September 2016
- Improve origin URL parsing [`#2`](https://github.com/CookPete/auto-changelog/issues/2) [`#5`](https://github.com/CookPete/auto-changelog/issues/5)
- Remove semicolons [`2ff61e2`](https://github.com/CookPete/auto-changelog/commit/2ff61e2f6b415bd24cfdf1788a3a4239138e6aa2)
- More robust log separators [`adc1dcc`](https://github.com/CookPete/auto-changelog/commit/adc1dccb744335ed1b0cb52a32f23605f92bbe97)
- Improve error handling [`96b7666`](https://github.com/CookPete/auto-changelog/commit/96b7666e50126dc515bb7bf2f9a79090ad7d8806)
- Bump packages [`c6b1b18`](https://github.com/CookPete/auto-changelog/commit/c6b1b18fdef492a382732b173487c1cf3d42915c)
- Use template literal for success string [`017f884`](https://github.com/CookPete/auto-changelog/commit/017f884bea2bdca22f8b07ac36e0968efdaf18c0)

#### [v0.3.0](https://github.com/CookPete/auto-changelog/compare/v0.2.2...v0.3.0)
> 11 January 2016
- Add semicolons after class properties [`07b2de5`](https://github.com/CookPete/auto-changelog/commit/07b2de5131f4354565b2ba94a5fc181a1448b5c2)
- Remove unique issue filter [`11acb7e`](https://github.com/CookPete/auto-changelog/commit/11acb7e4a9f2782a95e0932917828646103bd85a)
- Add support for minimumChangeCount in templates [`612d80b`](https://github.com/CookPete/auto-changelog/commit/612d80b02cabbc2faeddd39c57bd086661932aef)
- Case insensitive issue URL parsing [`d152cf6`](https://github.com/CookPete/auto-changelog/commit/d152cf6fed739f956d9abae0bd67fee907577d8c)

#### [v0.2.2](https://github.com/CookPete/auto-changelog/compare/v0.2.1...v0.2.2)
> 2 January 2016
@@ -77,8 +84,8 @@ Generated by [auto-changelog](https://github.com/CookPete/auto-changelog).
#### [v0.2.0](https://github.com/CookPete/auto-changelog/compare/v0.1.1...v0.2.0)
> 2 January 2016
- Add support for specifying templates [`369b51e`](https://github.com/CookPete/auto-changelog/commit/369b51e9ff05bccba19cd09d9d519bca579bf972)
- Add FAQ to readme [`9351ad0`](https://github.com/CookPete/auto-changelog/commit/9351ad0b5f6e7f59e1b51b1c7ea1a3e7720dfbbc)
- Rearrange usage docs [`c6bfb0b`](https://github.com/CookPete/auto-changelog/commit/c6bfb0be0b429ce7f9697eb1097ec3e2288aff74)
- Start using compact changelog [`8cbac18`](https://github.com/CookPete/auto-changelog/commit/8cbac1857fb9c61a9227d01ba48bbd7a74b39697)
- Lint and test before versioning [`9df54b4`](https://github.com/CookPete/auto-changelog/commit/9df54b4bf898a7efdee3f702af71307f28dc7cec)

#### [v0.1.1](https://github.com/CookPete/auto-changelog/compare/v0.1.0...v0.1.1)
> 31 December 2015
@@ -89,8 +96,8 @@ Generated by [auto-changelog](https://github.com/CookPete/auto-changelog).
> 31 December 2015
- Add option for specifying output file [`#1`](https://github.com/CookPete/auto-changelog/issues/1)
- Add support for --package [`772fbb9`](https://github.com/CookPete/auto-changelog/commit/772fbb988f41d893bccd88417a2b5992543bc936)
- Update badges [`d17791f`](https://github.com/CookPete/auto-changelog/commit/d17791f478b7fc4a48877b5c79a1ce857223553a)
- Remove todo list from readme [`4446226`](https://github.com/CookPete/auto-changelog/commit/4446226048642ad19a7bfbc1c2f8040a6d15cbc3)
- Add newline at end of generated logs [`837d088`](https://github.com/CookPete/auto-changelog/commit/837d0883f71dea332a46d1ae49749e1bfdc5b8b1)
- Generate changelog on version [`fd6f230`](https://github.com/CookPete/auto-changelog/commit/fd6f2300433d7cb5f9434b2fe64e1f2d9823fc93)

#### v0.0.1
> 31 December 2015
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ If you are upgrading from `0.x`, the same options are still supported out of the
- The default template is now `compact`
- If you still want to use the [`keepachangelog`](http://keepachangelog.com) format, use `--template keepachangelog`
- Templates now use `-` instead of `*` for lists
- Up to 3 commits are now shown per release
- Up to 3 commits are now shown per release by default
- Unreleased changes are no longer listed by default, use `--unreleased` to include them
- [GitLab](https://gitlab.com) and [BitBucket](https://bitbucket.org) are now fully supported

@@ -43,6 +43,7 @@ Options:
-r, --remote [remote] # specify git remote to use for links, default: origin
-p, --package # use version from package.json as latest release
-u, --unreleased # include section for unreleased changes
-l, --commit-limit [count] # number of commits to display per release, default: 3
-V, --version # output the version number
-h, --help # output usage information

@@ -58,6 +59,12 @@ auto-changelog --template keepachangelog

# Write log using custom handlebars template in current directory
auto-changelog --template my-custom-template.hbs

# Change rendered commit limit to 5
auto-changelog --commit-limit 5

# Disable the commit limit, rendering all commits
auto-changelog --commit-limit false
```

You can also set options in `package.json`:
@@ -72,7 +79,8 @@ You can also set options in `package.json`:
"auto-changelog": {
"output": "HISTORY.md",
"template": "keepachangelog",
"unreleased": true
"unreleased": true,
"commitLimit": false
}
}
```
@@ -97,7 +105,7 @@ Add `auto-changelog -p; git add CHANGELOG.md` to the `version` scripts in your `
"auto-changelog": "*"
},
"scripts": {
"version": "auto-changelog -p; git add CHANGELOG.md"
"version": "auto-changelog -p && git add CHANGELOG.md"
}
}
```
@@ -126,9 +134,9 @@ My custom changelog template. Don’t worry about indentation here; it is automa
{{#each fixes}}
- Each fix has a {{commit}} with a {{commit.subject}}, an {{id}} and a {{href}} to the fixed issue.
{{/each}}
{{#limit commits limit="5"}}
{{#each commits}}
- Commits have a {{shorthash}}, a {{subject}} and a {{href}}, amongst other things.
{{/limit}}
{{/each}}
{{/each}}
```

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "auto-changelog",
"version": "1.0.3",
"version": "1.1.0",
"description": "Command line tool for generating a changelog from git tags and commit history",
"bin": {
"auto-changelog": "./lib/index.js"
@@ -9,7 +9,7 @@
"lint": "standard --verbose | snazzy",
"test": "cross-env NODE_ENV=test nyc mocha test",
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
"clean": "rm -rf lib",
"clean": "rm -rf lib test/coverage",
"build": "babel src -d lib",
"preversion": "npm run lint && npm run test",
"version": "babel-node src/index.js --package && git add CHANGELOG.md",
@@ -85,9 +85,11 @@
"nyc": {
"all": true,
"include": "src",
"exclude": "src/index.js",
"sourceMap": false,
"instrument": false,
"temp-directory": "./coverage/.nyc_output",
"report-dir": "./test/coverage",
"temp-directory": "./test/coverage/.nyc_output",
"require": [
"babel-polyfill",
"babel-register"
28 changes: 28 additions & 0 deletions scripts/generate-test-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { readFile, writeFile } from 'fs-extra'
import { join } from 'path'

import { __get__ } from '../src/commits'
import { parseReleases } from '../src/releases'
import { compileTemplate } from '../src/template'

const parseCommits = __get__('parseCommits')

const DATA_DIR = join(__dirname, '..', 'test', 'data')

const origin = {
hostname: 'github.com',
url: 'https://github.com/user/repo'
}

async function run () {
const gitLog = await readFile(join(DATA_DIR, 'git-log.txt'), 'utf-8')
const commits = parseCommits(gitLog, origin)
const releases = parseReleases(commits, origin, null, false)
await writeFile(join(DATA_DIR, 'commits.js'), 'export default ' + JSON.stringify(commits, null, 2))
await writeFile(join(DATA_DIR, 'releases.js'), 'export default ' + JSON.stringify(releases, null, 2))
await writeFile(join(DATA_DIR, 'template-compact.md'), await compileTemplate('compact', { releases }))
await writeFile(join(DATA_DIR, 'template-keepachangelog.md'), await compileTemplate('keepachangelog', { releases }))
await writeFile(join(DATA_DIR, 'template-json.md'), await compileTemplate('json', { releases }))
}

run().catch(e => console.error(e))
14 changes: 7 additions & 7 deletions src/commits.js
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ const MATCH_STATS = /(\d+) files? changed(?:, (\d+) insertions?...)?(?:, (\d+) d
const TAG_PREFIX = 'tag: '

// https://help.github.com/articles/closing-issues-via-commit-messages
const FIX_PATTERN = /(?:close[sd]?|fixe?[sd]?|resolve[sd]?)\s(?:#(\d+)|(https?:\/\/.+\/issues\/(\d+)))/gi
const FIX_PATTERN = /(?:close[sd]?|fixe?[sd]?|resolve[sd]?)\s(?:#(\d+)|(https?:\/\/.+?\/issues\/(\d+)))/gi

const MERGE_PATTERNS = [
/Merge pull request #(\d+) from .+\n\n(.+)/, // Regular GitHub merge
@@ -103,21 +103,21 @@ function getMerge (message, origin) {

function getCommitLink (hash, origin) {
if (origin.hostname === 'bitbucket.org') {
return `${origin.repoURL}/commits/${hash}`
return `${origin.url}/commits/${hash}`
}
return `${origin.repoURL}/commit/${hash}`
return `${origin.url}/commit/${hash}`
}

function getIssueLink (id, origin) {
return `${origin.repoURL}/issues/${id}`
return `${origin.url}/issues/${id}`
}

function getPullLink (id, origin) {
if (origin.hostname === 'bitbucket.org') {
return `${origin.repoURL}/pull-requests/${id}`
return `${origin.url}/pull-requests/${id}`
}
if (origin.hostname === 'gitlab.com') {
return `${origin.repoURL}/merge_requests/${id}`
return `${origin.url}/merge_requests/${id}`
}
return `${origin.repoURL}/pull/${id}`
return `${origin.url}/pull/${id}`
}
10 changes: 9 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -3,4 +3,12 @@
import 'babel-polyfill'
import run from './run'

run().catch(e => console.error(e))
run(process.argv)
.then(message => {
console.log(message)
process.exit(0)
})
.catch(error => {
console.error(error)
process.exit(1)
})
6 changes: 3 additions & 3 deletions src/origin.js
Original file line number Diff line number Diff line change
@@ -9,9 +9,9 @@ export async function fetchOrigin (remote) {
}
const origin = parseRepoURL(originURL)
const protocol = origin.protocol === 'http:' ? 'http:' : 'https:'
const host = origin.hostname || origin.host
const hostname = origin.hostname || origin.host
return {
...origin,
repoURL: `${protocol}//${host}/${origin.repo}`
hostname,
url: `${protocol}//${hostname}/${origin.repo}`
}
}
19 changes: 11 additions & 8 deletions src/releases.js
Original file line number Diff line number Diff line change
@@ -2,12 +2,12 @@ import semver from 'semver'

import { niceDate } from './utils'

export function parseReleases (commits, origin, packageVersion, includeUnreleased) {
export function parseReleases (commits, origin, packageVersion, options) {
let release = newRelease(packageVersion)
const releases = []
for (let commit of commits) {
if (commit.tag && semver.valid(commit.tag)) {
if (release.tag || includeUnreleased) {
if (release.tag || options.unreleased) {
releases.push({
...release,
href: getCompareLink(commit.tag, release.tag || 'HEAD', origin),
@@ -23,7 +23,7 @@ export function parseReleases (commits, origin, packageVersion, includeUnrelease
fixes: commit.fixes,
commit
})
} else if (filterCommit(commit, release.merges)) {
} else if (filterCommit(commit, release, options.commitLimit)) {
release.commits.push(commit)
}
}
@@ -45,23 +45,26 @@ function newRelease (tag = null, date = new Date().toISOString()) {
return release
}

function filterCommit (commit, merges) {
function filterCommit (commit, release, limit) {
if (semver.valid(commit.subject)) {
// Filter out version commits
return false
}
if (merges.findIndex(m => m.message === commit.subject) !== -1) {
if (release.merges.findIndex(m => m.message === commit.subject) !== -1) {
// Filter out commits with the same message as an existing merge
return false
}
return true
if (limit === false) {
return true
}
return release.commits.length < limit
}

function getCompareLink (from, to, origin) {
if (origin.hostname === 'bitbucket.org') {
return `${origin.repoURL}/compare/${to}%0D${from}`
return `${origin.url}/compare/${to}%0D${from}`
}
return `${origin.repoURL}/compare/${from}...${to}`
return `${origin.url}/compare/${from}...${to}`
}

function sortCommits (a, b) {
47 changes: 29 additions & 18 deletions src/run.js
Original file line number Diff line number Diff line change
@@ -6,35 +6,46 @@ import { fetchOrigin } from './origin'
import { fetchCommits } from './commits'
import { parseReleases } from './releases'
import { compileTemplate } from './template'
import { parseLimit } from './utils'

const DEFAULT_OUTPUT = 'CHANGELOG.md'
const DEFAULT_TEMPLATE = 'compact'
const DEFAULT_REMOTE = 'origin'
const DEFAULT_COMMIT_LIMIT = 3
const NPM_VERSION_TAG_PREFIX = 'v'
const PACKAGE_OPTIONS_KEY = 'auto-changelog'

commander
.option('-o, --output [file]', `output file, default: ${DEFAULT_OUTPUT}`, DEFAULT_OUTPUT)
.option('-t, --template [template]', `specify template to use [compact, keepachangelog, json], default: ${DEFAULT_TEMPLATE}`, DEFAULT_TEMPLATE)
.option('-r, --remote [remote]', `specify git remote to use for links, default: ${DEFAULT_REMOTE}`, DEFAULT_REMOTE)
.option('-p, --package', 'use version from package.json as latest release')
.option('-u, --unreleased', 'include section for unreleased changes')
.version(version)
.parse(process.argv)
function getOptions (argv, pkg) {
const options = commander
.option('-o, --output [file]', `output file, default: ${DEFAULT_OUTPUT}`, DEFAULT_OUTPUT)
.option('-t, --template [template]', `specify template to use [compact, keepachangelog, json], default: ${DEFAULT_TEMPLATE}`, DEFAULT_TEMPLATE)
.option('-r, --remote [remote]', `specify git remote to use for links, default: ${DEFAULT_REMOTE}`, DEFAULT_REMOTE)
.option('-p, --package', 'use version from package.json as latest release')
.option('-u, --unreleased', 'include section for unreleased changes')
.option('-l, --commit-limit [count]', `number of commits to display per release, default: ${DEFAULT_COMMIT_LIMIT}`, parseLimit, DEFAULT_COMMIT_LIMIT)
.version(version)
.parse(argv)

export default async function run () {
const pkg = await pathExists('package.json') && await readJson('package.json')
let options = { ...commander }
if (pkg) {
options = { ...options, ...pkg['auto-changelog'] }
} else if (commander.package) {
throw Error('package.json could not be found')
if (!pkg) {
if (options.package) {
throw Error('package.json could not be found')
}
return options
}
return {
...options,
...pkg[PACKAGE_OPTIONS_KEY]
}
}

export default async function run (argv) {
const pkg = await pathExists('package.json') && await readJson('package.json')
const options = getOptions(argv, pkg)
const origin = await fetchOrigin(options.remote)
const commits = await fetchCommits(origin)
const packageVersion = options.package ? NPM_VERSION_TAG_PREFIX + pkg.version : null
const releases = parseReleases(commits, origin, packageVersion, options.unreleased)
const releases = parseReleases(commits, origin, packageVersion, options)
const log = await compileTemplate(options.template, { releases })
await writeFile(options.output, log)
console.log(`${Buffer.byteLength(log, 'utf8')} bytes written to ${options.output}`)
process.exit(0)
return `${Buffer.byteLength(log, 'utf8')} bytes written to ${options.output}`
}
Loading