Skip to content

Support linting more than the commit message itself #2455

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

Open
zimme opened this issue Feb 17, 2021 · 8 comments
Open

Support linting more than the commit message itself #2455

zimme opened this issue Feb 17, 2021 · 8 comments

Comments

@zimme
Copy link

zimme commented Feb 17, 2021

I would like to create a plugin for commitlint that would lint the committer/author email to only allow email domains from a list i.e. company emails only and possibly another to make sure commits are signed.

Would a PR that adds some fields to the parsed variable in the rules function be welcome?

Are there better ways of doing this maybe and it's not interesting to add support for it in commitlint?

@iamscottcab
Copy link
Collaborator

Given that this is fairly domain specific it's likely that a custom plugin would be the way to go.

https://commitlint.js.org/#/reference-plugins

If you follow the steps under Rules in Plugins or test it with Local Plugins you should be able to log out the parsed value and see if you have access to the details of the person making the commit.

I did have a dummy plugin sitting around a while ago but don't have access to one right now or I would show a simple Proof of Concept.

@zimme
Copy link
Author

zimme commented Feb 18, 2021

As I wrote, would a PR be accepted to add fields to the parsed variable in that custom plugin function. The reason I asked is because the information I need is not available in the parsed values and the raw property only contain the commit message and not thw author/comitter info.

@escapedcat
Copy link
Member

Wouldn't know any reason why not. @armano2 you have any objections to this?

@iamscottcab
Copy link
Collaborator

As I wrote, would a PR be accepted to add fields to the parsed variable in that custom plugin function. The reason I asked is because the information I need is not available in the parsed values and the raw property only contain the commit message and not thw author/comitter info.

Apologies I misread that this morning. I think if it's relevant to parsing the commit and it's something trivial to expose for plugin developers then that seems like a good idea to me.

@zimme
Copy link
Author

zimme commented Feb 18, 2021

We've all been there 🤦‍♂️ but it seems such an addition would not get shut down so I'll try and look into adding this. I've had a quick look over the code base and found the parse logic but it's not super obvious by the 10 min I spent looking where the git commit message are fetched.

Do anyone have any pointers on where I would start looking to add this?

@zimme
Copy link
Author

zimme commented Feb 19, 2021

Found where things need to be changed for this to be supported, it seems the git-raw-commits package supports getting the committer and author emails by using the placeholders from git log's pretty format, %cE and &aE, in addition to the message %B.

I hope I'll have time to add this over the next couple of weeks, kinda swamped at work and this isn't too high on my priority list currently.

@Billy-
Copy link

Billy- commented Mar 15, 2021

related: #2118 and #321

@AdeAttwood
Copy link
Member

AdeAttwood commented May 1, 2021

Just had a look into this. I think it's the same as #321 and there's not a lot we can do due to the parser. We can get all the info we need from get-raw-commits but the parser will not parse them without a bit of trickery.

There is a possibility of adding them to "notes" by adding something to the parserOptions.noteKeywords then using the format of

%B

COMMIT-USER: %cn
COMMIT-EMAIL: %ce

I think a good option would be to add it as another check in CI or git pre-commit hook

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

No branches or pull requests

5 participants