Skip to content

Commit

Permalink
fix(roc-plugin-repo): Made it work better with revert commits
Browse files Browse the repository at this point in the history
  • Loading branch information
dlmr committed Oct 3, 2017
1 parent 02d2291 commit 46395f1
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 16 deletions.
1 change: 1 addition & 0 deletions extensions/roc-plugin-repo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"commitizen": "^2.8.6",
"conventional-changelog": "^1.1.5",
"conventional-changelog-angular": "^1.5.0",
"conventional-commits-filter": "^1.0.0",
"cz-conventional-changelog": "^1.2.0",
"dateformat": "^2.0.0",
"eslint": "^3.19.0",
Expand Down
52 changes: 36 additions & 16 deletions extensions/roc-plugin-repo/src/semver/generateStatus.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import conventionalChangelog from 'conventional-changelog';
import conventionalCommitsFilter from 'conventional-commits-filter';
import semver from 'semver';
import { upperCase } from 'lodash';

Expand Down Expand Up @@ -61,11 +62,44 @@ export default async function generateStatus(
? latest[project].prerelease.hash
: latest[project].release.hash;

const commits = [];

conventionalChangelog(
{
preset: 'angular',
append: true,
transform(commit, cb) {
if (commit) {
// If the type of the commit is a revert commit we
// will get the scope from the subject instead
if (commit.type === 'revert') {
// Assums the Angular convention
// eslint-disable-next-line no-unused-vars
const [all, type, scope] = commit.subject.match(
/^(\w*)(?:\((.*)\))?: (.*)$/,
);
// eslint-disable-next-line no-param-reassign
commit.scope = scope;
}
commits.push(commit);
}

cb();
},
},
{},
{ reverse: true, from: from || fromRelease },
{
noteKeywords: [
'SCOPE',
'SCOPES',
'BREAKING CHANGE',
'BREAKING CHANGES',
],
},
)
.on('end', () => {
conventionalCommitsFilter(commits).forEach(commit => {
const multiScopes = getMultiScopes(commit, isMonorepo);
const autoScopes = getAutoScopes(commit, isMonorepo, projects);
// We are only interested in commits which scope is one of our projects
Expand All @@ -76,7 +110,6 @@ export default async function generateStatus(
!autoScopes.includes(project) &&
commit.scope !== project
) {
cb();
return;
}

Expand Down Expand Up @@ -105,21 +138,8 @@ export default async function generateStatus(
if (toPush) {
status[project].commits.push(commit);
}
cb();
},
},
{},
{ reverse: true, from: from || fromRelease },
{
noteKeywords: [
'SCOPE',
'SCOPES',
'BREAKING CHANGE',
'BREAKING CHANGES',
],
},
)
.on('end', () => {
});

resolve();
})
.resume();
Expand Down
14 changes: 14 additions & 0 deletions extensions/roc-plugin-repo/src/semver/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ export function conventionalChangelogOptions(preset, isMonorepo, projects) {
path: path.join(project.path, 'package.json'),
},
transform(commit, cb) {
if (commit) {
// If the type of the commit is a revert commit we
// will get the scope from the subject instead
if (commit.type === 'revert') {
// Assums the Angular convention
// eslint-disable-next-line no-unused-vars
const [all, type, scope] = commit.subject.match(
/^(\w*)(?:\((.*)\))?: (.*)$/,
);
// eslint-disable-next-line no-param-reassign
commit.scope = scope;
}
}

if (!isMonorepo) {
return cb(null, commit);
} else if (
Expand Down

0 comments on commit 46395f1

Please sign in to comment.