rails_git_hooks 0.7.1 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +86 -168
- data/lib/rails_git_hooks/checks/commit_msg/not_empty.rb +25 -0
- data/lib/rails_git_hooks/checks/commit_msg.rb +1 -0
- data/lib/rails_git_hooks/checks/post_checkout/bundle_install.rb +16 -0
- data/lib/rails_git_hooks/checks/post_checkout/db_migrate.rb +16 -0
- data/lib/rails_git_hooks/checks/post_checkout/npm_install.rb +16 -0
- data/lib/rails_git_hooks/checks/post_checkout/yarn_install.rb +16 -0
- data/lib/rails_git_hooks/checks/post_checkout.rb +13 -0
- data/lib/rails_git_hooks/checks/post_merge/bundle_install.rb +16 -0
- data/lib/rails_git_hooks/checks/post_merge/db_migrate.rb +16 -0
- data/lib/rails_git_hooks/checks/post_merge/npm_install.rb +16 -0
- data/lib/rails_git_hooks/checks/post_merge/yarn_install.rb +16 -0
- data/lib/rails_git_hooks/checks/post_merge.rb +13 -0
- data/lib/rails_git_hooks/checks/pre_commit/erblint.rb +30 -0
- data/lib/rails_git_hooks/checks/pre_commit/eslint.rb +34 -0
- data/lib/rails_git_hooks/checks/pre_commit/go_vet.rb +30 -0
- data/lib/rails_git_hooks/checks/pre_commit/golint.rb +30 -0
- data/lib/rails_git_hooks/checks/pre_commit/haml_lint.rb +30 -0
- data/lib/rails_git_hooks/checks/pre_commit/jslint.rb +34 -0
- data/lib/rails_git_hooks/checks/pre_commit/php_lint.rb +30 -0
- data/lib/rails_git_hooks/checks/pre_commit/pylint.rb +30 -0
- data/lib/rails_git_hooks/checks/pre_commit/rails_best_practices.rb +31 -0
- data/lib/rails_git_hooks/checks/pre_commit/scss_lint.rb +30 -0
- data/lib/rails_git_hooks/checks/pre_commit.rb +10 -0
- data/lib/rails_git_hooks/checks/pre_push/run_go_test.rb +24 -0
- data/lib/rails_git_hooks/checks/pre_push/run_pytest.rb +24 -0
- data/lib/rails_git_hooks/checks/pre_push.rb +2 -0
- data/lib/rails_git_hooks/checks/shared/bundle_install_check.rb +28 -0
- data/lib/rails_git_hooks/checks/shared/db_migrate_check.rb +28 -0
- data/lib/rails_git_hooks/checks/shared/npm_install_check.rb +28 -0
- data/lib/rails_git_hooks/checks/shared/yarn_install_check.rb +28 -0
- data/lib/rails_git_hooks/checks.rb +6 -0
- data/lib/rails_git_hooks/cli.rb +8 -100
- data/lib/rails_git_hooks/config/constants.rb +7 -1
- data/lib/rails_git_hooks/config/defaults.yml +321 -1
- data/lib/rails_git_hooks/install/installer.rb +31 -5
- data/lib/rails_git_hooks/runtime/check_registry.rb +22 -1
- data/lib/rails_git_hooks/runtime/override_config.rb +10 -4
- data/lib/rails_git_hooks/runtime/repository.rb +8 -0
- data/lib/rails_git_hooks/runtime/runner.rb +4 -0
- data/lib/rails_git_hooks/version.rb +1 -1
- data/templates/hooks/post-checkout +13 -0
- data/templates/hooks/post-merge +13 -0
- metadata +31 -44
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3e545765ea7576f3a3f3f20cb93e3137d24b9286d28d1fbf1a9a2750d8992b42
|
|
4
|
+
data.tar.gz: 7b2873f1099d4e1dbfdfc180bce56862fc782a21ff9131f9403d86f164cc1773
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dbb863f5890def3ef2cee7e3f762b428f81d9aaf3236325956adb302db92145e5b6eb1f0eeb500a2e996825439101df1e2e949ef1345f30670289a6cbd536c3c
|
|
7
|
+
data.tar.gz: 17b2b1e96f64cd8f1d59494ab40193e7f065bd1f450ea9e55365699f6b58ec3c79a08e49c392de0476cdbb06bba90b977fecbd8bb04d4a6dcd889969cae7d296
|
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,21 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
6
6
|
|
|
7
|
+
## [0.7.2]
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- **post-checkout hook** — Runs after branch checkout. Includes `bundle-install` (run `bundle install` when Gemfile/Gemfile.lock changed) and `db-migrate` (run `rails db:migrate` when migrations or schema changed). Both enabled by default.
|
|
12
|
+
- **post-merge hook** — Runs after merge. Same checks as post-checkout: `bundle-install` and `db-migrate`, enabled by default. Keeps the app bundled and migrated when pulling or merging (inspired by [hookup](https://rubygems.org/gems/hookup)).
|
|
13
|
+
- **Shared check modules** — `checks/shared/bundle_install_check.rb` and `checks/shared/db_migrate_check.rb` hold common logic and options for the post-checkout and post-merge bundle/migrate checks.
|
|
14
|
+
- **Specs for every check** — RSpec examples for all 13 checks (pre-commit, commit-msg, pre-push, post-checkout, post-merge) under `spec/rails_git_hooks/checks/`.
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- **Default install** — With no config file, `install` now installs **commit-msg**, **pre-commit**, **post-checkout**, and **post-merge** (post-checkout/post-merge bundle and db-migrate checks are on by default).
|
|
19
|
+
- **Runner** — `modified_files` now supports `post_checkout` (files changed between refs on branch checkout) and `post_merge` (files changed between ORIG_HEAD and HEAD). Repository adds `changed_files(ref1, ref2)`.
|
|
20
|
+
- **defaults.yml** — PostCheckout and PostMerge sections: `BundleInstall` and `DbMigrate` set to `enabled: true` by default.
|
|
21
|
+
|
|
7
22
|
## [0.7.1]
|
|
8
23
|
|
|
9
24
|
### Added
|
data/README.md
CHANGED
|
@@ -4,45 +4,80 @@
|
|
|
4
4
|
[](https://github.com/NikitaNazarov1/rails_git_hooks/actions/workflows/tests.yml?query=branch%3Amain)
|
|
5
5
|
[](https://github.com/NikitaNazarov1/rails_git_hooks/actions/workflows/rubocop.yml?query=branch%3Amain)
|
|
6
6
|
|
|
7
|
-
Git hooks for Rails and Ruby projects
|
|
8
|
-
|
|
9
|
-
##
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
|
21
|
-
|
|
22
|
-
|
|
|
23
|
-
|
|
|
24
|
-
|
|
|
7
|
+
Git hooks for Rails and Ruby projects: sensible defaults out of the box, optional YAML overrides, and per-check policies (enable/disable, fail vs warn, include/exclude).
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Code-first runtime** — Checks are Ruby classes; hook scripts are thin bootstraps that delegate to a shared runtime.
|
|
12
|
+
- **Sparse config** — Defaults live in the gem ([config/defaults.yml](https://github.com/NikitaNazarov1/rails_git_hooks/blob/main/lib/rails_git_hooks/config/defaults.yml)). But you can redefine them via your own yml config file in a root repository.
|
|
13
|
+
- **Flexible configuration options** — Per check: `enabled`, `quiet`, `on_fail`, `on_warn`, `on_missing_dependency`, `include`, `exclude`, `command`.
|
|
14
|
+
- **Dependency handling** — Checks declare executables/libraries; missing deps are handled by a single policy (`on_missing_dependency`).
|
|
15
|
+
|
|
16
|
+
## Included hooks and checks
|
|
17
|
+
|
|
18
|
+
### When hooks trigger
|
|
19
|
+
|
|
20
|
+
| Hook | Triggers at |
|
|
21
|
+
|------|-------------|
|
|
22
|
+
| **commit-msg** | After the user finishes editing the commit message, before the commit is created. |
|
|
23
|
+
| **pre-commit** | Before the commit is created (when running `git commit`). |
|
|
24
|
+
| **pre-push** | Before pushing to the remote (when running `git push`). |
|
|
25
|
+
| **post-checkout** | After switching branches or restoring files (e.g. `git checkout`). |
|
|
26
|
+
| **post-merge** | After a merge completes (when running `git merge`). |
|
|
27
|
+
|
|
28
|
+
### Checks by hook
|
|
29
|
+
|
|
30
|
+
| Hook | Check key | Enabled By Default | Description |
|
|
31
|
+
|-------------|----------------------|---------|-------------|
|
|
32
|
+
| **commit-msg** | `jira-prefix` | ✅ | Prefix commit messages with Jira-style ticket IDs from the branch name (e.g. `[TICKET-123]`). |
|
|
33
|
+
| **commit-msg** | `not-empty` | ✅ | Reject empty commit messages. |
|
|
34
|
+
| **pre-commit** | `default-branch` | ✅ | Block commits on `master` / `main`, prompt to use a feature branch. |
|
|
35
|
+
| **pre-commit** | `debugger-check` | ✅ | Warn (or fail) on debugger statements in Ruby, JavaScript/TypeScript, and Python. |
|
|
36
|
+
| **pre-commit** | `yaml-format-check` | ✅ | Warn on invalid `.yml` / `.yaml` files. |
|
|
37
|
+
| **pre-commit** | `json-format-check` | ✅ | Warn on invalid `.json` files. |
|
|
38
|
+
| **pre-commit** | `migrations-check` | ✅ | Warn when migration files are staged but schema/data_schema files are not. |
|
|
39
|
+
| **pre-commit** | `whitespace-check` | Off | Fail on trailing whitespace and merge conflict markers. |
|
|
40
|
+
| **pre-commit** | `rubocop-check` | Off | Run RuboCop on staged Ruby files (requires `rubocop` in the project). |
|
|
41
|
+
| **pre-commit** | `rails-best-practices` | Off | Warn on Rails best practices violations (requires `rails_best_practices` gem). |
|
|
42
|
+
| **pre-commit** | `erblint-check` | Off | Run `erblint` on staged ERB files (requires `erblint` gem). |
|
|
43
|
+
| **pre-commit** | `eslint-check` | Off | Run `eslint` on staged JavaScript files (.js, .jsx, .mjs, .cjs). You can set `command` in config to use an npm script (e.g. `npm run lint`). |
|
|
44
|
+
| **pre-commit** | `golint-check` | Off | Run `golint` on staged Go files (requires `golint`). |
|
|
45
|
+
| **pre-commit** | `haml-lint-check` | Off | Run `haml-lint` on staged HAML files (requires `haml_lint` gem). |
|
|
46
|
+
| **pre-commit** | `jslint-check` | Off | Run `jslint` on staged JavaScript files (.js, .jsx, .mjs, .cjs). |
|
|
47
|
+
| **pre-commit** | `php-lint-check` | Off | Run `php -l` (syntax check) on staged PHP files. |
|
|
48
|
+
| **pre-commit** | `pylint-check` | Off | Run `pylint` on staged Python files. |
|
|
49
|
+
| **pre-commit** | `scss-lint-check` | Off | Run `scss-lint` on staged SCSS files (requires `scss_lint` gem). |
|
|
50
|
+
| **pre-commit** | `go-vet-check` | Off | Run `go vet` on staged Go files. |
|
|
51
|
+
| **pre-push** | `run-tests` | Off | Run test suite before push (default: `bundle exec rspec`). Enable in config to install pre-push. |
|
|
52
|
+
| **pre-push** | `run-pytest` | Off | Run pytest test suite before push. Enable in config to install pre-push. |
|
|
53
|
+
| **pre-push** | `run-go-test` | Off | Run `go test` suite before push. Enable in config to install pre-push. |
|
|
54
|
+
| **post-checkout** | `bundle-install` | Off | Run `bundle install` when Gemfile or Gemfile.lock changed after a branch checkout. |
|
|
55
|
+
| **post-checkout** | `db-migrate` | Off | Run `rails db:migrate` when migrations or schema changed after a branch checkout. |
|
|
56
|
+
| **post-checkout** | `npm-install` | Off | Run `npm install` when package.json or package-lock.json changed after a branch checkout. |
|
|
57
|
+
| **post-checkout** | `yarn-install` | Off | Run `yarn install` when package.json or yarn.lock changed after a branch checkout. |
|
|
58
|
+
| **post-merge** | `bundle-install` | Off | Run `bundle install` when Gemfile or Gemfile.lock changed after a merge. |
|
|
59
|
+
| **post-merge** | `db-migrate` | Off | Run `rails db:migrate` when migrations or schema changed after a merge. |
|
|
60
|
+
| **post-merge** | `npm-install` | Off | Run `npm install` when package.json or package-lock.json changed after a merge. |
|
|
61
|
+
| **post-merge** | `yarn-install` | Off | Run `yarn install` when package.json or yarn.lock changed after a merge. |
|
|
25
62
|
|
|
26
63
|
## Quick start
|
|
27
64
|
|
|
28
|
-
### 1.
|
|
29
|
-
|
|
30
|
-
```bash
|
|
31
|
-
gem install rails_git_hooks
|
|
32
|
-
```
|
|
65
|
+
### 1. Add the gem
|
|
33
66
|
|
|
34
|
-
|
|
67
|
+
**Gemfile:**
|
|
35
68
|
|
|
36
69
|
```ruby
|
|
37
70
|
gem "rails_git_hooks"
|
|
38
71
|
```
|
|
39
72
|
|
|
40
|
-
Then
|
|
73
|
+
Then:
|
|
41
74
|
|
|
42
75
|
```bash
|
|
43
76
|
bundle install
|
|
44
77
|
```
|
|
45
78
|
|
|
79
|
+
Or install globally: `gem install rails_git_hooks`.
|
|
80
|
+
|
|
46
81
|
### 2. Install hooks
|
|
47
82
|
|
|
48
83
|
From your project root:
|
|
@@ -51,53 +86,25 @@ From your project root:
|
|
|
51
86
|
bundle exec rails_git_hooks install
|
|
52
87
|
```
|
|
53
88
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
### 3. Inspect available checks
|
|
57
|
-
|
|
58
|
-
```bash
|
|
59
|
-
bundle exec rails_git_hooks list
|
|
60
|
-
```
|
|
89
|
+
With default config this installs **commit-msg**, **pre-commit**, **post-checkout**, and **post-merge** into `.git/hooks/` and copies the runtime there (pre-push is off by default; enable `run-tests` in config to add it).
|
|
61
90
|
|
|
62
|
-
|
|
91
|
+
## Configuration
|
|
63
92
|
|
|
64
|
-
|
|
93
|
+
### Priority (low → high)
|
|
65
94
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
95
|
+
1. **Built-in defaults** (in the gem’s `config/defaults.yml`)
|
|
96
|
+
2. **`.rails_git_hooks.yml`** in the repo root (sparse overrides; commit this)
|
|
97
|
+
3. **`.rails_git_hooks.local.yml`** in the repo root (optional; overrides the above, typically gitignored)
|
|
69
98
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
```bash
|
|
73
|
-
bundle exec rails_git_hooks set debugger-check on_fail fail
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
Disable migrations warnings:
|
|
77
|
-
|
|
78
|
-
```bash
|
|
79
|
-
bundle exec rails_git_hooks disable migrations-check
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
Show effective config:
|
|
83
|
-
|
|
84
|
-
```bash
|
|
85
|
-
bundle exec rails_git_hooks show-config
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
## Config model
|
|
89
|
-
|
|
90
|
-
You do **not** need a config file for the defaults to work.
|
|
91
|
-
|
|
92
|
-
If you want overrides, create one:
|
|
99
|
+
**Create the main override file:**
|
|
93
100
|
|
|
94
101
|
```bash
|
|
95
102
|
bundle exec rails_git_hooks init
|
|
96
103
|
```
|
|
97
104
|
|
|
98
|
-
|
|
105
|
+
**Optional:** Create `.rails_git_hooks.local.yml` in the repo root for personal overrides (merged on top of `.rails_git_hooks.yml`). Add it to `.gitignore` if you don’t want to commit it.
|
|
99
106
|
|
|
100
|
-
Example
|
|
107
|
+
### Example override file
|
|
101
108
|
|
|
102
109
|
```yaml
|
|
103
110
|
PreCommit:
|
|
@@ -112,118 +119,29 @@ PreCommit:
|
|
|
112
119
|
- "lib/**/*.rb"
|
|
113
120
|
exclude:
|
|
114
121
|
- "db/schema.rb"
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
### Supported per-check options
|
|
118
122
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
| `on_fail` | Map a check failure to `fail`, `warn`, or `pass` |
|
|
124
|
-
| `on_warn` | Map a warning to `warn`, `fail`, or `pass` |
|
|
125
|
-
| `on_missing_dependency` | Control behavior when required tools/libraries are missing |
|
|
126
|
-
| `include` | File paths or glob patterns that the check should apply to |
|
|
127
|
-
| `exclude` | File paths or glob patterns to remove from the included set |
|
|
128
|
-
| `command` | Override the command used by command-based checks |
|
|
129
|
-
|
|
130
|
-
## Dependency model
|
|
131
|
-
|
|
132
|
-
Checks can declare dependencies such as:
|
|
133
|
-
|
|
134
|
-
- executables like `bundle`
|
|
135
|
-
- Ruby libraries like `rubocop`
|
|
136
|
-
- required files
|
|
137
|
-
|
|
138
|
-
If a dependency is missing, the runner produces a structured result and applies the check’s `on_missing_dependency` policy. This makes missing-tool behavior consistent across all checks.
|
|
139
|
-
|
|
140
|
-
## Default checks
|
|
141
|
-
|
|
142
|
-
### `commit-msg`
|
|
143
|
-
|
|
144
|
-
- `jira-prefix`
|
|
145
|
-
- enabled by default
|
|
146
|
-
- prefixes commit messages with `[TICKET-123]` when the branch name contains a Jira-style ticket ID
|
|
147
|
-
|
|
148
|
-
### `pre-commit`
|
|
149
|
-
|
|
150
|
-
- `default-branch`
|
|
151
|
-
- enabled by default
|
|
152
|
-
- fails on `master` / `main`
|
|
153
|
-
|
|
154
|
-
- `debugger-check`
|
|
155
|
-
- enabled by default
|
|
156
|
-
- warns on debugger statements in Ruby, JavaScript/TypeScript, and Python
|
|
157
|
-
|
|
158
|
-
- `yaml-format-check`
|
|
159
|
-
- enabled by default
|
|
160
|
-
- warns on invalid `.yml` / `.yaml`
|
|
161
|
-
|
|
162
|
-
- `json-format-check`
|
|
163
|
-
- enabled by default
|
|
164
|
-
- warns on invalid `.json`
|
|
165
|
-
|
|
166
|
-
- `migrations-check`
|
|
167
|
-
- enabled by default
|
|
168
|
-
- warns when schema/data schema files appear to be missing after migrations
|
|
169
|
-
|
|
170
|
-
- `whitespace-check`
|
|
171
|
-
- disabled by default
|
|
172
|
-
- fails on trailing whitespace and merge conflict markers
|
|
173
|
-
|
|
174
|
-
- `rubocop-check`
|
|
175
|
-
- disabled by default
|
|
176
|
-
- runs RuboCop on staged Ruby files
|
|
177
|
-
- default dependency behavior warns if `rubocop` is missing
|
|
178
|
-
|
|
179
|
-
### `pre-push`
|
|
180
|
-
|
|
181
|
-
- `run-tests`
|
|
182
|
-
- enabled by default when `pre-push` is installed
|
|
183
|
-
- runs `bundle exec rspec`
|
|
184
|
-
|
|
185
|
-
## CLI reference
|
|
186
|
-
|
|
187
|
-
| Command | Description |
|
|
188
|
-
|---|---|
|
|
189
|
-
| `rails_git_hooks install [HOOK...]` | Install hook scripts into `.git/hooks` |
|
|
190
|
-
| `rails_git_hooks list` | List available git hooks and check keys |
|
|
191
|
-
| `rails_git_hooks init` | Create `.rails_git_hooks.yml` |
|
|
192
|
-
| `rails_git_hooks enable CHECK_NAME` | Set `enabled: true` for a check override |
|
|
193
|
-
| `rails_git_hooks disable CHECK_NAME` | Set `enabled: false` for a check override |
|
|
194
|
-
| `rails_git_hooks set CHECK_NAME OPTION VALUE` | Set a single override option |
|
|
195
|
-
| `rails_git_hooks show-config` | Print effective merged configuration |
|
|
196
|
-
|
|
197
|
-
Examples:
|
|
198
|
-
|
|
199
|
-
```bash
|
|
200
|
-
rails_git_hooks install
|
|
201
|
-
rails_git_hooks install pre-push
|
|
202
|
-
rails_git_hooks enable rubocop-check
|
|
203
|
-
rails_git_hooks disable migrations-check
|
|
204
|
-
rails_git_hooks set debugger-check on_fail fail
|
|
205
|
-
rails_git_hooks set rubocop-check quiet true
|
|
206
|
-
rails_git_hooks show-config
|
|
123
|
+
# Run eslint via your npm script (useful if the script has its own config):
|
|
124
|
+
Eslint:
|
|
125
|
+
enabled: true
|
|
126
|
+
command: [npm, run, lint]
|
|
207
127
|
```
|
|
208
128
|
|
|
209
|
-
|
|
129
|
+
### Per-check options
|
|
210
130
|
|
|
211
|
-
|
|
131
|
+
| Option | Description |
|
|
132
|
+
|--------|--------------|
|
|
133
|
+
| `enabled` | Turn the check on or off. |
|
|
134
|
+
| `quiet` | Suppress normal output unless the check warns or fails. |
|
|
135
|
+
| `on_fail` | `fail`, `warn`, or `pass` when the check fails. |
|
|
136
|
+
| `on_warn` | `warn`, `fail`, or `pass` when the check would warn. |
|
|
137
|
+
| `on_missing_dependency` | Behavior when a required executable/library is missing. |
|
|
138
|
+
| `include` | Glob patterns for files the check applies to. |
|
|
139
|
+
| `exclude` | Glob patterns to exclude from `include`. |
|
|
140
|
+
| `command` | Override the command for checks that run external commands. |
|
|
212
141
|
|
|
213
|
-
|
|
214
|
-
bundle exec rails_git_hooks install
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
This installs the thin hook bootstraps and the embedded `rails_git_hooks` runtime into `.git/hooks/`.
|
|
218
|
-
|
|
219
|
-
## Development
|
|
142
|
+
## Contributing
|
|
220
143
|
|
|
221
|
-
|
|
222
|
-
bundle install
|
|
223
|
-
bundle exec rake # run specs
|
|
224
|
-
bundle exec rake build # build the gem
|
|
225
|
-
bundle exec rake install # install locally
|
|
226
|
-
```
|
|
144
|
+
Contributions are welcome. Open an [issue](https://github.com/NikitaNazarov1/rails_git_hooks/issues) for bugs or ideas, or submit a pull request.
|
|
227
145
|
|
|
228
146
|
## License
|
|
229
147
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module GitHooks
|
|
4
|
+
module Checks
|
|
5
|
+
module CommitMsg
|
|
6
|
+
class NotEmpty < Base
|
|
7
|
+
check_definition key: 'not-empty',
|
|
8
|
+
hook: :commit_msg,
|
|
9
|
+
description: 'Reject empty commit messages'
|
|
10
|
+
|
|
11
|
+
def run
|
|
12
|
+
message_file = argv.first
|
|
13
|
+
return CheckResult.pass unless message_file && File.file?(message_file)
|
|
14
|
+
|
|
15
|
+
message = File.read(message_file)
|
|
16
|
+
# Strip comment lines (git uses # in the message template) and blank lines
|
|
17
|
+
content = message.lines.reject { |line| line.strip.start_with?('#') || line.strip.empty? }.join.strip
|
|
18
|
+
return CheckResult.pass unless content.empty?
|
|
19
|
+
|
|
20
|
+
CheckResult.fail(messages: ['Commit message must not be empty.'])
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module GitHooks
|
|
4
|
+
module Checks
|
|
5
|
+
module PostCheckout
|
|
6
|
+
class BundleInstall < Base
|
|
7
|
+
include BundleInstallCheck
|
|
8
|
+
|
|
9
|
+
check_definition key: 'bundle-install',
|
|
10
|
+
hook: :post_checkout,
|
|
11
|
+
description: 'Run bundle install when Gemfile or Gemfile.lock changed (branch checkout)',
|
|
12
|
+
**BundleInstallCheck::DEFINITION_OPTIONS
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module GitHooks
|
|
4
|
+
module Checks
|
|
5
|
+
module PostCheckout
|
|
6
|
+
class DbMigrate < Base
|
|
7
|
+
include DbMigrateCheck
|
|
8
|
+
|
|
9
|
+
check_definition key: 'db-migrate',
|
|
10
|
+
hook: :post_checkout,
|
|
11
|
+
description: 'Run db:migrate when migrations or schema changed (branch checkout)',
|
|
12
|
+
**DbMigrateCheck::DEFINITION_OPTIONS
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module GitHooks
|
|
4
|
+
module Checks
|
|
5
|
+
module PostCheckout
|
|
6
|
+
class NpmInstall < Base
|
|
7
|
+
include NpmInstallCheck
|
|
8
|
+
|
|
9
|
+
check_definition key: 'npm-install',
|
|
10
|
+
hook: :post_checkout,
|
|
11
|
+
description: 'Run npm install when package.json or package-lock.json changed (branch checkout)',
|
|
12
|
+
**NpmInstallCheck::DEFINITION_OPTIONS
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module GitHooks
|
|
4
|
+
module Checks
|
|
5
|
+
module PostCheckout
|
|
6
|
+
class YarnInstall < Base
|
|
7
|
+
include YarnInstallCheck
|
|
8
|
+
|
|
9
|
+
check_definition key: 'yarn-install',
|
|
10
|
+
hook: :post_checkout,
|
|
11
|
+
description: 'Run yarn install when package.json or yarn.lock changed (branch checkout)',
|
|
12
|
+
**YarnInstallCheck::DEFINITION_OPTIONS
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module GitHooks
|
|
4
|
+
module Checks
|
|
5
|
+
module PostCheckout
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
require_relative 'post_checkout/bundle_install'
|
|
11
|
+
require_relative 'post_checkout/db_migrate'
|
|
12
|
+
require_relative 'post_checkout/npm_install'
|
|
13
|
+
require_relative 'post_checkout/yarn_install'
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module GitHooks
|
|
4
|
+
module Checks
|
|
5
|
+
module PostMerge
|
|
6
|
+
class BundleInstall < Base
|
|
7
|
+
include BundleInstallCheck
|
|
8
|
+
|
|
9
|
+
check_definition key: 'bundle-install',
|
|
10
|
+
hook: :post_merge,
|
|
11
|
+
description: 'Run bundle install when Gemfile or Gemfile.lock changed (after merge)',
|
|
12
|
+
**BundleInstallCheck::DEFINITION_OPTIONS
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module GitHooks
|
|
4
|
+
module Checks
|
|
5
|
+
module PostMerge
|
|
6
|
+
class DbMigrate < Base
|
|
7
|
+
include DbMigrateCheck
|
|
8
|
+
|
|
9
|
+
check_definition key: 'db-migrate',
|
|
10
|
+
hook: :post_merge,
|
|
11
|
+
description: 'Run db:migrate when migrations or schema changed (after merge)',
|
|
12
|
+
**DbMigrateCheck::DEFINITION_OPTIONS
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module GitHooks
|
|
4
|
+
module Checks
|
|
5
|
+
module PostMerge
|
|
6
|
+
class NpmInstall < Base
|
|
7
|
+
include NpmInstallCheck
|
|
8
|
+
|
|
9
|
+
check_definition key: 'npm-install',
|
|
10
|
+
hook: :post_merge,
|
|
11
|
+
description: 'Run npm install when package.json or package-lock.json changed (after merge)',
|
|
12
|
+
**NpmInstallCheck::DEFINITION_OPTIONS
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module GitHooks
|
|
4
|
+
module Checks
|
|
5
|
+
module PostMerge
|
|
6
|
+
class YarnInstall < Base
|
|
7
|
+
include YarnInstallCheck
|
|
8
|
+
|
|
9
|
+
check_definition key: 'yarn-install',
|
|
10
|
+
hook: :post_merge,
|
|
11
|
+
description: 'Run yarn install when package.json or yarn.lock changed (after merge)',
|
|
12
|
+
**YarnInstallCheck::DEFINITION_OPTIONS
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module GitHooks
|
|
4
|
+
module Checks
|
|
5
|
+
module PostMerge
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
require_relative 'post_merge/bundle_install'
|
|
11
|
+
require_relative 'post_merge/db_migrate'
|
|
12
|
+
require_relative 'post_merge/npm_install'
|
|
13
|
+
require_relative 'post_merge/yarn_install'
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module GitHooks
|
|
4
|
+
module Checks
|
|
5
|
+
module PreCommit
|
|
6
|
+
class ErbLint < Base
|
|
7
|
+
check_definition key: 'erblint-check',
|
|
8
|
+
hook: :pre_commit,
|
|
9
|
+
description: 'Run erblint on staged ERB files',
|
|
10
|
+
file_based: true,
|
|
11
|
+
enabled: false,
|
|
12
|
+
quiet: true,
|
|
13
|
+
dependencies: { 'executables' => ['bundle'], 'libraries' => ['erblint'] },
|
|
14
|
+
command: %w[bundle exec erblint],
|
|
15
|
+
install_hint: 'Add `gem "erblint"` to your Gemfile and run bundle install'
|
|
16
|
+
|
|
17
|
+
def run
|
|
18
|
+
erb_files = applicable_files.select { |path| path.end_with?('.erb') && File.file?(path) }
|
|
19
|
+
return CheckResult.pass if erb_files.empty?
|
|
20
|
+
|
|
21
|
+
output, status = capture(*Array(config['command']), *erb_files)
|
|
22
|
+
return CheckResult.pass if status.success?
|
|
23
|
+
|
|
24
|
+
messages = output.split("\n").map(&:rstrip).reject(&:empty?)
|
|
25
|
+
CheckResult.fail(messages: messages)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module GitHooks
|
|
4
|
+
module Checks
|
|
5
|
+
module PreCommit
|
|
6
|
+
class Eslint < Base
|
|
7
|
+
JS_EXTENSIONS = %w[.js .jsx .mjs .cjs].freeze
|
|
8
|
+
|
|
9
|
+
check_definition key: 'eslint-check',
|
|
10
|
+
hook: :pre_commit,
|
|
11
|
+
description: 'Run eslint on staged JavaScript files',
|
|
12
|
+
file_based: true,
|
|
13
|
+
enabled: false,
|
|
14
|
+
quiet: true,
|
|
15
|
+
dependencies: { 'executables' => ['eslint'] },
|
|
16
|
+
command: %w[eslint],
|
|
17
|
+
install_hint: 'Install eslint (e.g. npm install -D eslint) or override command in config'
|
|
18
|
+
|
|
19
|
+
def run
|
|
20
|
+
js_files = applicable_files.select do |path|
|
|
21
|
+
File.file?(path) && JS_EXTENSIONS.include?(File.extname(path))
|
|
22
|
+
end
|
|
23
|
+
return CheckResult.pass if js_files.empty?
|
|
24
|
+
|
|
25
|
+
output, status = capture(*Array(config['command']), *js_files)
|
|
26
|
+
return CheckResult.pass if status.success?
|
|
27
|
+
|
|
28
|
+
messages = output.split("\n").map(&:rstrip).reject(&:empty?)
|
|
29
|
+
CheckResult.fail(messages: messages)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module GitHooks
|
|
4
|
+
module Checks
|
|
5
|
+
module PreCommit
|
|
6
|
+
class GoVet < Base
|
|
7
|
+
check_definition key: 'go-vet-check',
|
|
8
|
+
hook: :pre_commit,
|
|
9
|
+
description: 'Run go vet on staged Go files',
|
|
10
|
+
file_based: true,
|
|
11
|
+
enabled: false,
|
|
12
|
+
quiet: true,
|
|
13
|
+
dependencies: { 'executables' => ['go'] },
|
|
14
|
+
command: %w[go vet],
|
|
15
|
+
install_hint: 'Ensure Go toolchain is installed and on PATH'
|
|
16
|
+
|
|
17
|
+
def run
|
|
18
|
+
go_files = applicable_files.select { |path| File.file?(path) && File.extname(path) == '.go' }
|
|
19
|
+
return CheckResult.pass if go_files.empty?
|
|
20
|
+
|
|
21
|
+
output, status = capture(*Array(config['command']), *go_files)
|
|
22
|
+
return CheckResult.pass if status.success?
|
|
23
|
+
|
|
24
|
+
messages = output.split("\n").map(&:rstrip).reject(&:empty?)
|
|
25
|
+
CheckResult.fail(messages: messages)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|