Skip to content

feat: Add a very basic pre-commit configuration #683

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
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hawksight
Copy link
Member

In #680 there were a couple of nits that I would personally solve by using pre-commit. I have added the most basic configuration here as a discussion topic. There may be other ways or tools to achieve the same goal of "not having to correct whitespace or newline nits"

Assuming you have this checked out:

# run once
pre-commit install
# run on any changed files
pre-commit run
# run on specific file(s)
pre-commit run --files deploy/charts/trust-manager/values.yaml

Reasons to have it

  • Standard tool available pretty widely
  • Sets a very low baseline of checks, to help contributors to catch empty space and newline problems.
  • Fixes the issue before committing so it is easier to get right first time
  • Only runs on the files you have changed / staged (unless you specify --all-files)
  • It is opt in! ie. it should not affect existing users by default. You must set it up per repo once, if want to benefit.

Concerns / addressed

I've left this section to record concerns about adding this, in the hope they can be addressed.

Will talk about this on some standup 🤞

@cert-manager-prow cert-manager-prow bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 11, 2025
@cert-manager-prow
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@cert-manager-prow cert-manager-prow bot added the dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. label Aug 11, 2025
@cert-manager-prow
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign jakexks for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@cert-manager-prow cert-manager-prow bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Aug 11, 2025
@hawksight hawksight marked this pull request as ready for review August 12, 2025 09:54
@cert-manager-prow cert-manager-prow bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 12, 2025
@maelvls
Copy link
Member

maelvls commented Aug 12, 2025

Hey,

I've tested it and it works:

$ brew install pre-commit
$ pre-commit install
$ echo "    " >>deploy/charts/trust-manager/values.yaml
$ git ci -a -m test
trim trailing whitespace.................................................Failed
- hook id: trailing-whitespace
- exit code: 1
- files were modified by this hook

Fixing deploy/charts/trust-manager/values.yaml

fix end of files.........................................................Failed
- hook id: end-of-file-fixer
- exit code: 1
- files were modified by this hook

Fixing deploy/charts/trust-manager/values.yaml

Upon testing it, I am slightly annoyed by the slowness of git commit, especially in context of large rebases.

I'm using my editor (VS Code + trailing-spaces extension) for spotting trailing whitespace and removing them, and also for spotting missing EOF newlines.

Not sure what to do next, so leaving it up to other maintainers! 😇

Copy link
Member

@erikgb erikgb left a comment

Choose a reason for hiding this comment

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

I am not a huge fan of pre-commit hooks, but I have no issues with them being added to our projects - if it's helpful for other contributors. I just tested this feature branch locally, and as I don't use pre-commit hooks everything seems to be working as before.

Change looks good to me, but I would like @SgtCoDFish to have an opinion on this as well.

/lgtm

@cert-manager-prow cert-manager-prow bot added the lgtm Indicates that a PR is ready to be merged. label Aug 12, 2025
@erikgb erikgb requested a review from SgtCoDFish August 12, 2025 10:57
@SgtCoDFish
Copy link
Member

My starting point for reviewing this is: would this cause a large maintenance burden or would this break anything? I don't think it'll do either of those things - for most it would at worst be a slight distraction.

I wouldn't personally use this, because I really value a high level of control over my commits, but I can see why this might be valuable to others.

I'd be happy to merge this given it has very low impact - I think my gut says that this would be a good fit for a page under https://cert-manager.io/docs/contributing/ so it's not explicitly in-repo, but I don't think that's a blocker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. lgtm Indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants