Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Implement 2 layer group by for commits #908

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,4 @@
# Change Log

All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
@@ -0,0 +1,15 @@
### ISC License

Copyright © [conventional-changelog team](https://github.com/conventional-changelog)

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
@@ -0,0 +1,50 @@
# [![Build Status][travis-image]][travis-url] [![Coverage Status][coveralls-image]][coveralls-url]

## conventionalcommits.org convention

A concrete implementation of the specification described at
[conventionalcommits.org](https://conventionalcommits.org/) for automated
CHANGELOG generation and version management.


## Indirect Usage (as preset)

Use the [Conventional Changelog CLI Quick Start](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-cli#quick-start) with the `-p conventionalcommits` option.

## Direct Usage (as a base preset so you can customize it)

If you want to use this package directly and pass options, you can use the [Conventional Changelog CLI Quick Start](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-cli#quick-start) and with the `--config` or `-n` parameter, pass a js config that looks like this
```
'use strict'
const config = require('conventional-changelog-conventionalcommits-grouped')

module.exports = config({
"issuePrefixes": ["TEST-"],
"issueUrlFormat": "https://myBugTracker.com/{{prefix}}{{id}}"
})
```

or json config like that:
```
{
"options": {
"preset": {
"name": "conventionalchangelog",
"issuePrefixes": ["TEST-"],
"issueUrlFormat": "https://myBugTracker.com/{{prefix}}{{id}}"
}
}
}
```
This last json config way passes the `preset` object to the `conventional-changelog-preset-loader` package, that in turn, passes this same `preset` object as the config for the `conventional-changelog-conventionalcommits-grouped`.



See [conventional-changelog-config-spec](https://github.com/conventional-changelog/conventional-changelog-config-spec) for available
configuration options.


[travis-image]: https://travis-ci.org/conventional-changelog/conventional-changelog.svg?branch=master
[travis-url]: https://travis-ci.org/conventional-changelog/conventional-changelog
[coveralls-image]: https://coveralls.io/repos/conventional-changelog/conventional-changelog/badge.svg
[coveralls-url]: https://coveralls.io/r/conventional-changelog/conventional-changelog
@@ -0,0 +1,11 @@
const { breakingHeaderPattern } = require('./parser-opts')()

module.exports = (commit) => {
const match = commit.header.match(breakingHeaderPattern)
if (match && commit.notes.length === 0) {
const noteText = match[3] // the description of the change.
commit.notes.push({
text: noteText
})
}
}
@@ -0,0 +1,12 @@
'use strict'

const Q = require('q')
const parserOpts = require('./parser-opts')
const writerOpts = require('./writer-opts')

module.exports = function (config) {
return Q.all([parserOpts(config), writerOpts(config)])
.spread((parserOpts, writerOpts) => {
return { parserOpts, writerOpts }
})
}
@@ -0,0 +1,43 @@
'use strict'

const addBangNotes = require('./add-bang-notes')
const parserOpts = require('./parser-opts')

module.exports = function (config) {
return {
parserOpts: parserOpts(config),

whatBump: (commits) => {
let level = 2
let breakings = 0
let features = 0

commits.forEach(commit => {
// adds additional breaking change notes
// for the special case, test(system)!: hello world, where there is
// a '!' but no 'BREAKING CHANGE' in body:
addBangNotes(commit)
if (commit.notes.length > 0) {
breakings += commit.notes.length
level = 0
} else if (commit.type === 'feat' || commit.type === 'feature') {
features += 1
if (level === 2) {
level = 1
}
}
})

if (config.preMajor && level < 2) {
level++
}

return {
level: level,
reason: breakings === 1
? `There is ${breakings} BREAKING CHANGE and ${features} features`
: `There are ${breakings} BREAKING CHANGES and ${features} features`
}
}
}
}
@@ -0,0 +1,38 @@
'use strict'
const Q = require('q')
const _ = require('lodash')
const conventionalChangelog = require('./conventional-changelog')
const parserOpts = require('./parser-opts')
const recommendedBumpOpts = require('./conventional-recommended-bump')
const writerOpts = require('./writer-opts')

module.exports = function (parameter) {
// parameter passed can be either a config object or a callback function
if (_.isFunction(parameter)) {
// parameter is a callback object
const config = {}
// FIXME: use presetOpts(config) for callback
Q.all([
conventionalChangelog(config),
parserOpts(config),
recommendedBumpOpts(config),
writerOpts(config)
]).spread((conventionalChangelog, parserOpts, recommendedBumpOpts, writerOpts) => {
parameter(null, { gitRawCommitsOpts: { noMerges: null }, conventionalChangelog, parserOpts, recommendedBumpOpts, writerOpts })
})
} else {
const config = parameter || {}
return presetOpts(config)
}
}

function presetOpts (config) {
return Q.all([
conventionalChangelog(config),
parserOpts(config),
recommendedBumpOpts(config),
writerOpts(config)
]).spread((conventionalChangelog, parserOpts, recommendedBumpOpts, writerOpts) => {
return { conventionalChangelog, parserOpts, recommendedBumpOpts, writerOpts }
})
}
@@ -0,0 +1,41 @@
{
"name": "conventional-changelog-conventionalcommits-grouped",
"version": "4.6.3",
"description": "conventional-changelog conventionalcommits.org preset",
"main": "index.js",
"scripts": {
"test-windows": "mocha --timeout 30000"
},
"repository": {
"type": "git",
"url": "https://github.com/conventional-changelog/conventional-changelog.git"
},
"keywords": [
"conventional-changelog",
"conventionalcommits.org",
"preset"
],
"files": [
"add-bang-notes.js",
"conventional-changelog.js",
"conventional-recommended-bump.js",
"index.js",
"parser-opts.js",
"writer-opts.js",
"templates"
],
"author": "Ben Coe",
"engines": {
"node": ">=10"
},
"license": "ISC",
"bugs": {
"url": "https://github.com/conventional-changelog/conventional-changelog/issues"
},
"homepage": "https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-conventionalcommits-groupedreadme",
"dependencies": {
"compare-func": "^2.0.0",
"lodash": "^4.17.15",
"q": "^1.5.1"
}
}
@@ -0,0 +1,25 @@
'use strict'

module.exports = function (config) {
config = defaultConfig(config)
return {
headerPattern: /^(\w*)(?:\((.*)\))?!?: (.*)$/,
breakingHeaderPattern: /^(\w*)(?:\((.*)\))?!: (.*)$/,
headerCorrespondence: [
'type',
'scope',
'subject'
],
noteKeywords: ['BREAKING CHANGE', 'BREAKING-CHANGE'],
revertPattern: /^(?:Revert|revert:)\s"?([\s\S]+?)"?\s*This reverts commit (\w*)\./i,
revertCorrespondence: ['header', 'hash'],
issuePrefixes: config.issuePrefixes
}
}

// merge user set configuration with default configuration.
function defaultConfig (config) {
config = config || {}
config.issuePrefixes = config.issuePrefixes || ['#']
return config
}
@@ -0,0 +1,29 @@
* {{#if subject}}
{{~subject}}
{{~else}}
{{~header}}
{{~/if}}

{{~!-- commit link --}}{{~#if hash}} {{#if @root.linkReferences~}}
([{{shortHash}}]({{commitUrlFormat}}))
{{~else}}
{{~shortHash}}
{{~/if}}{{~/if}}

{{~!-- commit references --}}
{{~#if references~}}
, closes
{{~#each references}} {{#if @root.linkReferences~}}
[
{{~#if this.owner}}
{{~this.owner}}/
{{~/if}}
{{~this.repository}}{{this.prefix}}{{this.issue}}]({{issueUrlFormat}})
{{~else}}
{{~#if this.owner}}
{{~this.owner}}/
{{~/if}}
{{~this.repository}}{{this.prefix}}{{this.issue}}
{{~/if}}{{/each}}
{{~/if}}

@@ -0,0 +1,13 @@
{{#if isPatch~}}
###
{{~else~}}
##
{{~/if}} {{#if @root.linkCompare~}}
[{{version}}]({{compareUrlFormat}})
{{~else}}
{{~version}}
{{~/if}}
{{~#if title}} "{{title}}"
{{~/if}}
{{~#if date}} ({{date}})
{{/if}}
@@ -0,0 +1,28 @@
{{> header}}

{{#if noteGroups}}
{{#each noteGroups}}

### ⚠ {{title}}

{{#each notes}}
* {{#if commit.scope}}**{{commit.scope}}:** {{/if}}{{text}}
{{/each}}
{{/each}}
{{/if}}
{{#each commitGroups}}
{{#if title}}

### {{title}}
{{/if}}
{{#each commits}}
{{#if this.title}}

#### {{this.title}}
{{/if}}

{{#each this.commits}}
{{> commit root=@root}}
{{/each}}
{{/each}}
{{/each}}
@@ -0,0 +1,5 @@
{
"repository": "ghe",
"version": "v3.0.0",
"repository": "https://github.internal.example.com/conventional-changelog/internal"
}
@@ -0,0 +1,5 @@
{
"repository": "known",
"version": "v2.0.0",
"repository": "https://github.com/conventional-changelog/example"
}
@@ -0,0 +1,4 @@
{
"repository": "http://unknown",
"version": "v2.0.0"
}