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

commitcheck: lint commit messages #18782

Closed
wants to merge 1 commit into from

Conversation

benesch
Copy link
Contributor

@benesch benesch commented Sep 26, 2017

Whipped this up on the train yesterday. Won't be offended if we think this is a bad idea, but seems to work well on the several included test cases.


Gently remind developers of the proper commit message style after they
write a non-conforming commit. Developers who really hate the warning
can opt out by setting the COCKROACH_NO_LINT_COMMITS environment
variable.

commitcheck warns about the following:

  • lines longer than 72 characters
  • a missing blank line between the summary and description
  • summaries without a scope: prefix
  • summaries that do not separate scopes with a comma and without
    whitespace
  • scopes not matching a package/folder name or an approved
    meta-scope, like mvcc or *
  • summaries with a capital letter after the colon

@benesch benesch requested a review from a team September 26, 2017 14:57
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@tbg tbg left a comment

Choose a reason for hiding this comment

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

I'm 👎 unless I am convinced of the benefits of this change. There are disadvantages: eat more CI, have the package-hardcoding below rot, more burden on external contributors, just one more thing that can break in the merge path.

@benesch
Copy link
Contributor Author

benesch commented Sep 26, 2017

How would you feel about having the linter post a comment with the complaints to the PR instead of blocking the merge? The problem I'm trying to solve is that, as a new employee or external contributor, it's very hard to internalize all the commit message rules for your first PR. Then reviewers often let the bad commit messages slide because it's a pain to make people run through CI again. If we can warn people early, they can address the commit message fix while addressing the rest of their review feedback.

@dt
Copy link
Member

dt commented Sep 26, 2017

Having to wait for CI to fail without a way to run the check locally, in make lint, is a bummer. I wonder if we could at least try to figure out the merge base using some sane heuristics so we could lint locally, pre-PR.

EDIT: e.g. default of origin/master configurable via git config, then the value in any given run overridable via env or flag (ie. when your merge base should be from release branch or whatever).

@a-robinson
Copy link
Contributor

Are we being negatively affected by occasionally having commits without a package prefix? We do a pretty good job of it and the few exceptions have never bothered me, but maybe other people are using them for something that I'm not?

@tbg
Copy link
Member

tbg commented Sep 26, 2017

@benesch I'm more on board with a lintbot such as rust-highfive.

@benesch
Copy link
Contributor Author

benesch commented Sep 26, 2017

@a-robinson if you base email filters on the package prefix, commits with inconsistent/missing package prefixes are a real drag. (Though only inasmuch as the missing prefix propagates to the PR title.)

@tbg
Copy link
Member

tbg commented Sep 26, 2017

@benesch can't you base your filters on the below section? Sounds a little unreasonable to force developers to transcribe certain information from their diff into the commit title.

image

@benesch
Copy link
Contributor Author

benesch commented Sep 26, 2017

Sounds a little unreasonable to force developers to transcribe certain information from their diff into the commit title.

Er, isn't that exactly what our commit message style guide already does? In my mind, either the scope: bit is useful and we should enforce it, or the scope: bit is not useful and we shouldn't waste our time with it.

@benesch
Copy link
Contributor Author

benesch commented Sep 26, 2017

As I understand it, the reason to ask for an explicit scope: is because often you incidentally touch files (in, say, util), but the only meaningful changes are in server. It's pretty hard to determine that automatically.

To be honest I'm fairly neutral on whether these scopes are useful. I just want them to be consistent if we're going to have them.

@benesch benesch changed the title github-pull-request-make: lint commit messages commitcheck: lint commit messages Oct 11, 2017
@benesch
Copy link
Contributor Author

benesch commented Oct 11, 2017

Ok, PTAL! I've updated this to instead install a commit-msg githook which gently warns you when your commit message doesn't match our standards. It does not fail the commit.

@benesch benesch force-pushed the lint-commits branch 3 times, most recently from f4b495d to 428c0e8 Compare October 16, 2017 19:51
@knz
Copy link
Contributor

knz commented Oct 17, 2017

Please extend the commit message and the PR description at the top with a summary of the checks performed by the linter. It's not obvious to me by reading the code.

@knz
Copy link
Contributor

knz commented Oct 17, 2017

Review status: 0 of 6 files reviewed at latest revision, 2 unresolved discussions, all commit checks successful.


pkg/cmd/commitcheck/main.go, line 130 at r1 (raw file):

}

// Everything after scissorsLine in a Git commit message is ignored.

Why? What is this string and where does it come from?


pkg/cmd/commitcheck/main.go, line 183 at r1 (raw file):

}

const noLintEnvVar = "COCKROACH_NO_LINT_COMMITS"

Document this in the commit message.


Comments from Reviewable

@benesch
Copy link
Contributor Author

benesch commented Oct 17, 2017

Review status: 0 of 6 files reviewed at latest revision, 2 unresolved discussions, all commit checks successful.


pkg/cmd/commitcheck/main.go, line 130 at r1 (raw file):

Previously, knz (kena) wrote…

Why? What is this string and where does it come from?

https://git-scm.com/docs/git-commit#git-commit-scissors

It's included in the message (and later stripped) if you run git commit -v.


Comments from Reviewable

@knz
Copy link
Contributor

knz commented Oct 17, 2017

Review status: 0 of 6 files reviewed at latest revision, 2 unresolved discussions, all commit checks successful.


pkg/cmd/commitcheck/main.go, line 130 at r1 (raw file):

Previously, benesch (Nikhil Benesch) wrote…

https://git-scm.com/docs/git-commit#git-commit-scissors

It's included in the message (and later stripped) if you run git commit -v.

Add this explanation in a comment.


Comments from Reviewable

Gently remind developers of the proper commit message style after they
write a non-conforming commit. Developers who really hate the warning
can opt out by setting the COCKROACH_NO_LINT_COMMITS environment
variable.

commitcheck warns about the following:

   * lines longer than 72 characters
   * a missing blank line between the summary and description
   * summaries without a `scope:` prefix
   * summaries that do not separate scopes with a comma and without
     whitespace
   * scopes not matching a package/folder name or an approved
     meta-scope, like `mvcc` or `*`
   * summaries with a capital letter after the colon
@benesch
Copy link
Contributor Author

benesch commented Oct 17, 2017

Done.


Review status: 0 of 6 files reviewed at latest revision, 2 unresolved discussions.


pkg/cmd/commitcheck/main.go, line 130 at r1 (raw file):

Previously, knz (kena) wrote…

Add this explanation in a comment.

Done.


pkg/cmd/commitcheck/main.go, line 183 at r1 (raw file):

Previously, knz (kena) wrote…

Document this in the commit message.

Done.


Comments from Reviewable

tbg added a commit to tbg/cockroach that referenced this pull request Dec 2, 2017
Targeted alternative (or perhaps short-term stand-in) for [1].
I think it's worth linting this sooner rather than later.

Release notes: none.

[1]: cockroachdb#18782
@danhhz
Copy link
Contributor

danhhz commented Dec 4, 2017

Does this githook prevent me from doing git commit -m "WIP" to save and push my progress at the end of the day?

I'm generally 👎 on using githooks for anything unless it's absolutely necessary. They tend to be too prescriptive of people's pre-PR workflows.

@benesch
Copy link
Contributor Author

benesch commented Dec 4, 2017 via email

@benesch
Copy link
Contributor Author

benesch commented Feb 20, 2018

This rotted, and @knz wrote a nice linter for release notes. Closing. ¯_(ツ)_/¯

@benesch benesch closed this Feb 20, 2018
@benesch benesch deleted the lint-commits branch February 24, 2018 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants