Commit e6ecd254 authored by Ash McKenzie's avatar Ash McKenzie

Merge branch '220807-consider-replacing-overcommit-with-another-git-hooks-manager' into 'master'

Add a default Lefthook configuration

See merge request gitlab-org/gitlab!36347
parents e5bc562b 5acb0662
...@@ -56,6 +56,7 @@ eslint-report.html ...@@ -56,6 +56,7 @@ eslint-report.html
/doc/code/* /doc/code/*
/dump.rdb /dump.rdb
/jsconfig.json /jsconfig.json
/lefthook-local.yml
/log/*.log* /log/*.log*
/node_modules /node_modules
/nohup.out /nohup.out
......
...@@ -37,7 +37,8 @@ def build_message(commit, message, more_info: true) ...@@ -37,7 +37,8 @@ def build_message(commit, message, more_info: true)
end end
def squash_mr? def squash_mr?
gitlab_danger.ci? ? gitlab.mr_json['squash'] : false # Locally, we assume the MR is set to be squashed so that the user only sees warnings instead of errors.
gitlab_danger.ci? ? gitlab.mr_json['squash'] : true
end end
def wip_mr? def wip_mr?
...@@ -112,7 +113,7 @@ def lint_commits(commits) ...@@ -112,7 +113,7 @@ def lint_commits(commits)
if multi_line_commit_linter && multi_line_commit_linter.failed? if multi_line_commit_linter && multi_line_commit_linter.failed?
warn_or_fail_commits(multi_line_commit_linter) warn_or_fail_commits(multi_line_commit_linter)
else elsif gitlab_danger.ci? # We don't have access to the MR title locally
title_linter = lint_mr_title(gitlab.mr_json['title']) title_linter = lint_mr_title(gitlab.mr_json['title'])
if title_linter.failed? if title_linter.failed?
warn_or_fail_commits(title_linter) warn_or_fail_commits(title_linter)
......
...@@ -15,25 +15,35 @@ settings automatically by default. If your editor/IDE does not automatically sup ...@@ -15,25 +15,35 @@ 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-commit static analysis ## Pre-push static analysis
You should install [`overcommit`](https://github.com/sds/overcommit) to automatically check for We strongly recommend installing
static analysis offenses before committing locally. [Lefthook](https://github.com/Arkweid/lefthook) to automatically check for
static analysis offenses before pushing your changes.
After installing `overcommit`, run the following in your GitLab source directory: After installing `overcommit`, run the following in your GitLab source directory:
```shell ```shell
make -C tooling/overcommit # Make sure to uninstall Overcommit first
overcommit --uninstall
# Install lefthook
gem install lefthook && lefthook install -f
``` ```
Then before a commit is created, `overcommit` automatically checks for RuboCop (and other checks) Before you push your changes, Lefthook will then automatically run Danger checks, as well
offenses on every modified file. as RuboCop, ES Lint, HAML Lint, and SCSS Lint for the changed files.
This saves you time as you don't have to wait for the same errors to be detected by CI/CD. This saves you time as you don't have to wait for the same errors to be detected by CI/CD.
`overcommit` relies on a pre-commit hook to prevent commits that violate its ruleset. To override Lefthook relies on a pre-push hook to prevent commits that violate its ruleset.
this behavior, pass the `OVERCOMMIT_DISABLE` environment variable. For example, If you wish to override this behavior, pass the environment variable `LEFTHOOK=0`.
`OVERCOMMIT_DISABLE=1 git rebase master` to rebase while disabling the Git hook. That is, `LEFTHOOK=0 git push`.
You can also:
- Define [local configuration](https://github.com/Arkweid/lefthook/blob/master/docs/full_guide.md#local-config).
- Skip [checks per tag on the fly](https://github.com/Arkweid/lefthook/blob/master/docs/full_guide.md#skip-some-tags-on-the-fly).
## Ruby, Rails, RSpec ## Ruby, Rails, RSpec
......
...@@ -716,7 +716,7 @@ Sample configuration for `overcommit` is available in the ...@@ -716,7 +716,7 @@ Sample configuration for `overcommit` is available in the
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 `overcommit` for documentation linting, see To set up `overcommit` for documentation linting, see
[Pre-commit static analysis](../contributing/style_guides.md#pre-commit-static-analysis). [Pre-commit static analysis](../contributing/style_guides.md#pre-push-static-analysis).
#### Disable Vale tests #### Disable Vale tests
......
pre-push:
parallel: true
commands:
danger:
run: bundle exec danger dry_run
eslint:
tags: frontend style
files: git diff --name-only $(git merge-base origin/master HEAD)..HEAD
glob: "*.{js,vue}"
run: yarn eslint --cache --max-warnings 0 --report-unused-disable-directives {files}
haml-lint:
tags: view haml style
files: git diff --name-only $(git merge-base origin/master HEAD)..HEAD
glob: "*.html.haml"
run: bundle exec haml-lint --config .haml-lint.yml {files}
scss-lint:
tags: stylesheet css style
files: git diff --name-only $(git merge-base origin/master HEAD)..HEAD
glob: "*.scss.css"
exclude: "app/assets/stylesheets/pages/emojis.scss"
run: bundle exec scss-lint --config .scss-lint.yml {files}
rubocop:
tags: backend style
files: git diff --name-only $(git merge-base origin/master HEAD)..HEAD
glob: "*.rb"
run: bundle exec rubocop --parallel --force-exclusion {files}
...@@ -168,7 +168,7 @@ module Gitlab ...@@ -168,7 +168,7 @@ module Gitlab
%r{\A(\.gitlab-ci\.yml\z|\.gitlab\/ci)} => :engineering_productivity, %r{\A(\.gitlab-ci\.yml\z|\.gitlab\/ci)} => :engineering_productivity,
%r{\A\.codeclimate\.yml\z} => :engineering_productivity, %r{\A\.codeclimate\.yml\z} => :engineering_productivity,
%r{\A\.overcommit\.yml\.example\z} => :engineering_productivity, %r{\Alefthook.yml\z} => :engineering_productivity,
%r{\A\.editorconfig\z} => :engineering_productivity, %r{\A\.editorconfig\z} => :engineering_productivity,
%r{Dangerfile\z} => :engineering_productivity, %r{Dangerfile\z} => :engineering_productivity,
%r{\A(ee/)?(danger/|lib/gitlab/danger/)} => :engineering_productivity, %r{\A(ee/)?(danger/|lib/gitlab/danger/)} => :engineering_productivity,
......
...@@ -278,9 +278,9 @@ RSpec.describe Gitlab::Danger::Helper do ...@@ -278,9 +278,9 @@ RSpec.describe Gitlab::Danger::Helper do
'scripts/foo' | [:engineering_productivity] 'scripts/foo' | [:engineering_productivity]
'lib/gitlab/danger/foo' | [:engineering_productivity] 'lib/gitlab/danger/foo' | [:engineering_productivity]
'ee/lib/gitlab/danger/foo' | [:engineering_productivity] 'ee/lib/gitlab/danger/foo' | [:engineering_productivity]
'.overcommit.yml.example' | [:engineering_productivity] 'lefthook.yml' | [:engineering_productivity]
'.editorconfig' | [:engineering_productivity] '.editorconfig' | [:engineering_productivity]
'tooling/overcommit/foo' | [:engineering_productivity] 'tooling/bin/find_foss_tests' | [:engineering_productivity]
'.codeclimate.yml' | [:engineering_productivity] '.codeclimate.yml' | [:engineering_productivity]
'.gitlab/CODEOWNERS' | [:engineering_productivity] '.gitlab/CODEOWNERS' | [:engineering_productivity]
......
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