Skip to content

Commit

Permalink
Support running Copywrite as a pre-commit hook via .pre-commit-hooks.…
Browse files Browse the repository at this point in the history
…yaml (#24)

* Add pre-commit-hooks for copywrite

* Add documentation for pre-commit hooks

* Add copywrite to our own pre-commit-config
  • Loading branch information
CalebAlbers authored Feb 2, 2023
1 parent 166e2ce commit 66e5399
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

---
repos:
- repo: https://github.com/hashicorp/copywrite
rev: v0.15.0 # Use any release tag
hooks:
- id: copywrite-headers
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
Expand Down
27 changes: 27 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
- id: add-headers
name: Add copyright headers
description: Adds missing copyright headers to all source code files
entry: go run .
language: golang
args: [headers]

- id: check-headers
name: Validate copyright headers
description: Checks if any copyright headers are missing, but does not make changes
entry: go run .
language: golang
args: [headers --plan]

- id: add-license
name: Add or fix repo license
description: Adds or updates a non-compliant LICENSE file
entry: go run .
language: golang
args: [license]

- id: check-license
name: Validate repo license
description: Checks if a LICENSE file is valid, but does not make changes
entry: go run .
language: golang
args: [license --plan]
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,21 @@ freely in later steps.
:bulb: Running the copywrite command with the `--plan` flag will return a non-zero exit code if the repo is out of compliance.

## Pre-Commit Hooks

Copywrite can be used as a [Pre-Commit](https://pre-commit.com) Hook for those
looking to add copyright headers during local development. A list of supported
hooks can be found in [here](./.pre-commit-hooks.yaml), but the most common use
case for adding missing copyright headers can be done by adding the following
snippet to your repo's `.pre-commit-config.yaml`:

```yaml
- repo: https://github.com/hashicorp/copywrite
rev: v0.15.0 # Use any release tag
hooks:
- id: copywrite-headers
```

## Debugging

Copywrite supports several built-in features to aid with debugging. The first
Expand All @@ -171,14 +186,11 @@ itself in. The `copywrite debug` command can print the running configuration,
whether or not a config file was loaded, what GitHub auth type is in use, and
more. No sensitive information is printed, however.

## Development

### IDE Settings
## Development

To maintain a consistent developer experience, this repo comes bundled with VS Code settings. When opening the repo for the first time, you will be asked if you want to install [suggested extensions](./.vscode/extensions.json) and your workspace will be pre-configured with consistent format-on-save [settings](./.vscode/settings.json).

### Pre-Commit Hooks

Before committing code, this repo has been setup to check Go files using [pre-commit git hooks](https://pre-commit.com/). To leverage pre-commit, developers must install pre-commit and associated tools locally:

```bash
Expand Down

0 comments on commit 66e5399

Please sign in to comment.