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

Match IDs? #95

Closed
AustinMatherne opened this issue Oct 16, 2017 · 6 comments
Closed

Match IDs? #95

AustinMatherne opened this issue Oct 16, 2017 · 6 comments
Labels

Comments

@AustinMatherne
Copy link

Can commitlint validate numerical IDs?

PRJ-123: valid commit
PRJ-789: valid commit
MFB-123: valid commit
MFB: invalid commit
@marionebl
Copy link
Contributor

This feature is not implemented yet. There is a PR taking a stab at it: https://github.com/marionebl/commitlint/pull/76, where I added an outline how this could work:

// commitlint.config.js
module.exports = {
  parserPreset: './parser-preset',
  rules: {
     'references-empty': [2, 'never'],
     // extended use case, check if id is present
     'references-enum': getIssueIds().then((ids) => [2, 'always', ids])
  }
}

// parser-preset
module.exports = {
  paserOpts: {
    issuePrefixes: ['PRJ-', 'MFB-']
  }
};

@marionebl
Copy link
Contributor

@AustinMatherne Would the feature match your use case?

@AustinMatherne
Copy link
Author

AustinMatherne commented Oct 20, 2017

@marionebl What is the value of ids? Is it a RegEx, or an array of all possible IDs?

I'm matching against thousands of numerical IDs. Generating an array of them is easy enough, but seems less than ideal.

Thanks!

@marionebl
Copy link
Contributor

marionebl commented Oct 20, 2017

It is an string[], like the other *-enum rules. My impression is you'd be catered by this anyways as for your example the *-enum rule is not necessary:

  1. given references-empty: [2, 'never'], commits without issue id would fail as outlined in your examples
  2. optionally, given 'references-enum': [2, 'always', someArray] you could fetch the actual list of available/allowed issue ids (say by fetching them from JIRA) and check if the given ID is present. The pattern is established for the lerna and patternplate configs and works reasonably well: https://github.com/marionebl/commitlint/blob/master/%40commitlint/config-lerna-scopes/index.js#L6

I'd like to keep parsing/regexp matching out of commitlint. If the current conventional-commits-parser capabilities are not enough to distinguish between valid and invalid references we can work on improving it.

@AustinMatherne
Copy link
Author

In theory validating the ID against a real Jira story would be nice, but there's no way my team would accept an online requirement in order to make commits. Instead I'd have to create an array for every value between "0" and at least "99999".

@happyhunter7
Copy link
Contributor

@AustinMatherne I created a plugin and a config special for JIRA commit messages style commitlint-jira ;) I think this will be useful for you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants