Skip to content
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

fix: read full git commit message (#22) #23

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/plenty-ways-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'changeset-conventional-commits': patch
---

fix: read full git commit message

Fixes an issue where the body of a git
commit message was ignored.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const conventionalCommitChangeset = async (

const commitsWithMessages = commitsSinceBase.map((commitHash) => ({
commitHash,
commitMessage: execSync(`git log -n 1 --pretty=format:%s ${commitHash}`).toString(),
commitMessage: execSync(`git log -n 1 --pretty=format:%B ${commitHash}`).toString(),
}));

const changelogMessagesWithAssociatedCommits = associateCommitsToConventionalCommitMessages(commitsWithMessages);
Expand Down
103 changes: 72 additions & 31 deletions src/utils/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,81 @@ describe('is-breaking', () => {
});
});

describe('is-conventional-commit', () => {
it('correctly identifies a feature conventional commit', () => {
expect(isConventionalCommit('feat: a change')).toEqual(true);
});
it('correctly identifies a fix conventional commit', () => {
expect(isConventionalCommit('fix: a change')).toEqual(true);
});
it('correctly identifies a perf conventional commit', () => {
expect(isConventionalCommit('perf: a change')).toEqual(true);
});
it('correctly identifies a revert conventional commit', () => {
expect(isConventionalCommit('revert: a change')).toEqual(true);
});
it('correctly identifies a docs conventional commit', () => {
expect(isConventionalCommit('docs: a change')).toEqual(true);
});
it('correctly identifies a style conventional commit', () => {
expect(isConventionalCommit('style: a change')).toEqual(true);
});
it('correctly identifies a chore conventional commit', () => {
expect(isConventionalCommit('chore: a change')).toEqual(true);
});
it('correctly identifies a refactor conventional commit', () => {
expect(isConventionalCommit('refactor: a change')).toEqual(true);
});
it('correctly identifies a test conventional commit', () => {
expect(isConventionalCommit('test: a change')).toEqual(true);
describe('is-breaking-multiline', () => {
it('correctly identifies a breaking change', () => {
expect(
isBreakingChange(
['feat!: a change', 'First paragraph description.', 'Second paragraph description.'].join('\n\n'),
),
).toEqual(true);
});
it('correctly identifies a build conventional commit', () => {
expect(isConventionalCommit('build: a change')).toEqual(true);
it('correctly identifies a breaking change with a scope', () => {
expect(
isBreakingChange(
['feat(scope)!: a change', 'First paragraph description.', 'Second paragraph description.'].join('\n\n'),
),
).toEqual(true);
});
// @see https://www.conventionalcommits.org/en/v1.0.0/#specification
it('correctly identifies a breaking change with all caps BREAKING CHANGE in message footer without body', () => {
expect(isBreakingChange(['feat(scope): a change', 'BREAKING CHANGE: vars now uppercase'].join('\n\n'))).toEqual(
true,
);
});
it('correctly identifies a breaking change with all caps BREAKING CHANGE in message footer', () => {
expect(
isBreakingChange(
[
'feat(scope): a change',
'First paragraph description.',
'Second paragraph description.',
'BREAKING CHANGE: vars now uppercase',
].join('\n\n'),
),
).toEqual(true);
});
it('correctly identifies a ci conventional commit', () => {
expect(isConventionalCommit('ci: a change')).toEqual(true);
it('correctly identifies a non-breaking change', () => {
expect(
isBreakingChange(
[
'feat: a change',
'First paragraph description.',
'Second paragraph description.',
'Reviewed-by: ZZZ\nRefs: #123',
].join('\n\n'),
),
).toEqual(false);
});
});

describe('is-conventional-commit', () => {
describe.each(['feat', 'fix', 'perf', 'revert', 'docs', 'style', 'chore', 'refactor', 'test', 'build', 'ci'])(
'correctly identifies a %s conventional commit',
(type: string) => {
it('with subject only', () => {
expect(isConventionalCommit(`${type}: a change`)).toEqual(true);
});
it('with subject and body', () => {
expect(
isConventionalCommit(
[`${type}: a change`, 'First paragraph description.', 'Second paragraph description.'].join('\n\n'),
),
).toEqual(true);
});
it('with subject, body and footers', () => {
expect(
isConventionalCommit(
[
`${type}: a change`,
'First paragraph description.',
'Second paragraph description.',
'Reviewed-by: ZZZ\nRefs: #123',
].join('\n\n'),
),
).toEqual(true);
});
},
);
it('correctly identifies a non-conventional commit', () => {
expect(isConventionalCommit('a change')).toEqual(false);
});
Expand Down