Skip to content

Commit

Permalink
feat(build): commit message integration check
Browse files Browse the repository at this point in the history
* commit message check, aids in changelog updates
  • Loading branch information
cdcabrera committed Oct 8, 2019
1 parent 26b3bcc commit c9691d3
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions tests/commit.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const { execSync } = require('child_process');

describe('Commit Message', () => {
it('should have consistently formatted commit messages', () => {
const stdout = execSync(`git cherry -v master`);
const messages = stdout
.toString()
.trim()
.split(/\n/g)
.map(message => {
const [hash, typeScope, issueNumber, ...description] = message.split(/\s/g).slice(1);
return {
hash,
typeScope,
issueNumber,
description: description.join(' ')
};
});

const messagesList = messages.map(message => {
const { typeScope = null, issueNumber = null, description = null } = message;

const issueNumberException = /(^chore\([\d\D]+\))|(^fix\([\d\D]+\))|(^[\d\D]+\(build\))/.test(typeScope);

const typeScopeValid =
(/(^[\d\D]+\([\d\D]+\):$)|(^[\d\D]+:$)/.test(typeScope) && 'valid') || 'INVALID: type scope';

const issueNumberValid =
(/(^issues\/[\d]+$)/.test(issueNumber) && 'valid') ||
(issueNumberException && 'valid') ||
'INVALID: issue number';

const descriptionValid =
(/(^[\d\D]+$)/.test(description || (issueNumberException && issueNumber)) && 'valid') ||
(issueNumberException && !description && issueNumber && 'valid') ||
'INVALID: description';

/**
* See CONTRIBUTING.md for commit messaging guidelines
*
* TypeScope is required and should be in the form of "<type>([scope]):" or "<type>:"
*
* IssueNumber is conditional and should be in the form of "issues/[issue number]"
* Exceptions are available for chore and fix type scopes, and "build" type scope "scopes"
*
* Description is required, can be in the form of "<string>"
*/
// expect(
return `${typeScope}<${typeScopeValid}> ${issueNumber}<${issueNumberValid}> ${description}<${descriptionValid}>`
// ).toMatch(/<valid>[\d\D]*<valid>[\d\D]*<valid>/);
});

expect(messagesList.filter(value => !/<valid>[\d\D]*<valid>[\d\D]*<valid>/.test(value))).toEqual([]);
});
});

0 comments on commit c9691d3

Please sign in to comment.