This repository has been archived by the owner on Jun 6, 2019. It is now read-only.
forked from greenkeeperio/greenkeeper
-
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(config): add the ability to customize commit messages
Add configuration options allowing Greenkeeper's commit message format to be customized as the user desires. These are handled exactly like other configuration options, as a `commitMessages` key in `package.json`. Some messages support data coming in, the format for this follows JavaScript's template literals. This will allow Greenkeeper to fit in with any custom commit message format that a project requires, instead of forcing the conventional-commit style. Fixes greenkeeperio#153.
- Loading branch information
1 parent
b719d61
commit 6a4fae5
Showing
7 changed files
with
96 additions
and
12 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
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
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
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 @@ | ||
const template = require('es6-template-strings') | ||
|
||
module.exports = async function (commitMessages, key, values) { | ||
if (!Object.prototype.hasOwnProperty.call(commitMessages, key)) { | ||
throw new Error(`Unknown message key '${key}'`) | ||
} | ||
|
||
const templateValues = Object.assign({}, values) | ||
|
||
return template(commitMessages[key], templateValues) | ||
} |
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
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
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,53 @@ | ||
const { test } = require('tap') | ||
const getMessage = require('../../lib/get-message') | ||
|
||
/* eslint-disable no-template-curly-in-string */ | ||
|
||
test('get default commit messages', t => { | ||
const commitMessages = { | ||
initialBadge: 'docs(readme): add Greenkeeper badge', | ||
initialDependencies: 'chore(package): update dependencies', | ||
initialBranches: 'chore(travis): whitelist greenkeeper branches', | ||
dependencyUpdate: 'fix(package): update ${dependency} to version ${version}', | ||
devDependencyUpdate: 'chore(package): update ${dependency} to version ${version}', | ||
dependencyPin: 'fix: pin ${dependency} to ${oldVersion}', | ||
devDependencyPin: 'chore: pin ${dependency} to ${oldVersion}', | ||
closes: '\n\nCloses #${number}' | ||
} | ||
const values = { | ||
dependency: 'foo', | ||
version: 'bar', | ||
oldVersion: 'rab', | ||
number: 42 | ||
} | ||
const expected = { | ||
initialBadge: 'docs(readme): add Greenkeeper badge', | ||
initialDependencies: 'chore(package): update dependencies', | ||
initialBranches: 'chore(travis): whitelist greenkeeper branches', | ||
dependencyUpdate: 'fix(package): update foo to version bar', | ||
devDependencyUpdate: 'chore(package): update foo to version bar', | ||
dependencyPin: 'fix: pin foo to rab', | ||
devDependencyPin: 'chore: pin foo to rab', | ||
closes: '\n\nCloses #42' | ||
} | ||
|
||
t.plan(Object.keys(commitMessages).length) | ||
t.is(getMessage(commitMessages, 'initialBadge'), expected.initialBadge) | ||
t.is(getMessage(commitMessages, 'initialDependencies'), expected.initialDependencies) | ||
t.is(getMessage(commitMessages, 'initialBranches'), expected.initialBranches) | ||
t.is(getMessage(commitMessages, 'dependencyUpdate', values), expected.dependencyUpdate) | ||
t.is(getMessage(commitMessages, 'devDependencyUpdate', values), expected.devDependencyUpdate) | ||
t.is(getMessage(commitMessages, 'dependencyPin', values), expected.dependencyPin) | ||
t.is(getMessage(commitMessages, 'devDependencyPin', values), expected.devDependencyPin) | ||
t.is(getMessage(commitMessages, 'closes', values), expected.closes) | ||
}) | ||
|
||
test("throws when it doesn't know a message", t => { | ||
const commitMessages = { | ||
foo: '42' | ||
} | ||
const message = "Unknown message key 'bar'" | ||
|
||
t.plan(1) | ||
t.throws(() => getMessage(commitMessages, 'bar'), message) | ||
}) |