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(parse): allow setting fieldPattern in parserOpts #3538

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
34 changes: 24 additions & 10 deletions @commitlint/parse/src/index.test.ts
Expand Up @@ -169,24 +169,38 @@ test('registers inline #', async () => {
});

test('keep -side notes- in the body section', async () => {
const header = "type(some/scope): subject"
const body =
"CI on master branch caught this:\n\n" +
"```\n" +
"Unhandled Exception:\n" +
const header = 'type(some/scope): subject';
const body =
'CI on master branch caught this:\n\n' +
'```\n' +
'Unhandled Exception:\n' +
"System.AggregateException: One or more errors occurred. (Some problem when connecting to 'api.mycryptoapi.com/eth')\n\n" +
"--- End of stack trace from previous location where exception was thrown ---\n\n" +
"at GWallet.Backend.FSharpUtil.ReRaise (System.Exception ex) [0x00000] in /Users/runner/work/geewallet/geewallet/src/GWallet.Backend/FSharpUtil.fs:206\n" +
"...\n" +
"```";
'--- End of stack trace from previous location where exception was thrown ---\n\n' +
'at GWallet.Backend.FSharpUtil.ReRaise (System.Exception ex) [0x00000] in /Users/runner/work/geewallet/geewallet/src/GWallet.Backend/FSharpUtil.fs:206\n' +
'...\n' +
'```';

const message = header + "\n\n" + body
const message = header + '\n\n' + body;
escapedcat marked this conversation as resolved.
Show resolved Hide resolved

const actual = await parse(message);

expect(actual.body).toBe(body);
});

test('allows separating -side nodes- by setting parserOpts.fieldPattern', async () => {
const message =
'type(scope): subject\n\nbody text\n-authorName-\nrenovate[bot]';
const changelogOpts = {
parserOpts: {
fieldPattern: /^-(.*)-$/,
},
};
const actual = await parse(message, undefined, changelogOpts.parserOpts);

expect(actual.body).toBe('body text');
expect(actual).toHaveProperty('authorName', 'renovate[bot]');
});

test('parses references leading subject', async () => {
const message = '#1 some subject';
const opts = await require('conventional-changelog-angular');
Expand Down
2 changes: 1 addition & 1 deletion @commitlint/parse/src/index.ts
Expand Up @@ -11,8 +11,8 @@ export default async function parse(
const defaultOpts = (await defaultChangelogOpts).parserOpts;
const opts = {
...defaultOpts,
fieldPattern: null,
...(parserOpts || {}),
fieldPattern: null
};
const parsed = parser(message, opts) as Commit;
parsed.raw = message;
Expand Down
1 change: 1 addition & 0 deletions @commitlint/types/src/parse.ts
Expand Up @@ -34,6 +34,7 @@ export type Parser = (

export interface ParserOptions {
commentChar?: string;
fieldPattern?: RegExp;
headerCorrespondence?: string[];
headerPattern?: RegExp;
issuePrefixes?: string[];
Expand Down