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

Add native support for pre-commit hook #140

Open
mszostok opened this issue Apr 8, 2022 · 6 comments
Open

Add native support for pre-commit hook #140

mszostok opened this issue Apr 8, 2022 · 6 comments
Labels
enhancement New feature or request
Milestone

Comments

@mszostok
Copy link
Owner

mszostok commented Apr 8, 2022

Description

The native support for pre-commit hook was requested by external users.

To integrate with https://pre-commit.com/ the .pre-commit-hooks.yaml file needs to be added to the root for repository.

Example:

- id: codeowners-validator-docker
  name: Validate CODEOWNERS file
  description: Ensures the correctness of your CODEOWNERS file.
  language: docker_image
  # TODO: types: hardcode expected file location?
  entry:  ghcr.io/mszostok/codeowners-validator:stable
- id: codeowners-validator
  name: Validate CODEOWNERS file
  description: Ensures the correctness of your CODEOWNERS file.
  language: golang
  # TODO: types: hardcode expected file location?
  entry: codeowners-validator

To support the input parameters, the codeowners-validator CLI should accept flags or config file.

Reasons

Support https://pre-commit.com/ out of the box to simplify external user workflow.

@mszostok mszostok added the enhancement New feature or request label Apr 8, 2022
@mszostok
Copy link
Owner Author

mszostok commented Apr 8, 2022

Hi @peterdemin and @jeremycohen!

You both posted that the pre-commit support would be nice to see in codeowners-validator.

Do you already have snippets on how you use it with pre-commit? I see, one problem that the CLI supports for now only env variables, where pre-commit allows only flags. For example:

-   repo: https://github.com/path/to/your/hook/repo
    rev: badf00ddeadbeef
    hooks:
    -   id: my-hook-script-id
        args: [--myarg1=1, --myarg1=2]

Additionally, you want to use the docker_image, go or system option? The last option, AFAIK, the bin needs to be preinstalled.

@peterdemin
Copy link

peterdemin commented Apr 8, 2022

I don't like our setup, because we don't have control over which version to use. I still put it here so others could avoid our mistakes:

We use gh CLI to figure out binary management:

gh extension install mszostok/gh-validate-codeowners

.pre-commit-config.yaml:

  - id: verify_codeowners
    name: verify_codeowners
    entry: tools/validate_codeowners.sh
    language: script
    files: CODEOWNERS

tools/validate_codeowners.sh:

env REPOSITORY_PATH="." CHECKS="syntax,files,duppatterns" gh validate-codeowners

@mszostok mszostok added this to the Next milestone Apr 15, 2022
@jeremycohen
Copy link
Contributor

Sorry I didn't get back sooner. Here's roughly how we currently use this script to look for unowned files in a specific subdirectory:

REPOSITORY_PATH=... EXPERIMENTAL_CHECKS="notowned" NOT_OWNED_CHECKER_SKIP_PATTERNS=... CHECKS="files,duppatterns,syntax" NOT_OWNED_CHECKER_SUBDIRECTORIES=... ./bin/codeowners-validator

We don't have a precommit hook yet for this, but I would guess it would look like @peterdemin's setup if we were to do so (lower-pri item for us, not typically a common error to hit for devs).

@mszostok mszostok modified the milestones: Next, v0.8.0 Aug 17, 2022
@dudicoco
Copy link

Hi @mszostok, any updates on this one?

@dannysauer
Copy link

Since this is apparently dead, what about #199?

@bobertrublik
Copy link

@dannysauer @mszostok I'd be happy to fix any issues I had when I wrote the PR last year. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants