Skip to content

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

Open
hawksight wants to merge 3 commits into
cert-manager:mainfrom
hawksight:pre-commit
Open

feat: Add a very basic pre-commit configuration#683
hawksight wants to merge 3 commits into
cert-manager:mainfrom
hawksight:pre-commit

Conversation

@hawksight

Copy link
Copy Markdown
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 🤞

Signed-off-by: Peter Fiddes <peter.fiddes@jetstack.io>
@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
Copy Markdown
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
Copy Markdown
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.

Details 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

maelvls commented Aug 12, 2025

Copy link
Copy Markdown
Member

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! 😇

@erikgb erikgb left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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.

Signed-off-by: Peter Fiddes <peter.fiddes@jetstack.io>
@cert-manager-prow

Copy link
Copy Markdown
Contributor

New changes are detected. LGTM label has been removed.

@cert-manager-prow cert-manager-prow Bot removed the lgtm Indicates that a PR is ready to be merged. label Aug 19, 2025
Signed-off-by: Peter Fiddes <peter.fiddes@jetstack.io>
@hawksight

Copy link
Copy Markdown
Member Author

Adding comment to the end of the has inf323703 seemed to break functionality, so I added a proper reference in 69d704b.

@hawksight

Copy link
Copy Markdown
Member Author

Thanks all for the feedback.

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.

@SgtCoDFish - I could follow up with a PR to the website under contributing as you suggested? In the context, these are provided as optional to use?

@cert-manager-bot

Copy link
Copy Markdown
Contributor

Issues go stale after 6 months of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues remain open for an additional 3 months of inactivity and then close.
If this issue is safe to close now please do so with /close.
/lifecycle stale

@cert-manager-prow cert-manager-prow Bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 17, 2026
@cert-manager-bot

Copy link
Copy Markdown
Contributor

Stale issues rot after 3 months of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 3 months of inactivity.
If this issue is safe to close now please do so with /close.
/lifecycle rotten
/remove-lifecycle stale

@cert-manager-prow cert-manager-prow Bot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels May 19, 2026
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. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. 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.

5 participants