Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1128: pre-commit #1164

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
default_stages: [pre-commit, pre-push]
fail_fast: false

repos:
- repo: local
hooks:
#
# YAML
- id: yamllint
name: yamllint
files: .*\.(yaml|yml)$
entry: yamllint --config-file ./.yamllint
language: system
always_run: false
pass_filenames: true

#
# Python
- id: py-flake8
name: py-flake8
files: .*\.py$
entry: flake8 --config setup.cfg
language: system
always_run: false
pass_filenames: true

#
# POST-CHECKOUT
# optional, need to be installed with: pre-commit install -t post-checkout
- id: git-pull
name: git pull
entry: bash -c '[[ $(git branch --show-current) == "master" ]] && git pull --all || true'
language: system
stages: [post-checkout]
always_run: true
pass_filenames: false

- id: git-branch-delete-stale
name: Delete stale committed branches
# yamllint disable-line rule:line-length
entry: bash -c '[[ $(git branch --show-current) == "master" ]] && (git fetch -p && git branch -vv | grep ":\ gone]" | awk "{ print \$1 }" | xargs git branch -D) || true' --
language: system
stages: [post-checkout]
always_run: true
pass_filenames: false
12 changes: 12 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
extends: default

rules:
braces:
min-spaces-inside: 1
max-spaces-inside: 1
comments:
min-spaces-from-content: 1
empty-values: enable
line-length:
max: 160
27 changes: 22 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ We also run the public [Github Project Board](https://github.com/vas3k/vas3k.clu

## 🙋‍♂️ How to report a bug or propose a feature?

- 🆕Open [a new issue](https://github.com/vas3k/vas3k.club/issues/new).
- 🆕Open [a new issue](https://github.com/vas3k/vas3k.club/issues/new).
- 🔦 Please, **use a search**, to check, if there is already exied issue!
- Explain your idea or proposal in all the details:
- Explain your idea or proposal in all the details:
- If it's a **new feature**:
- 🖼 If it's **UI/UX** related: attach a screenshot or wireframe.
- Please mark this issues with prefix **"Фича:"**
- 🐞 If it's a **bug**:
- make sure you clearly describe "observed" and "expected" behaviour. It will dramatically save time for our contributors and maintainers.
- make sure you clearly describe "observed" and "expected" behaviour. It will dramatically save time for our contributors and maintainers.
- **For minor fixes** please just open a PR.
- *Please mark this issues with prefix **"Баг:"***

## 😎 I want to write some code!

- Open our [Issues page](https://github.com/vas3k/vas3k.club/issues) to see the most important tickets at top.
- Open our [Issues page](https://github.com/vas3k/vas3k.club/issues) to see the most important tickets at top.
- Pick one issue you like and **leave a comment** inside that you're getting it.

**For big changes** open an issues first or (if it's already opened) leave a comment with brief explanation what and why you're going to change. Many tickets hang open not because they cannot be done, but because they cause many logical contradictions that you may not know. It's better to clarify them in comments before sending a PR.
Expand All @@ -43,7 +43,7 @@ We also run the public [Github Project Board](https://github.com/vas3k/vas3k.clu

##### 🟨 Discussion is needed

- **new feature** — completely new features. Usually they're too hard for newbies, leave them **for experienced contributors.**
- **new feature** — completely new features. Usually they're too hard for newbies, leave them **for experienced contributors.**

- **idea** — **discussion is needed**. Those tickets look adequate, but waiting for real proposals how they will be done. Don't implement them right away.

Expand Down Expand Up @@ -72,3 +72,20 @@ We try to keep our stack as simple and stupid as possible. Because we're not ver

Basically `docker-compose up`. See [README.md](README.md) for details.

## Pre-commit hooks

`pre-commit` can be used to run Git hooks before submitting the code to review.
These hook scripts perform simple tasks before each commit (code formatting mostly).
To activate the hooks, simply run the following command in your terminal.

```sh
pre-commit install
```

If you try to commit a non-compliant (i.e. badly formatted) file, `pre-commit` will modify this file and make the commit fail.
However you need to stage the new changes **yourself** as `pre-commit` will not do that for you (this is by design; see [here](https://github.com/pre-commit/pre-commit/issues/806) or [here](https://github.com/pre-commit/pre-commit/issues/747)).
Fortunately, `pre-commit` outputs useful messages.

The list of hooks (and their options) can be found in [`.pre-commit-config.yaml`](.pre-commit-config.yaml).
For more information, see [their website](https://pre-commit.com/).
If you want to manually run all pre-commit hooks on a repository, run `pre-commit run --all-files`. To run individual hooks use `pre-commit run <hook_id>`.