Skip to content

Commit 2940808

Browse files
authored
Merge pull request #31 from BerryBytes/feat/sync-precommit
Feat/sync precommit
2 parents 00f2982 + 6911b50 commit 2940808

5 files changed

Lines changed: 126 additions & 26 deletions

File tree

.github/scripts/extract_config.sh

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
# #!/bin/bash
2-
3-
# # Extract the YAML config from setup_pre_commit_config function in global/pre-commit.sh
4-
# # and save it to global/precommitFile/.pre-commit-config.yaml
5-
6-
# mkdir -p global/precommitFile
7-
8-
# sed -n '/cat > "\$file" <<'\''EOF'\''/,/EOF/p' global/pre-commit.sh | sed '1d;$d' > global/precommitFile/.pre-commit-config.yaml
9-
10-
# echo "Config extracted to global/precommitFile/.pre-commit-config.yaml"
11-
121
#!/bin/bash
132

143
# List of directories in root that may contain pre-commit.sh

python/pre-commit.sh

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,15 @@ check_dependencies() {
4747
# Create .pre-commit-config.yaml if missing
4848
############################################
4949
setup_pre_commit_config() {
50-
local config=".pre-commit-config.yaml"
51-
log "STEP" "Setting up pre-commit configuration..."
50+
local file=".pre-commit-config.yaml"
51+
log "STEP" "Setting up pre-commit configuration"
5252

53-
if [[ -f "$config" ]]; then
54-
log "INFO" "$config already exists — skipping creation."
53+
if [[ -f "$file" ]]; then
54+
log "INFO" "$file already exists — skipping creation"
5555
return
5656
fi
5757

58-
local python_version
59-
python_version=$(python3 -V | awk '{print $2}' | cut -d. -f1-2)
60-
61-
cat > "$config" <<'EOF'
58+
cat > "$file" <<'EOF'
6259
repos:
6360
- repo: https://github.com/pre-commit/pre-commit-hooks
6461
rev: v6.0.0
@@ -142,7 +139,7 @@ repos:
142139
143140
EOF
144141

145-
log "INFO" "$config created successfully."
142+
log "INFO" "$file created successfully."
146143
}
147144

148145
############################################
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v6.0.0
4+
hooks:
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
8+
- id: check-added-large-files
9+
- id: check-vcs-permalinks
10+
- id: check-symlinks
11+
- id: destroyed-symlinks
12+
- id: detect-private-key
13+
- id: check-merge-conflict
14+
15+
# ✅ Python code formatter
16+
- repo: https://github.com/psf/black
17+
rev: 23.9.1
18+
hooks:
19+
- id: black
20+
args: [--line-length=88]
21+
22+
# ✅ Import sorter (runs before Black)
23+
- repo: https://github.com/PyCQA/isort
24+
rev: 5.12.0
25+
hooks:
26+
- id: isort
27+
args: ["--profile=black"]
28+
29+
# ✅ Linter (flake8 for code quality)
30+
- repo: https://github.com/pycqa/flake8
31+
rev: 6.1.0
32+
hooks:
33+
- id: flake8
34+
args:
35+
- --max-line-length=88
36+
- --extend-ignore=E203,W503
37+
additional_dependencies:
38+
- flake8-bugbear
39+
- flake8-comprehensions
40+
- flake8-docstrings
41+
42+
# ✅ Type checking
43+
- repo: https://github.com/pre-commit/mirrors-mypy
44+
rev: v1.10.0
45+
hooks:
46+
- id: mypy
47+
args: ["--ignore-missing-imports", "--strict"]
48+
49+
# ✅ Security scanning (Bandit)
50+
- repo: https://github.com/PyCQA/bandit
51+
rev: 1.7.5
52+
hooks:
53+
- id: bandit
54+
args: ["-ll", "-r", "."]
55+
56+
# ✅ Detect secrets in code
57+
- repo: https://github.com/gitleaks/gitleaks
58+
rev: v8.21.0
59+
hooks:
60+
- id: gitleaks
61+
args: ["detect", "--verbose"]
62+
63+
# ✅ Static code analysis for Python (pylint optional)
64+
- repo: https://github.com/pycqa/pylint
65+
rev: v3.2.6
66+
hooks:
67+
- id: pylint
68+
args: ["--disable=C0114,C0115,C0116"] # disable docstring warnings
69+
additional_dependencies:
70+
- pylint-django
71+
- pylint-flask
72+
73+
# ✅ Spell checking for docs, code comments, configs
74+
- repo: https://github.com/codespell-project/codespell
75+
rev: v2.2.5
76+
hooks:
77+
- id: codespell
78+
files: ^.*\.(py|c|h|md|rst|yml|go|sh|sql|tf|yaml)$
79+
args: ["--ignore-words-list", "hist,nd,bu,maks,gir"]
80+
81+

terraform/pre-commit.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,19 @@ check_dependencies() {
3737
exit 1
3838
fi
3939
}
40-
40+
#######################################
41+
# Generate pre-commit config if missing
42+
#######################################
4143
setup_pre_commit_config() {
42-
log "STEP" "Setting Up Pre-commit Config"
43-
local pre_commit_config=".pre-commit-config.yaml"
44-
if [ ! -f "$pre_commit_config" ]; then
45-
cat > "$pre_commit_config" <<EOF
44+
local file=".pre-commit-config.yaml"
45+
log "STEP" "Setting up pre-commit configuration"
46+
47+
if [[ -f "$file" ]]; then
48+
log "INFO" "$file already exists — skipping creation"
49+
return
50+
fi
51+
52+
cat > "$file" <<'EOF'
4653
repos:
4754
- repo: https://github.com/terraform-docs/terraform-docs
4855
rev: "v0.16.0"
@@ -70,7 +77,7 @@ repos:
7077
7178
7279
EOF
73-
log "INFO" "$pre_commit_config created."
80+
log "INFO" "$file created successfully."
7481
fi
7582
}
7683

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
repos:
2+
- repo: https://github.com/terraform-docs/terraform-docs
3+
rev: "v0.16.0"
4+
hooks:
5+
- id: terraform-docs-go
6+
args: ["markdown", "table", "--output-file", "README.md", "./"]
7+
- repo: https://github.com/antonbabenko/pre-commit-terraform
8+
rev: "v1.74.1"
9+
hooks:
10+
- id: terraform_fmt
11+
- id: terraform_tflint
12+
- id: terraform_validate
13+
- id: terraform_tfsec
14+
- repo: https://github.com/codespell-project/codespell
15+
rev: v2.2.5
16+
hooks:
17+
- id: codespell
18+
files: ^.*\.(py|c|h|md|rst|yml|go|sh|sql|tf|yaml)$
19+
args: ["--ignore-words-list", "hist,nd"]
20+
- repo: https://github.com/gitleaks/gitleaks
21+
rev: v8.21.0
22+
hooks:
23+
- id: gitleaks
24+
args: ["detect", "--verbose"]
25+
26+

0 commit comments

Comments
 (0)