Commit 1b7e69c0 authored by Rémy Coutable's avatar Rémy Coutable Committed by Heinrich Lee Yu

Add Lefthook to the Gemfile and improve documentation

This will ease the integration of Lefthook with GitPod.
Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent c095fcc7
...@@ -336,6 +336,7 @@ end ...@@ -336,6 +336,7 @@ end
group :development do group :development do
gem 'brakeman', '~> 4.2', require: false gem 'brakeman', '~> 4.2', require: false
gem 'danger', '~> 8.0.6', require: false gem 'danger', '~> 8.0.6', require: false
gem 'lefthook', '~> 0.7', require: false
gem 'letter_opener_web', '~> 1.3.4' gem 'letter_opener_web', '~> 1.3.4'
......
...@@ -658,6 +658,7 @@ GEM ...@@ -658,6 +658,7 @@ GEM
rest-client (~> 2.0) rest-client (~> 2.0)
launchy (2.4.3) launchy (2.4.3)
addressable (~> 2.3) addressable (~> 2.3)
lefthook (0.7.2)
letter_opener (1.7.0) letter_opener (1.7.0)
launchy (~> 2.2) launchy (~> 2.2)
letter_opener_web (1.3.4) letter_opener_web (1.3.4)
...@@ -1410,6 +1411,7 @@ DEPENDENCIES ...@@ -1410,6 +1411,7 @@ DEPENDENCIES
knapsack (~> 1.17) knapsack (~> 1.17)
kramdown (~> 2.3.0) kramdown (~> 2.3.0)
kubeclient (~> 4.9.1) kubeclient (~> 4.9.1)
lefthook (~> 0.7)
letter_opener_web (~> 1.3.4) letter_opener_web (~> 1.3.4)
license_finder (~> 6.0) license_finder (~> 6.0)
licensee (~> 8.9) licensee (~> 8.9)
......
...@@ -15,52 +15,83 @@ settings automatically by default. If your editor/IDE does not automatically sup ...@@ -15,52 +15,83 @@ settings automatically by default. If your editor/IDE does not automatically sup
we suggest investigating to see if a plugin exists. For instance here is the we suggest investigating to see if a plugin exists. For instance here is the
[plugin for vim](https://github.com/editorconfig/editorconfig-vim). [plugin for vim](https://github.com/editorconfig/editorconfig-vim).
## Pre-push static analysis ## Pre-push static analysis with Lefthook
We strongly recommend installing [Lefthook](https://github.com/Arkweid/lefthook) to automatically check [Lefthook](https://github.com/Arkweid/lefthook) is a Git hooks manager that allows
for static analysis offenses before pushing your changes. custom logic to be executed prior to Git committing or pushing. GitLab comes with
Lefthook configuration (`lefthook.yml`), but it must be installed.
To install `lefthook`, run the following in your GitLab source directory: We have a `lefthook.yml` checked in but it is ignored until Lefthook is installed.
```shell ### Uninstall Overcommit
# 1. Make sure to uninstall Overcommit first
overcommit --uninstall We were using Overcommit prior to Lefthook, so you may want to uninstall it first with `overcommit --uninstall`.
### Install Lefthook
1. Install the `lefthook` Ruby gem:
```shell
bundle install
```
1. Install Lefthook managed Git hooks:
```shell
bundle exec lefthook install
```
1. Test Lefthook is working by running the Lefthook `prepare-commit-msg` Git hook:
```shell
bundle exec lefthook run prepare-commit-msg
```
This should return a fully qualified path command with no other output.
# If using rbenv, at this point you may need to do: rbenv rehash ### Lefthook configuration
# 2. Install lefthook... The current Lefthook configuration can be found in [`lefthook.yml`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/lefthook.yml).
## With Homebrew (macOS) Before you push your changes, Lefthook automatically runs the following checks:
brew install Arkweid/lefthook/lefthook
## Or with Go - Danger: Runs a subset of checks that `danger-review` runs on your merge requests.
go get github.com/Arkweid/lefthook - ES lint: Run `yarn eslint` checks (with the [`.eslintrc.yml`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.eslintrc.yml) config) on the modified `*.{js,vue}` files. Tags: `frontend`, `style`.
- HAML lint: Run `bundle exec haml-lint` checks (with the [`.haml-lint.yml`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.haml-lint.yml) config) on the modified `*.html.haml` files. Tags: `view`, `haml`, `style`.
- Markdown lint: Run `yarn markdownlint` checks on the modified `*.md` files. Tags: `documentation`, `style`.
- SCSS lint: Run `bundle exec scss-lint` checks (with the [`.scss-lint.yml`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.scss-lint.yml) config) on the modified `*.scss{,.css}` files. Tags: `stylesheet`, `css`, `style`.
- RuboCop: Run `bundle exec rubocop` checks (with the [`.rubocop.yml`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.rubocop.yml) config) on the modified `*.rb` files. Tags: `backend`, `style`.
- Vale: Run `vale` checks (with the [`.vale.ini`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.vale.ini) config) on the modified `*.md` files. Tags: `documentation`, `style`.
## Or with Rubygems In addition to the default configuration, you can define a [local configuration](https://github.com/Arkweid/lefthook/blob/master/docs/full_guide.md#local-config).
gem install lefthook
### You may need to run the following if you're using rbenv ### Disable Lefthook temporarily
rbenv rehash
# 3. Install the Git hooks To disable Lefthook temporarily, you can set the `LEFTHOOK` environment variable to `0`. For instance:
lefthook install -f
```shell
LEFTHOOK=0 git push ...
```
### Run Lefthook hooks manually
To run the `pre-push` Git hook, run:
```shell
bundle exec lefthook run pre-push
``` ```
Before you push your changes, Lefthook then automatically run Danger checks, and other checks For more information, check out [Lefthook documentation](https://github.com/Arkweid/lefthook/blob/master/docs/full_guide.md#run-githook-group-directly).
for changed files. This saves you time as you don't have to wait for the same errors to be detected
by CI/CD. ### Skip Lefthook checks per tag
Lefthook relies on a pre-push hook to prevent commits that violate its ruleset. To skip some checks based on tags when pushing, you can set the `LEFTHOOK_EXCLUDE` environment variable. For instance:
To override this behavior, pass the environment variable `LEFTHOOK=0`. That is,
`LEFTHOOK=0 git push`.
You can also: ```shell
LEFTHOOK_EXCLUDE=frontend,documentation git push ...
```
- Define [local configuration](https://github.com/Arkweid/lefthook/blob/master/docs/full_guide.md#local-config). For more information, check out [Lefthook documentation](https://github.com/Arkweid/lefthook/blob/master/docs/full_guide.md#skip-some-tags-on-the-fly).
- Skip [checks per tag on the fly](https://github.com/Arkweid/lefthook/blob/master/docs/full_guide.md#skip-some-tags-on-the-fly).
For example, `LEFTHOOK_EXCLUDE=frontend git push origin`.
- Run [hooks manually](https://github.com/Arkweid/lefthook/blob/master/docs/full_guide.md#run-githook-group-directly).
For example, `lefthook run pre-push`.
## Ruby, Rails, RSpec ## Ruby, Rails, RSpec
......
...@@ -286,7 +286,7 @@ Configuration for `lefthook` is available in the [`lefthook.yml`](https://gitlab ...@@ -286,7 +286,7 @@ Configuration for `lefthook` is available in the [`lefthook.yml`](https://gitlab
file for the [`gitlab`](https://gitlab.com/gitlab-org/gitlab) project. file for the [`gitlab`](https://gitlab.com/gitlab-org/gitlab) project.
To set up `lefthook` for documentation linting, see To set up `lefthook` for documentation linting, see
[Pre-push static analysis](../contributing/style_guides.md#pre-push-static-analysis). [Pre-push static analysis](../contributing/style_guides.md#pre-push-static-analysis-with-lefthook).
### Show subset of Vale alerts ### Show subset of Vale alerts
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment