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: add pre-commit support #138

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Thomy90
Copy link

@Thomy90 Thomy90 commented Jan 23, 2023

Hi guys,

great tool. I have looked around and this tool is exactly what i am looking for.

I would like to use your tool in combination with pre-commit. The cool thing is then to run your tool during git hooks.

I have seen that for example the project golangci-lint also provide this pre-commit integration.
https://github.com/golangci/golangci-lint/blob/master/.pre-commit-hooks.yaml

If you have questions, feel free to ask me.

Kind Regards,
Thomy90

@google-cla
Copy link

google-cla bot commented Jan 23, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@willnorris
Copy link
Collaborator

willnorris commented Jan 23, 2023

seems reasonable to me on the surface.

Some missing context here is that "pre-commit" seems to refer to https://pre-commit.com/ (and https://github.com/pre-commit). So it looks like we would just add this .pre-commit-hooks.yaml file, and then anyone that wanted to use addlicense would add an entry to their .pre-commit-config.yaml file to the effect of:

repos:
- repo: https://github.com/google/addlicense
  rev: v1.1.1
  hooks:
  - id: addlicense
    args: [ "-c", "Company, Inc", "*.go" ]

We don't need a .pre-commit-config.yaml file in addlicense unless we actually wanted to use pre-commit to run hooks ourselves.

Maybe add a comment at the top of the file that indicates that this is for use with pre-commit.com ?

@Thomy90
Copy link
Author

Thomy90 commented Jan 23, 2023

thanks a lot for your advice.

Yes, exactly. Your code snippet is the way i meant how addlicense can be used as a pre-commit hook.

Good point with the comment.

How about a extension in the readme with a code snippet to makes it clear how running addlicense with pre-commit?

For example:

Running with pre-commit

This is the official pre-commit hook for addlicense.

Activate by adding it to your .pre-commit-config.yaml:

repos:
- repo: https://github.com/google/addlicense
  rev: ''  # Use the sha / tag you want to point at
  hooks:
  - id: addlicense
    args: [ "-c", "Company, Inc", "*.go" ]

@rickeylev
Copy link

@mco-gh @willnorris Would one of you be willing to review/merge this PR? I, too, would like pre-commit to Just Work with addlicense

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