From a3acc3222135b17af0ee9785605d21b104ed0aef Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Thu, 5 Sep 2019 11:06:08 -0400 Subject: [PATCH] feat: sort sections of CHANGELOG based on priority (#513) --- package.json | 1 + .../test/test.js | 8 ++++++++ .../writer-opts.js | 13 ++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 1fc1a865b..8ee5924a4 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ }, "scripts": { "lint": "eslint . --cache --cache-location ./node_modules/.cache/ --ignore-path .gitignore", + "fix": "eslint . --fix --cache --cache-location ./node_modules/.cache/ --ignore-path .gitignore", "pretest": "npm run lint", "test": "nyc mocha --timeout 30000 packages/*/test{,/*}.js", "test-windows": "lerna exec --concurrency 1 -- npm run test-windows", diff --git a/packages/conventional-changelog-conventionalcommits/test/test.js b/packages/conventional-changelog-conventionalcommits/test/test.js index 1f68c7241..e50326da9 100644 --- a/packages/conventional-changelog-conventionalcommits/test/test.js +++ b/packages/conventional-changelog-conventionalcommits/test/test.js @@ -113,6 +113,14 @@ describe('conventionalcommits.org preset', function () { expect(chunk).to.not.include('***:**') expect(chunk).to.not.include(': Not backward compatible.') + // CHANGELOG should group sections in order of importance: + expect( + chunk.indexOf('BREAKING CHANGE') < chunk.indexOf('Features') && + chunk.indexOf('Features') < chunk.indexOf('Bug Fixes') && + chunk.indexOf('Bug Fixes') < chunk.indexOf('Performance Improvements') && + chunk.indexOf('Performance Improvements') < chunk.indexOf('Reverts') + ).to.equal(true) + done() })) }) diff --git a/packages/conventional-changelog-conventionalcommits/writer-opts.js b/packages/conventional-changelog-conventionalcommits/writer-opts.js index 43880e981..c4f569928 100644 --- a/packages/conventional-changelog-conventionalcommits/writer-opts.js +++ b/packages/conventional-changelog-conventionalcommits/writer-opts.js @@ -138,7 +138,18 @@ function getWriterOpts (config) { return commit }, groupBy: `type`, - commitGroupsSort: `title`, + // the groupings of commit messages, e.g., Features vs., Bug Fixes, are + // sorted based on their probable importance: + commitGroupsSort: (a, b) => { + const commitGroupOrder = ['Reverts', 'Performance Improvements', 'Bug Fixes', 'Features'] + const gRankA = commitGroupOrder.indexOf(a.title) + const gRankB = commitGroupOrder.indexOf(b.title) + if (gRankA >= gRankB) { + return -1 + } else { + return 1 + } + }, commitsSort: [`scope`, `subject`], noteGroupsSort: `title`, notesSort: compareFunc