feat: add filename convention pre-commit
This commit is contained in:
commit
12e3965730
|
|
@ -0,0 +1,2 @@
|
||||||
|
__pycache__
|
||||||
|
fc_hooks.egg-info
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
default_stages: [commit, merge-commit, push, manual]
|
||||||
|
default_install_hook_types: [commit-msg, pre-commit]
|
||||||
|
repos:
|
||||||
|
- repo: https://github.com/compilerla/conventional-pre-commit
|
||||||
|
rev: v2.3.0
|
||||||
|
hooks:
|
||||||
|
- id: conventional-pre-commit
|
||||||
|
stages: [commit-msg]
|
||||||
|
args: []
|
||||||
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||||
|
rev: v0.3.3
|
||||||
|
hooks:
|
||||||
|
- id: ruff
|
||||||
|
args: [ --fix ]
|
||||||
|
- id: ruff-format
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
- id: fc-path-convention
|
||||||
|
name: Frog Collective path convention
|
||||||
|
description: Check paths follows Frog Collective's naming convention
|
||||||
|
entry: fc-hooks
|
||||||
|
language: python
|
||||||
|
types: [text]
|
||||||
|
exclude: |
|
||||||
|
(?x)(
|
||||||
|
^.pre-commit-config.yaml
|
||||||
|
)
|
||||||
|
stages: [pre-commit, pre-merge-commit, manual]
|
||||||
|
|
@ -0,0 +1,69 @@
|
||||||
|
# Frog Collective's commit hooks
|
||||||
|
|
||||||
|
## Use these hooks
|
||||||
|
|
||||||
|
### Configure pre-commit
|
||||||
|
|
||||||
|
Add this repository to your .pre-commit-config.yaml file :
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
repos:
|
||||||
|
- repo: https://git.frog-collective.com/frog-collective/commit-hooks.git
|
||||||
|
rev: 0.1
|
||||||
|
hooks:
|
||||||
|
- id: fc-path-convention
|
||||||
|
```
|
||||||
|
|
||||||
|
### Available Hooks
|
||||||
|
|
||||||
|
* fc-path-convention : Adri je te laisse mettre ici ce qu'il faut
|
||||||
|
|
||||||
|
## Test hooks
|
||||||
|
|
||||||
|
### Test the hooks command
|
||||||
|
|
||||||
|
You can install the hook command and test it without calling pre-commit by
|
||||||
|
installing a virtualenv, and thise package in it :
|
||||||
|
|
||||||
|
```
|
||||||
|
$ virtualenv .venv
|
||||||
|
$ source .venv/bin/activate
|
||||||
|
$ pip install -e .
|
||||||
|
```
|
||||||
|
|
||||||
|
Then you can test the hooks by running the 'fc-hooks' command :
|
||||||
|
|
||||||
|
```
|
||||||
|
$ fc-hooks TestBadFileName.py
|
||||||
|
TestBadFileName.py doesn't follow the naming convention
|
||||||
|
```
|
||||||
|
|
||||||
|
### Test hooks inside a repository
|
||||||
|
|
||||||
|
You can test the hooks in any repository, by using the pre-commit's 'try-repo'
|
||||||
|
command.
|
||||||
|
|
||||||
|
First, clone this repository :
|
||||||
|
|
||||||
|
``` $ git git@git.frog-collective.com:frog-collective/commit-hooks.git ```
|
||||||
|
|
||||||
|
Go to your repository, and try the hooks :
|
||||||
|
|
||||||
|
```
|
||||||
|
$ cd my-repo
|
||||||
|
$ pre-commit try-repo ../commit-hooks
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
Using config:
|
||||||
|
===============================================================================
|
||||||
|
repos:
|
||||||
|
- repo: ../commit-hooks
|
||||||
|
rev: 5ca01ce3117dfc15baa68e31cf580601a3f12c9b
|
||||||
|
hooks:
|
||||||
|
- id: fc-path-convention
|
||||||
|
===============================================================================
|
||||||
|
[INFO] Installing environment for ../commit-hooks.
|
||||||
|
[INFO] Once installed this environment will be reused.
|
||||||
|
[INFO] This may take a few minutes...
|
||||||
|
Frog Collective path convention..........................................Passed
|
||||||
|
```
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
import re
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from click import argument, command, echo
|
||||||
|
|
||||||
|
|
||||||
|
def check_path(path: Path) -> bool:
|
||||||
|
str_path = str(path)
|
||||||
|
|
||||||
|
if path.suffix == ".cs":
|
||||||
|
if re.search(r"^[a-zA-Z\\\/\._]*$", str_path) is None:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
if re.search(r"^[a-z\\\/\._]*$", str_path) is None:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@command
|
||||||
|
@argument(
|
||||||
|
"paths",
|
||||||
|
nargs=-1,
|
||||||
|
)
|
||||||
|
def main(paths: list[str]) -> None:
|
||||||
|
has_error = False
|
||||||
|
for path in paths:
|
||||||
|
if not check_path(Path(path)):
|
||||||
|
echo(f"{path} doesn't follows convention")
|
||||||
|
has_error = True
|
||||||
|
|
||||||
|
if has_error:
|
||||||
|
exit(1)
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
[project]
|
||||||
|
name = "fc-hooks"
|
||||||
|
version = "0.0.1"
|
||||||
|
description = "Frog Collective's commit hooks"
|
||||||
|
license = {text = "WTFPL"}
|
||||||
|
readme = "README.md"
|
||||||
|
dependencies = [
|
||||||
|
"click",
|
||||||
|
]
|
||||||
|
|
||||||
|
[project.scripts]
|
||||||
|
fc-hooks = "fc_hooks:main"
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["setuptools>=45"]
|
||||||
|
|
||||||
|
[tool.setuptools.packages.find]
|
||||||
|
include = ["fc_hooks"]
|
||||||
|
|
||||||
|
[tool.ruff]
|
||||||
|
line-length = 120
|
||||||
|
|
||||||
|
[tool.ruff.lint]
|
||||||
|
select = [
|
||||||
|
"E",
|
||||||
|
"F",
|
||||||
|
"W",
|
||||||
|
"UP",
|
||||||
|
"B",
|
||||||
|
"SIM",
|
||||||
|
"I",
|
||||||
|
"N",
|
||||||
|
"U",
|
||||||
|
"YTT",
|
||||||
|
"ASYNC",
|
||||||
|
"RUF"
|
||||||
|
]
|
||||||
|
|
||||||
|
[tool.mypy]
|
||||||
|
strict = true
|
||||||
|
packages = "fc_hooks"
|
||||||
|
|
||||||
Loading…
Reference in New Issue