-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(conventional-changelog): Introduce GitHub conventional changelog
- Loading branch information
Showing
15 changed files
with
803 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# @lmc-eu/conventional-changelog-lmc-github | ||
|
||
> LMC's Conventional Changelog preset for GitHub repositories | ||
## Usage | ||
|
||
### Installation | ||
|
||
NPM: | ||
|
||
``` | ||
npm i --dev @commitlint/cli @commitlint/config-conventional @lmc-eu/conventional-changelog-lmc-github | ||
``` | ||
|
||
Yarn: | ||
|
||
``` | ||
yarn add --dev @commitlint/cli @commitlint/config-conventional @lmc-eu/conventional-changelog-lmc-github | ||
``` | ||
|
||
### Configuration | ||
|
||
#### Linting | ||
|
||
Create a _commitlint.config.js_ file with the following contents: | ||
|
||
```javascript | ||
'use strict'; | ||
|
||
module.exports = { | ||
extends: ['@commitlint/config-conventional'], | ||
parserPreset: '@lmc-eu/conventional-changelog-lmc-github', | ||
}; | ||
``` | ||
|
||
#### Changelog | ||
|
||
In a _package.json_ define following scripts: | ||
|
||
```json | ||
{ | ||
"scripts": { | ||
"changelog": "conventional-changelog -p lmc-github -i CHANGELOG.md -s", | ||
"changelog:origin": "conventional-changelog -p lmc-github -i CHANGELOG.md -s -r 0" | ||
} | ||
} | ||
``` | ||
|
||
For example see [example changelog file][example-changelog] | ||
|
||
[example-changelog]: example-changelog.md |
29 changes: 29 additions & 0 deletions
29
packages/conventional-changelog-lmc-github/example-changelog.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<a name="2.1.0"></a> | ||
|
||
# [2.1.0](https://github.com/projects/lmc-eu/code-quality-tools/compare/v2.0.0...v2.1.0) (2018-10-05) | ||
|
||
### Features | ||
|
||
- New info block html structure ([ee334bb](https://github.com/lmc-eu/code-quality-tools/commit/ee334bb)) | ||
|
||
<a name="2.0.0"></a> | ||
|
||
# [2.0.0](https://github.com/projects/lmc-eu/code-quality-tools/compare/v1.2.5...v2.0.0) (2018-10-05) | ||
|
||
### BREAKING CHANGES | ||
|
||
- New HTML structure and CSS for detail page ([f1390fb](https://github.com/lmc-eu/code-quality-tools/commit/f1390fb)) | ||
|
||
<a name="1.2.5"></a> | ||
|
||
## [1.2.5](https://github.com/projects/lmc-eu/code-quality-tools/compare/v1.2.4...v1.2.5) (2018-10-02) | ||
|
||
Miscellaneous changes: code refactoring, adding missing tests, changes to the build process or auxiliary tools and libraries such as documentation generation | ||
|
||
<a name="1.2.4"></a> | ||
|
||
## [1.2.4](https://github.com/projects/lmc-eu/code-quality-tools/compare/v1.2.3...v1.2.4) (2018-10-02) | ||
|
||
### Bug Fixes | ||
|
||
- Load GTM script using another library ([ec4211a](https://github.com/lmc-eu/code-quality-tools/commit/ec4211a)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"name": "@lmc-eu/conventional-changelog-lmc-github", | ||
"version": "1.0.0", | ||
"description": "conventional-changelog LMC preset for GitHub", | ||
"keywords": [ | ||
"lmc", | ||
"github", | ||
"changelog", | ||
"conventional-changelog", | ||
"preset" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/lmc-eu/code-quality-tools", | ||
"directory": "packages/conventional-changelog-lmc-github" | ||
}, | ||
"author": "Tomáš Litera <tomas.litera@lmc.eu>", | ||
"license": "BSD-3-Clause", | ||
"bugs": { | ||
"url": "https://github.com/lmc-eu/issues" | ||
}, | ||
"files": [ | ||
"src" | ||
], | ||
"main": "src/index.js", | ||
"scripts": { | ||
"test": "jest" | ||
}, | ||
"dependencies": { | ||
"compare-func": "^2.0.0", | ||
"q": "^1.5.1" | ||
}, | ||
"devDependencies": { | ||
"better-than-before": "^1.0.0", | ||
"conventional-changelog-core": "^4.2.0", | ||
"git-dummy-commit": "^1.3.0", | ||
"jest": "^26.4.2", | ||
"jest-extended": "^0.11.5", | ||
"shelljs": "^0.8.4", | ||
"through2": "^4.0.2" | ||
}, | ||
"jest": { | ||
"setupFilesAfterEnv": [ | ||
"jest-extended" | ||
], | ||
"testTimeout": 30000 | ||
}, | ||
"engines": { | ||
"node": ">=4.x" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const Q = require('q'); | ||
const readFile = Q.denodeify(require('fs').readFile); | ||
const { resolve } = require('path'); | ||
const parserOpts = require('./parser-opts'); | ||
const writerOpts = require('./writer-opts'); | ||
|
||
module.exports = Q.all([ | ||
readFile(resolve(__dirname, 'templates/template.hbs'), 'utf-8'), | ||
readFile(resolve(__dirname, 'templates/header.hbs'), 'utf-8'), | ||
readFile(resolve(__dirname, 'templates/commit.hbs'), 'utf-8'), | ||
readFile(resolve(__dirname, 'templates/footer.hbs'), 'utf-8'), | ||
]).spread((template, header, commit, footer) => { | ||
writerOpts.mainTemplate = template; | ||
writerOpts.headerPartial = header; | ||
writerOpts.commitPartial = commit; | ||
writerOpts.footerPartial = footer; | ||
|
||
return { | ||
parserOpts, | ||
writerOpts, | ||
}; | ||
}); |
7 changes: 7 additions & 0 deletions
7
packages/conventional-changelog-lmc-github/src/parser-opts.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
headerPattern: /^(?:Pull request #[0-9]+: )?(?:([a-zA-Z]*-[0-9_]*)(?: ))* ?([\w ]*)(?:\((.*)\))?: (.*)$/, | ||
headerCorrespondence: ['body', 'type', 'scope', 'subject'], | ||
noteKeywords: ['BREAKING CHANGE', 'BREAKING CHANGES'], | ||
revertPattern: /^revert:\s([\s\S]*?)\s*This reverts commit (\w*)\./, | ||
revertCorrespondence: ['header', 'hash'], | ||
}; |
30 changes: 30 additions & 0 deletions
30
packages/conventional-changelog-lmc-github/src/templates/commit.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
*{{#if scope}} **{{scope}}:** | ||
{{~/if}} {{#if subject}} | ||
{{~subject}} | ||
{{~else}} | ||
{{~header}} | ||
{{~/if}} | ||
|
||
{{~!-- commit link --}} {{#if @root.linkReferences~}} | ||
([{{hash}}]( | ||
{{~#if @root.repository~}} | ||
{{~#if @root.host}} | ||
{{~@root.host}}/ | ||
{{~/if}} | ||
{{~#if @root.owner~}} | ||
{{~@root.owner}}/ | ||
{{~/if~}} | ||
{{~@root.repository}}/ | ||
{{~else}} | ||
{{~@root.repoUrl}}/ | ||
{{~/if~}} | ||
commits/{{~hash}})) | ||
{{~else}} | ||
({{~hash}}) | ||
{{~/if}} | ||
|
||
{{~!-- commit references --}} | ||
{{~#if references~}} | ||
, closes {{references}} | ||
{{~/if}} |
11 changes: 11 additions & 0 deletions
11
packages/conventional-changelog-lmc-github/src/templates/footer.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{{#if noteGroups}} | ||
{{#each noteGroups}} | ||
|
||
### {{title}} | ||
|
||
{{#each notes}} | ||
* {{#if commit.scope}}**{{commit.scope}}:** {{/if}}{{text}} | ||
{{/each}} | ||
{{/each}} | ||
|
||
{{/if}} |
26 changes: 26 additions & 0 deletions
26
packages/conventional-changelog-lmc-github/src/templates/header.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<a name="{{version}}"></a> | ||
{{#if isPatch~}} | ||
## | ||
{{~else~}} | ||
# | ||
{{~/if}} {{#if @root.linkCompare~}} | ||
[{{version}}]( | ||
{{~#if @root.repository~}} | ||
{{~#if @root.host}} | ||
{{~@root.host}}/ | ||
{{~/if}} | ||
{{~#if @root.owner~}} | ||
{{~@root.owner}}/ | ||
{{~/if~}} | ||
{{~@root.repository}}/ | ||
{{~else}} | ||
{{~@root.repoUrl}}/ | ||
{{~/if~}} | ||
compare/{{previousTag}}...{{currentTag}}) | ||
{{~else}} | ||
{{~version}} | ||
{{~/if}} | ||
{{~#if title}} "{{title}}" | ||
{{~/if}} | ||
{{~#if date}} ({{date}}) | ||
{{/if}} |
17 changes: 17 additions & 0 deletions
17
packages/conventional-changelog-lmc-github/src/templates/template.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{{> header}} | ||
|
||
{{#each commitGroups}} | ||
|
||
{{#if title}} | ||
### {{title}} | ||
{{/if}} | ||
|
||
{{#each commits}} | ||
{{> commit root=@root}} | ||
{{/each}} | ||
{{/each}} | ||
{{#unless commitGroups}} | ||
Miscellaneous changes | ||
{{/unless}} | ||
|
||
{{> footer}} |
102 changes: 102 additions & 0 deletions
102
packages/conventional-changelog-lmc-github/src/writer-opts.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* eslint-disable consistent-return */ | ||
/* eslint-disable prefer-destructuring */ | ||
/* eslint-disable no-param-reassign */ | ||
const compareFunc = require('compare-func'); | ||
|
||
/** | ||
* Formats issues using the issueURL as the prefix of the complete issue URL | ||
* | ||
* @param {string} issueUrl - if the issueURL is falsy, then the issue will be printed as-is. Otherwise, it will be printed as a link | ||
* @param {string} issue - the issue reference (without the # in-front of it) | ||
* @returns {string} - Either the issue or a Markdown-formatted link to the issue. | ||
*/ | ||
function formatIssue(issueUrl, issue) { | ||
if (issueUrl) { | ||
return `[#${issue}](${issueUrl}/${issue})`; | ||
} | ||
|
||
return `#${issue}`; | ||
} | ||
|
||
module.exports = { | ||
transform: (commit, context) => { | ||
let discard = true; | ||
const issues = []; | ||
|
||
commit.notes.forEach((note) => { | ||
note.title = 'BREAKING CHANGES'; | ||
discard = false; | ||
}); | ||
|
||
const transformedCommit = commit; | ||
|
||
if (commit.type === 'BREAKING CHANGE') { | ||
transformedCommit.type = 'BREAKING CHANGES'; | ||
} else if (commit.type === 'Feat') { | ||
transformedCommit.type = 'Features'; | ||
} else if (commit.type === 'Fix') { | ||
transformedCommit.type = 'Bug Fixes'; | ||
} else if (commit.type === 'Perf') { | ||
transformedCommit.type = 'Performance Improvements'; | ||
} else if (commit.type === 'Revert') { | ||
transformedCommit.type = 'Reverts'; | ||
} else if (commit.type === 'Docs') { | ||
transformedCommit.type = 'Documentation'; | ||
} else if (commit.type === 'Style') { | ||
transformedCommit.type = 'Styles'; | ||
} else if (commit.type === 'Refactor') { | ||
transformedCommit.type = 'Code Refactoring'; | ||
} else if (commit.type === 'Test') { | ||
transformedCommit.type = 'Tests'; | ||
} else if (commit.type === 'Chore') { | ||
transformedCommit.type = 'Chores'; | ||
} else if (commit.type === 'Deps') { | ||
transformedCommit.type = 'Dependencies'; | ||
} else if (discard) { | ||
return; | ||
} | ||
|
||
if (commit.scope === '*') { | ||
transformedCommit.scope = ''; | ||
} | ||
|
||
if (typeof commit.hash === 'string') { | ||
transformedCommit.hash = commit.hash.substring(0, 7); | ||
} | ||
|
||
// Remove port from host URI | ||
if (typeof context.host === 'string') { | ||
context.host = context.host.match(/(^https?:\/\/[a-z.-]*)/)[0]; | ||
} | ||
|
||
// Take issue url from package.json | ||
const issueUrl = context.packageData.bugs && context.packageData.bugs.url; | ||
|
||
if (typeof transformedCommit.subject === 'string') { | ||
transformedCommit.subject = transformedCommit.subject.replace(/#([a-zA-Z0-9-]+)/g, (_, issue) => { | ||
issues.push(issue); | ||
|
||
return formatIssue(issueUrl, issue); | ||
}); | ||
} | ||
|
||
// remove references that already appear in the subject | ||
transformedCommit.references = commit.references | ||
.filter((reference) => { | ||
if (issues.indexOf(reference.issue) === -1) { | ||
return true; | ||
} | ||
|
||
return false; | ||
}) | ||
.map((reference) => formatIssue(issueUrl, reference.issue)) | ||
.join(', '); | ||
|
||
return transformedCommit; | ||
}, | ||
groupBy: 'type', | ||
commitGroupsSort: 'title', | ||
commitsSort: ['scope', 'subject'], | ||
noteGroupsSort: 'title', | ||
notesSort: compareFunc, | ||
}; |
4 changes: 4 additions & 0 deletions
4
packages/conventional-changelog-lmc-github/tests/__fixtures/_unknown-host.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"repository": "unknown", | ||
"version": "v2.0.0" | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/conventional-changelog-lmc-github/tests/__fixtures/github-host.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"version": "v2.0.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.internal.example.com/owner/repo-name.git" | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/conventional-changelog-lmc-github/tests/__fixtures/github-http-host.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"version": "v2.0.0", | ||
"repository": "https://github.internal.example.com/owner/repo-name" | ||
} |
Oops, something went wrong.