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 3 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
7 changes: 5 additions & 2 deletions README.md
Expand Up @@ -57,18 +57,21 @@ feat(ui): Add `Button` component.
```yml
with:
# Configure which types are allowed.
# Newline delimited.
jszwedko marked this conversation as resolved.
Show resolved Hide resolved
# Default: https://github.com/commitizen/conventional-commit-types
types: |
fix
feat
# 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.
# Newline delimited.
disallowScopes: |
release
# Configure additional validation for the subject based on a regex.
Expand All @@ -84,7 +87,7 @@ feat(ui): Add `Button` component.
# 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.
# Newline delimited.
# 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 +183,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
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 if you don't want the default ones from https://www.conventionalcommits.org. Newline delimited."
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, the validation is skipped. Newline delimited. 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
@@ -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
@@ -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 \n\rfour')).toEqual([
'one',
'two',
'three',
Expand Down