Skip to content

Commit

Permalink
feat(flow): add new flow step
Browse files Browse the repository at this point in the history
added a step to check if the commit is a breaking change and append it to the
message

Fixes ##11
  • Loading branch information
cainaleaouk authored and hassankhan committed Nov 20, 2018
1 parent 4cdee96 commit 4249677
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 8 deletions.
9 changes: 9 additions & 0 deletions src/__fixtures__/commitAnswers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,12 @@ export const formattedBody = [
'fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in',
'culpa qui officia deserunt mollit anim id est laborum.',
].join(os.EOL);

export const formattedBreakingBody = [
'BREAKING CHANGE: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do',
'eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim',
'veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo',
'consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum',
'dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident,',
'sunt in culpa qui officia deserunt mollit anim id est laborum.',
].join(os.EOL);
4 changes: 2 additions & 2 deletions src/lib/createPrompts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('#createPrompts', () => {

it('creates valid prompts', () => {
const result = createPrompts({ config, pkg });
expect(result).toHaveLength(6);
expect(result).toHaveLength(7);
const scopePrompt = find(result, ['name', 'scope']) as Question;
expect(scopePrompt.choices).toBeUndefined();
});
Expand All @@ -35,7 +35,7 @@ describe('#createPrompts', () => {
},
};
const result = createPrompts({ config: pullRequestsConfig, pkg });
expect(result).toHaveLength(6);
expect(result).toHaveLength(7);

const scopePrompt = find(result, ['name', 'scope']) as Question;
expect(scopePrompt.choices).toHaveLength(2);
Expand Down
10 changes: 9 additions & 1 deletion src/lib/createPrompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
createScopeChoices,
formatGitBranchName,
} from './util';
import validateDescription from './validation/validateDescription';
import validateIssues from './validation/validateIssues';
import validateLowercase from './validation/validateLowercase';
import validateSubject from './validation/validateSubject';
Expand Down Expand Up @@ -46,12 +47,19 @@ export default ({ config, pkg }: CreatePrompts): Questions => {
type: 'input',
validate: validateSubject,
},
{
deafult: false,
message: 'Is this a breaking change?',
name: 'isBreak',
type: 'confirm',
validate: validateLowercase,
},
{
message:
'Provide a longer description of the change: (press enter to skip)',
name: 'body',
type: 'input',
validate: validateLowercase,
validate: validateDescription,
},
{
default: false,
Expand Down
10 changes: 10 additions & 0 deletions src/lib/formatCommit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ describe('#formatCommit', () => {
expect(result).toEqual(message);
});

it('should commit with breaking change', () => {
const message = [
'build(api): This took waaaaay too long',
FIXTURE.formattedBreakingBody,
'Fixes #11, fixes #65, fixes #3168',
].join(os.EOL + os.EOL);
const result = formatCommit({ ...FIXTURE, isBreak: true });
expect(result).toEqual(message);
});

it('should use the defaults if type and/or workflow are not defined', () => {
const result = formatCommit({
isIssueAffected: true,
Expand Down
6 changes: 5 additions & 1 deletion src/lib/formatCommit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default function formatCommit(answers: Answers) {
issues,
scope,
subject,
isBreak,
type = 'feat',
} = answers;

Expand All @@ -29,7 +30,10 @@ export default function formatCommit(answers: Answers) {
}: ${subject.trim()}`.slice(0, wrapOptions.width);

// Wrap these lines at 100 characters
const commitBody = wrap(body, wrapOptions);
const commitBody = wrap(
`${isBreak ? 'BREAKING CHANGE: ' : ''}${body ? body : ''}`,
wrapOptions,
);

// GitHub issue IDs
const formattedIssues = splitIssues(issues)
Expand Down
31 changes: 31 additions & 0 deletions src/lib/validation/validateDescription.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import validateDescription from './validateDescription';

describe('#validateDescription', () => {
describe('#Errors', () => {
it('should return error if input is empty and breaking change is true', () => {
expect(validateDescription('', { isBreak: true })).toContain(
'specify a description for breaking changes',
);
});

it('should return error if input is not lowercase', () => {
expect(
validateDescription('LOREM ipsum dolor sit amet', {
isBreak: false,
}),
).toContain('value must be all lowercase');
});
});

describe('#Success', () => {
it('should return true if input is empty and breaking change is false', () => {
expect(validateDescription('', { isBreak: false })).toBeTruthy();
});

it('should return true if input has value and breaking change is true', () => {
expect(
validateDescription('requires new user dependency', { isBreak: true }),
).toBeTruthy();
});
});
});
9 changes: 9 additions & 0 deletions src/lib/validation/validateDescription.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import validateLowercase from './validateLowercase';

export default (input: string, answers: any) => {
if (answers.isBreak && (!input || input === '')) {
return 'Must specify a description for breaking changes';
}

return validateLowercase(input);
};
27 changes: 23 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ array-unique@^0.3.2:
resolved "https://registry.yarnpkg.com/array-unique/-/array-unique-0.3.2.tgz#a894b75d4bc4f6cd679ef3244a9fd8f46ae2d428"
integrity sha1-qJS3XUvE9s1nnvMkSp/Y9Gri1Cg=

arrify@^1.0.1:
arrify@^1.0.0, arrify@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/arrify/-/arrify-1.0.1.tgz#898508da2226f380df904728456849c1501a4b0d"
integrity sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=
Expand Down Expand Up @@ -1162,7 +1162,7 @@ btoa-lite@^1.0.0:
resolved "https://registry.yarnpkg.com/btoa-lite/-/btoa-lite-1.0.0.tgz#337766da15801210fdd956c22e9c6891ab9d0337"
integrity sha1-M3dm2hWAEhD92VbCLpxokaudAzc=

buffer-from@1.x, buffer-from@^1.0.0:
buffer-from@1.x, buffer-from@^1.0.0, buffer-from@^1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==
Expand Down Expand Up @@ -2010,7 +2010,7 @@ dezalgo@^1.0.0, dezalgo@~1.0.3:
asap "^2.0.0"
wrappy "1"

diff@^3.2.0:
diff@^3.1.0, diff@^3.2.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12"
integrity sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==
Expand Down Expand Up @@ -4661,7 +4661,7 @@ make-dir@^1.0.0:
dependencies:
pify "^3.0.0"

make-error@1.x:
make-error@1.x, make-error@^1.1.1:
version "1.3.5"
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.5.tgz#efe4e81f6db28cadd605c70f29c831b58ef776c8"
integrity sha512-c3sIjNUow0+8swNwVpqoH4YCShKNFkMaw6oH1mNS2haDZQqkeZFlHS3dhoeEbKKmJB4vXpJucU6oH75aDYeE9g==
Expand Down Expand Up @@ -7299,6 +7299,20 @@ ts-jest@^23:
semver "^5.5"
yargs-parser "10.x"

ts-node@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-7.0.1.tgz#9562dc2d1e6d248d24bc55f773e3f614337d9baf"
integrity sha512-BVwVbPJRspzNh2yfslyT1PSbl5uIk03EZlb493RKHN4qej/D06n1cEhjlOJG69oFsE7OT8XjpTUcYf6pKTLMhw==
dependencies:
arrify "^1.0.0"
buffer-from "^1.1.0"
diff "^3.1.0"
make-error "^1.1.1"
minimist "^1.2.0"
mkdirp "^0.5.1"
source-map-support "^0.5.6"
yn "^2.0.0"

tslib@1.9.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.0.tgz#e37a86fda8cbbaf23a057f473c9f4dc64e5fc2e8"
Expand Down Expand Up @@ -7826,3 +7840,8 @@ yargs@^12.0.0:
which-module "^2.0.0"
y18n "^3.2.1 || ^4.0.0"
yargs-parser "^10.1.0"

yn@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/yn/-/yn-2.0.0.tgz#e5adabc8acf408f6385fc76495684c88e6af689a"
integrity sha1-5a2ryKz0CPY4X8dklWhMiOavaJo=

0 comments on commit 4249677

Please sign in to comment.