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

feat: Allow enum options to be newline delimited only #205

Merged
merged 4 commits into from
Oct 11, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,20 @@ feat(ui): Add `Button` component.

```yml
with:
# Configure which types are allowed.
# Configure which types are allowed (newline delimited).
# Default: https://github.com/commitizen/conventional-commit-types
types: |
fix
feat
# Configure which scopes are allowed.
# Configure which scopes are allowed (newline delimited).
scopes: |
core
ui
# Configure that a scope must always be provided.
requireScope: true
# Configure which scopes are disallowed in PR titles. For instance by setting
# the value below, `chore(release): ...` and `ci(e2e,release): ...` will be rejected.
# Configure which scopes (newline delimited) are disallowed in PR
# titles. For instance by setting # the value below, `chore(release):
# ...` and `ci(e2e,release): ...` will be rejected.
disallowScopes: |
release
# Configure additional validation for the subject based on a regex.
Expand All @@ -83,8 +84,8 @@ feat(ui): Add `Button` component.
doesn't start with an uppercase character.
# If you use GitHub Enterprise, you can set this to the URL of your server
githubBaseUrl: https://github.myorg.com/api/v3
# If the PR contains one of these labels, the validation is skipped.
# Multiple labels can be separated by newlines.
# If the PR contains one of these labels (newline delimited), the
# validation is skipped.
# If you want to rerun the validation when labels change, you might want
# to use the `labeled` and `unlabeled` event triggers in your workflow.
ignoreLabels: |
Expand Down Expand Up @@ -180,4 +181,4 @@ When using "Squash and merge" on a PR with only one commit, GitHub will suggest
# Related to `validateSingleCommit` you can opt-in to validate that the PR
# title matches a single commit to avoid confusion.
validateSingleCommitMatchesPrTitle: true
```
```
8 changes: 4 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ branding:
color: 'green'
inputs:
types:
description: "Provide custom types if you don't want the default ones from https://www.conventionalcommits.org"
description: "Provide custom types (newline delimited) if you don't want the default ones from https://www.conventionalcommits.org."
required: false
scopes:
description: "Configure which scopes are allowed."
description: "Configure which scopes are allowed (newline delimited)."
required: false
requireScope:
description: "Configure that a scope must always be provided."
required: false
disallowScopes:
description: 'Configure which scopes are disallowed in PR titles.'
description: 'Configure which scopes are disallowed in PR titles (newline delimited).'
required: false
subjectPattern:
description: "Configure additional validation for the subject based on a regex. E.g. '^(?![A-Z]).+$' ensures the subject doesn't start with an uppercase character."
Expand All @@ -36,7 +36,7 @@ inputs:
description: "If you use Github Enterprise, you can set this to the URL of your server (e.g. https://github.myorg.com/api/v3)"
required: false
ignoreLabels:
description: "If the PR contains one of these labels, the validation is skipped. Multiple labels can be separated by newlines. If you want to rerun the validation when labels change, you might want to use the `labeled` and `unlabeled` event triggers in your workflow."
description: "If the PR contains one of these labels (newline delimited), the validation is skipped. If you want to rerun the validation when labels change, you might want to use the `labeled` and `unlabeled` event triggers in your workflow."
required: false
headerPattern:
description: "If you're using a format for the PR title that differs from the traditional Conventional Commits spec, you can use this to customize the parsing of the type, scope and subject. The `headerPattern` should contain a regex where the capturing groups in parentheses correspond to the parts listed in `headerPatternCorrespondence`. For more details see: https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-commits-parser#headerpattern"
Expand Down
2 changes: 1 addition & 1 deletion src/ConfigParser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const ENUM_SPLIT_REGEX = /[,\s]\s*/;
const ENUM_SPLIT_REGEX = /\n/;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it makes sense since \r, by itself, is just a carriage return rather than a newline. For Windows file editing, it'd typically have \r\n which would still be split, and then subsequently trimmed, correctly. I'll push a change to add \r\n to the test.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds fair, thank you for your feedback!


module.exports = {
parseEnum(input) {
Expand Down
13 changes: 2 additions & 11 deletions src/ConfigParser.test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
const ConfigParser = require('./ConfigParser');

describe('parseEnum', () => {
it('parses commas', () => {
expect(ConfigParser.parseEnum('one, two,three, \nfour ')).toEqual([
'one',
'two',
'three',
'four'
]);
});

it('parses white space', () => {
expect(ConfigParser.parseEnum('one two\nthree \n\rfour')).toEqual([
it('parses newline-delimited lists, trimming whitespace', () => {
expect(ConfigParser.parseEnum('one \ntwo \nthree \r\nfour')).toEqual([
'one',
'two',
'three',
Expand Down