From 9405365f41cd6dca13b19682e2ef34a3527e507c Mon Sep 17 00:00:00 2001 From: Caleb Albers Date: Wed, 1 Feb 2023 16:54:09 -0800 Subject: [PATCH 1/3] Add pre-commit-hooks for copywrite --- .pre-commit-hooks.yaml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .pre-commit-hooks.yaml diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml new file mode 100644 index 0000000..5d418dc --- /dev/null +++ b/.pre-commit-hooks.yaml @@ -0,0 +1,27 @@ +- id: copywrite-headers + name: Add copyright headers + description: Adds missing copyright headers to all source code files + entry: go run . + language: golang + args: [headers] + +- id: copywrite-headers-check-only + 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: copywrite-license + name: Add or fix repo license + description: Adds or updates a non-compliant LICENSE file + entry: go run . + language: golang + args: [license] + +- id: copywrite-license-check-only + 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] From 3a3c9b4554284de19b55747cd4f9e725a5af57ad Mon Sep 17 00:00:00 2001 From: Caleb Albers Date: Wed, 1 Feb 2023 17:06:22 -0800 Subject: [PATCH 2/3] Add documentation for pre-commit hooks --- .pre-commit-hooks.yaml | 8 ++++---- README.md | 19 +++++++++++++++---- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 5d418dc..aec47c9 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -1,25 +1,25 @@ -- id: copywrite-headers +- 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: copywrite-headers-check-only +- 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: copywrite-license +- 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: copywrite-license-check-only +- id: check-license name: Validate repo license description: Checks if a LICENSE file is valid, but does not make changes entry: go run . diff --git a/README.md b/README.md index cddcb95..a1916e8 100644 --- a/README.md +++ b/README.md @@ -147,13 +147,24 @@ 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. -## Development +## Pre-Commit Hooks -### IDE Settings +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`: -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). +```yaml +- repo: https://github.com/hashicorp/copywrite + rev: v0.15.0 # Use any release tag + hooks: + - id: copywrite-headers +``` -### Pre-Commit Hooks +## 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). 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: From f97ea911b7c746ccb6dd773c8d228a7375957304 Mon Sep 17 00:00:00 2001 From: Caleb Albers Date: Wed, 1 Feb 2023 17:12:27 -0800 Subject: [PATCH 3/3] Add copywrite to our own pre-commit-config --- .pre-commit-config.yaml | 4 ++++ README.md | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9d290ab..c98686d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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: diff --git a/README.md b/README.md index a1916e8..a52524f 100644 --- a/README.md +++ b/README.md @@ -156,10 +156,10 @@ 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 + - repo: https://github.com/hashicorp/copywrite + rev: v0.15.0 # Use any release tag hooks: - - id: copywrite-headers + - id: copywrite-headers ``` ## Development