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

Feature => Pre-commit hook #14

Merged
merged 12 commits into from
Aug 9, 2019
Merged

Feature => Pre-commit hook #14

merged 12 commits into from
Aug 9, 2019

Conversation

sc250024
Copy link
Contributor

@sc250024 sc250024 commented Aug 7, 2019

Enables this repository to serve as source for a helm-docs pre-commit hook compatible with the Pre-commit project. Alternatively, this could be its own repository; something like pre-commit-helm-docs.

Huge shoutout to @antonbabenko and the https://github.com/antonbabenko/pre-commit-terraform project, where I took most of the code from.

Description

In a nutshell, this enables someone using pre-commit to do something like the following in their Helm charts repository:

.pre-commit-config.yaml

- repo: https://github.com/norwoodj/helm-docs
  rev: master
  hooks:
    - id: helm_docs

If there are changes to their Helm chart (which are detected by helm-docs itself), this will automatically generate a corresponding README.md file. If the user hadn't updated and staged the README.md file before, this hook will fail, and ensure that a user always updates their README.md before they do a commit.

Motivation and Context

I was always doing this manually before:

$ cd stable/some-chart
$ helm-docs
$ git add README.md

Since I make extensive use of the Pre-Commit project, I wanted a hook to automatically generate the README.md for a chart I just changed.

How Has This Been Tested?

Tested locally. If you want to test a Helm chart repo against this hook, run the following in your Helm charts repo:

$ pwd
/a/local/copy/of/this/branch/helm-docs

$ cd /some/helm/chart/repo
$ vim stable/mychart/Chart.yaml # Do a quick version bump for testing
$ git add stable/mychart
$ pre-commit try-repo --all-files --verbose '/a/local/copy/of/this/branch/helm-docs' helm_docs

You should see that the hook will say "FAIL" because the README.md file changed, but it hasn't been staged yet. After staging, the pre-commit try-repo command will succeed.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@RothAndrew
Copy link

This would be fantastic! I use pre-commit a lot and this is a perfect fit for it.

scripts/helm_docs.sh Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
.pre-commit-hooks.yaml Outdated Show resolved Hide resolved
@norwoodj
Copy link
Owner

norwoodj commented Aug 7, 2019

Hey @sc250024 thanks a ton for the submission! I had a few comments, wasn't entirely clear why the whole getopt implementation was necessary for the script, but otherwise this is fantastic. If you can fix the couple comments up, I will merge this

.pre-commit-hooks.yaml Outdated Show resolved Hide resolved
scripts/helm_docs.sh Outdated Show resolved Hide resolved
@sc250024
Copy link
Contributor Author

sc250024 commented Aug 9, 2019

@norwoodj I updated based on the changes you requested.

@norwoodj norwoodj merged commit 56bad9e into norwoodj:master Aug 9, 2019
@sc250024 sc250024 deleted the feature/PreCommitHook branch August 9, 2019 15:04
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.

3 participants