Skip to content

✨ Add support for custom commit URLs and issue resolution #82

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

Open
wants to merge 1 commit into
base: main
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .releaserc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ module.exports = {
},
releaseNotes: {
template: fs.readFileSync(tplFile, 'utf-8'),
commitUrlTemplate: 'https://{source}/{owner}/{repo}/commit/{commit.commit.short}',
},
issueResolution: {
template: '{baseUrl}/{owner}/{repo}/issues/{ref}',
baseUrl: 'https://github.com',
source: 'github.com',
removeFromCommit: false,
regex: /#\d+/g
}
}
],
Expand Down
1 change: 1 addition & 0 deletions lib/assets/default-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = {
releaseNotes: {
semver: false,
template: readFileAsync(path.join(TEMPLATE_DIR, 'default-template.hbs')),
commitUrlTemplate: 'https://{source}/{owner}/{repo}/commit/{commit}',
partials: {
commitTemplate: readFileAsync(path.join(TEMPLATE_DIR, 'commit-template.hbs'))
},
Expand Down
4 changes: 2 additions & 2 deletions lib/assets/templates/commit-template.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[`{{commit.short}}`](https://github.com/{{owner}}/{{repo}}/commit/{{commit.short}}) {{subject}} {{#if issues}}(Issues:{{#each issues}} [`{{text}}`]({{link}}){{/each}}){{/if}}{{#if wip}}{{#each wip}}
- [`{{commit.short}}`](https://github.com/{{owner}}/{{repo}}/commit/{{commit.short}}) {{subject}}{{/each}}
[`{{commit.short}}`]({{url}}) {{subject}} {{#if issues}}(Issues:{{#each issues}} [`{{text}}`]({{link}}){{/each}}){{/if}}{{#if wip}}{{#each wip}}
- [`{{commit.short}}`]({{url}}) {{subject}}{{/each}}
{{/if}}
4 changes: 4 additions & 0 deletions lib/helper/get-cmp-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ module.exports = function getCmpLink (host, owner, repo, prevTag, nextTag) {
switch (host) {
case 'github.com':
return `https://github.com/${owner}/${repo}/compare/${prevTag}...${nextTag}`
case 'gitlab.com':
return `https://gitlab.com/${owner}/${repo}/compare/${prevTag}...${nextTag}`
case 'bitbucket.org':
return `https://bitbucket.org/${owner}/${repo}/compare/${nextTag}..${prevTag}`
default:
return ''
}
Expand Down
6 changes: 6 additions & 0 deletions lib/helper/get-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ function handleArrayConfig (dest, src) {
module.exports = function getConfig (userConfig) {
if (userConfig && 'releaseNotes' in userConfig && 'semver' in userConfig.releaseNotes && userConfig.releaseNotes.semver) {
DEFAULT_CONFIG.releaseNotes.template = readFileAsync(path.join(TEMPLATE_DIR, 'default-template-semver.hbs'))
console.log('config:semver')
console.table(userConfig)
} else {
console.log('config:')
console.table(userConfig)
}

return _mergeWith(_cloneDeep(DEFAULT_CONFIG), userConfig, handleArrayConfig)
}
29 changes: 22 additions & 7 deletions lib/release-notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ const RELEASE_TYPES = require('./assets/release-types.json')
module.exports = class ReleaseNotes {
/**
* @param {object} context
*/
constructor (context, { issueResolution, template, partials, helpers, semver } = {}) {
debug('Found %d commits', context.commits.length)
*/
constructor (context, { issueResolution, commitUrlTemplate, commitBaseUrl, template, partials, helpers, semver } = {}) {
debug('Found %d commits', Object.keys(context.commits).length)

const { owner, name: repo, source } = parseGitUrl(context.options.repositoryUrl)

debug('Git remote: %s', source)
debug('Repository: %s/%s', owner, repo)

console.table(context)

this._semver = semver
this._template = template
this._partials = partials
Expand All @@ -46,14 +48,27 @@ module.exports = class ReleaseNotes {
...helpers
}

const parsedCommits = parseCommits(context.commits, { owner, repo, source, commitBaseUrl }, {
issues: { owner, repo, source, ...issueResolution },
semver: this._semver
})

this._context = {
owner,
repo,
source,
commits: parseCommits(context.commits, { owner, repo, source }, {
issues: { owner, repo, source, ...issueResolution },
semver: this._semver
})
commits: Object.entries(parsedCommits).reduce((acc, [key, commits]) => {
acc[key] = commits.map(commit => {
return {
...commit,
url: commitUrlTemplate.replace('{source}', source)
.replace('{owner}', owner)
.replace('{repo}', repo)
.replace('{commit}', commit.commit.short)
}
})
return acc
}, {})
}

Object.values(this._context.commits)
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"commit": "gitmoji -c",
"lint": "eslint ./index.js ./lib/**/*.js",
"link": "npm link && npm link semantic-release-gitmoji",
"test": "ava test/**/*.test.js"
"test": "ava test/**/*.test.js --verbose"
},
"repository": {
"type": "git",
Expand Down
46 changes: 38 additions & 8 deletions test/integration/analyze-commits.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,59 +15,89 @@ test.after(function () {
stub.restore()
})

const commitUrlTemplate = 'https://{source}/{owner}/{repo}/commit/{commit}';

const CASES = [
{
name: 'default config + common context w/o updates',
pluginConfig: {},
pluginConfig: {
releaseNotes: {
commitUrlTemplate
}
},
context: getContext('common', { commits: { boring: 2 } }),
expectedRelease: undefined
},
{
name: 'default config + common context w/ patch updates',
pluginConfig: {},
pluginConfig: {
releaseNotes: {
commitUrlTemplate
}
},
context: getContext('common', { commits: { boring: 2, patch: 4 } }),
expectedRelease: 'patch'
},
{
name: 'default config + common context w/ minor updates',
pluginConfig: {},
pluginConfig: {
releaseNotes: {
commitUrlTemplate
}
},
context: getContext('common', { commits: { boring: 2, patch: 4, minor: 2 } }),
expectedRelease: 'minor'
},
{
name: 'default config + common context w/ major updates',
pluginConfig: {},
pluginConfig: {
releaseNotes: {
commitUrlTemplate
}
},
context: getContext('common', { commits: { boring: 2, patch: 4, minor: 2, major: 1 } }),
expectedRelease: 'major'
},
{
name: 'default config + common context w/o updates using gitmoji semver',
pluginConfig: {
semver: true
semver: true,
releaseNotes: {
commitUrlTemplate
}
},
context: getContext('common', { commits: { boring: 2 } }),
expectedRelease: undefined
},
{
name: 'default config + common context w/ patch updates using gitmoji semver',
pluginConfig: {
semver: true
semver: true,
releaseNotes: {
commitUrlTemplate
}
},
context: getContext('common', { commits: { boring: 2, patch: 4 } }),
expectedRelease: 'patch'
},
{
name: 'default config + common context w/ minor updates using gitmoji semver',
pluginConfig: {
semver: true
semver: true,
releaseNotes: {
commitUrlTemplate
}
},
context: getContext('common', { commits: { boring: 2, patch: 4, minor: 2 } }),
expectedRelease: 'minor'
},
{
name: 'default config + common context w/ major updates using gitmoji semver',
pluginConfig: {
semver: true
semver: true,
releaseNotes: {
commitUrlTemplate
}
},
context: getContext('common', { commits: { boring: 2, patch: 4, minor: 2, major: 1 } }),
expectedRelease: 'major'
Expand Down
33 changes: 29 additions & 4 deletions test/integration/generate-notes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,16 @@ test.after(function () {
stub.restore()
})

const commitUrlTemplate = 'https://{source}/{owner}/{repo}/commit/{commit}'

const CASES = [
{
name: 'default config + common context w/ patch updates',
pluginConfig: {},
pluginConfig: {
releaseNotes: {
commitUrlTemplate
}
},
context: getContext('common', {
commits: { boring: 2, patch: 4 },
nextRelease: {
Expand All @@ -43,7 +49,11 @@ const CASES = [
},
{
name: 'default config + common context w/ minor updates',
pluginConfig: {},
pluginConfig: {
releaseNotes: {
commitUrlTemplate
}
},
context: getContext('common', {
commits: { boring: 2, patch: 4, minor: 2 },
nextRelease: {
Expand All @@ -55,7 +65,11 @@ const CASES = [
},
{
name: 'default config + common context w/ major updates',
pluginConfig: {},
pluginConfig: {
releaseNotes: {
commitUrlTemplate
}
},
context: getContext('common', {
commits: { boring: 2, patch: 4, minor: 2, major: 1 },
nextRelease: {
Expand All @@ -67,7 +81,11 @@ const CASES = [
},
{
name: 'default config + WIP context w/ minor updates',
pluginConfig: {},
pluginConfig: {
releaseNotes: {
commitUrlTemplate
}
},
context: getContext('wip', {
nextRelease: {
version: '1.0.0',
Expand All @@ -81,6 +99,7 @@ const CASES = [
pluginConfig: {
releaseNotes: {
template: '{{capitalize "cUSTOM"}} Helpers',
commitUrlTemplate,
helpers: {
capitalize: function (str = '') {
return str.length > 0 ? str[0].toUpperCase() + str.slice(1).toLowerCase() : str
Expand All @@ -101,6 +120,7 @@ const CASES = [
name: 'default config + custom issueResolution',
pluginConfig: {
releaseNotes: {
commitUrlTemplate,
issueResolution: {
removeFromCommit: true,
regex: /CUSTOM-\d{4}/g,
Expand All @@ -121,6 +141,7 @@ const CASES = [
pluginConfig: {
releaseNotes: {
semver: true,
commitUrlTemplate,
template: template
}
},
Expand All @@ -138,6 +159,7 @@ const CASES = [
pluginConfig: {
releaseNotes: {
semver: true,
commitUrlTemplate,
template
}
},
Expand All @@ -155,6 +177,7 @@ const CASES = [
pluginConfig: {
releaseNotes: {
semver: true,
commitUrlTemplate,
template
}
},
Expand All @@ -172,6 +195,7 @@ const CASES = [
pluginConfig: {
releaseNotes: {
semver: true,
commitUrlTemplate,
template
}
},
Expand All @@ -188,6 +212,7 @@ const CASES = [
pluginConfig: {
releaseNotes: {
semver: true,
commitUrlTemplate,
template,
issueResolution: {
removeFromCommit: true,
Expand Down