Skip to content

Commit

Permalink
fix: parse commit references based on git host
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Dec 5, 2017
1 parent 4ee3f87 commit d3b011e
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 69 deletions.
16 changes: 11 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@ const HOSTS_CONFIG = require('./lib/hosts-config');
*/
async function releaseNotesGenerator(pluginConfig, {commits, lastRelease, nextRelease, options: {repositoryUrl}}) {
const {parserOpts, writerOpts} = await loadChangelogConfig(pluginConfig);
commits = commits.map(rawCommit =>
Object.assign(rawCommit, conventionalCommitsParser(rawCommit.message, parserOpts))
);

const {resource: hostname, port, name: repository, owner, protocols} = gitUrlParse(repositoryUrl);
const protocol = protocols.includes('https') ? 'https' : protocols.includes('http') ? 'http' : 'https';

const {issue, commit, referenceActions, issuePrefixes} =
find(HOSTS_CONFIG, conf => conf.hostname === hostname) || HOSTS_CONFIG.default;
const parsedCommits = commits.map(rawCommit => ({
...rawCommit,
...conventionalCommitsParser(rawCommit.message, {...parserOpts, referenceActions, issuePrefixes}),
}));

const previousTag = lastRelease.gitTag || lastRelease.gitHead;
const currentTag = nextRelease.gitTag || nextRelease.gitHead;
const context = {
Expand All @@ -41,7 +46,8 @@ async function releaseNotesGenerator(pluginConfig, {commits, lastRelease, nextRe
previousTag,
currentTag,
linkCompare: currentTag && previousTag,
...(find(HOSTS_CONFIG, conf => conf.hostname === hostname) || HOSTS_CONFIG.default),
issue,
commit,
};

debug('version: %o', nextRelease.version);
Expand All @@ -51,7 +57,7 @@ async function releaseNotesGenerator(pluginConfig, {commits, lastRelease, nextRe
debug('previousTag: %o', previousTag);
debug('currentTag: %o', currentTag);

return getStream(intoStream.obj(commits).pipe(conventionalChangelogWriter(context, writerOpts)));
return getStream(intoStream.obj(parsedCommits).pipe(conventionalChangelogWriter(context, writerOpts)));
}

module.exports = releaseNotesGenerator;
34 changes: 34 additions & 0 deletions lib/hosts-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,53 @@ module.exports = {
hostname: 'github.com',
issue: 'issues',
commit: 'commit',
referenceActions: ['close', 'closes', 'closed', 'fix', 'fixes', 'fixed', 'resolve', 'resolves', 'resolved'],
issuePrefixes: ['#', 'gh-'],
},
bitbucket: {
hostname: 'bitbucket.org',
issue: 'issue',
commit: 'commits',
referenceActions: [
'close',
'closes',
'closed',
'closing',
'fix',
'fixes',
'fixed',
'fixing',
'resolve',
'resolves',
'resolved',
'resolving',
],
issuePrefixes: ['#'],
},
gitlab: {
hostname: 'gitlab.com',
issue: 'issues',
commit: 'commit',
referenceActions: ['close', 'closes', 'closed', 'closing', 'fix', 'fixes', 'fixed', 'fixing'],
issuePrefixes: ['#'],
},
default: {
issue: 'issues',
commit: 'commit',
referenceActions: [
'close',
'closes',
'closed',
'closing',
'fix',
'fixes',
'fixed',
'fixing',
'resolve',
'resolves',
'resolved',
'resolving',
],
issuePrefixes: ['#', 'gh-'],
},
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"conventional-changelog-express": "^0.2.0",
"conventional-changelog-jshint": "^0.2.0",
"cz-conventional-changelog": "^2.0.0",
"escape-string-regexp": "^1.0.5",
"eslint-config-prettier": "^2.3.0",
"eslint-plugin-prettier": "^2.3.0",
"nyc": "^11.1.0",
Expand Down
Loading

0 comments on commit d3b011e

Please sign in to comment.