Skip to content

Commit c08a4d8

Browse files
authored
refactor: Remove duplicated pre-commit-configs (#157)
* refactor(pre-commit): Remove duplicated pre-commit config * refactor: Move CI script out of repository root * refactor: Resolve lint issues in script
1 parent 39e99d9 commit c08a4d8

File tree

4 files changed

+11
-46
lines changed

4 files changed

+11
-46
lines changed
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import json
44
import os
55
from typing import Union
6-
6+
from pathlib import Path
77

88
SECRET_PATTERNS = [
99
re.compile(r'[\'"]?subscription_id[\'"]?\s*[:=]\s*[\'"][0-9a-f\-]{36}[\'"]', re.IGNORECASE),
@@ -22,7 +22,7 @@
2222
def check_ipynb_for_secrets(filename: Union[str, os.PathLike]) -> bool:
2323
"""Jupyter notebooks can't be parsed directly - need to convert to JSON first"""
2424
try:
25-
with open(filename, "r", encoding="utf-8") as file:
25+
with Path(filename).open("r", encoding="utf-8") as file:
2626
notebook_data = json.load(file)
2727
failed = False
2828
for cell in notebook_data.get("cells", []):
@@ -38,23 +38,22 @@ def check_ipynb_for_secrets(filename: Union[str, os.PathLike]) -> bool:
3838
return True
3939

4040

41-
def main():
41+
def main() -> None:
4242
failed = False
4343

4444
for filename in sys.argv[1:]:
4545
if filename.endswith((".py", ".yaml", ".yml", ".md")):
4646
try:
47-
with open(filename, "r", encoding="utf-8") as file:
47+
with Path(filename).open("r", encoding="utf-8") as file:
4848
for line_number, line in enumerate(file, start=1):
4949
for pattern in SECRET_PATTERNS:
5050
if pattern.search(line):
5151
print(f"Secret detected in {filename} on line {line_number}: {line.strip()}")
5252
failed = True
5353
except UnicodeDecodeError:
5454
print(f"Failed to read {filename}. Skipping secrets check.")
55-
elif filename.endswith(".ipynb"):
56-
if check_ipynb_for_secrets(filename):
57-
failed = True
55+
elif filename.endswith(".ipynb") and check_ipynb_for_secrets(filename):
56+
failed = True
5857

5958
if failed:
6059
sys.exit(1)

.github/workflows/pre-commit.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ jobs:
2020
python-version: "3.8"
2121
- run: pip install -r dev-requirements.txt
2222
- name: Run Pre-Commit
23-
run: pre-commit run --all-files --config .pre-commit-config-remote.yaml
23+
run: pre-commit run --all-files
24+
env:
25+
SKIP: detect-azure-secrets-custom

.pre-commit-config-remote.yaml

Lines changed: 0 additions & 36 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ repos:
2424
require_serial: true
2525
additional_dependencies: []
2626
minimum_pre_commit_version: "2.9.2"
27-
args: ["--fix", "--exit-non-zero-on-fix", "--exclude", "detect_azure_secrets.py"]
27+
args: ["--fix", "--exit-non-zero-on-fix"]
2828
- id: black
2929
name: black
3030
description: "Black: The uncompromising Python code formatter"
@@ -36,6 +36,6 @@ repos:
3636
args: ["-m", "tox", "-qqq", "run", "-e", "black", "--"]
3737
- id: detect-azure-secrets-custom
3838
name: Detect Azure Secrets
39-
entry: python detect_azure_secrets.py
39+
entry: python .github/scripts/detect_azure_secrets.py
4040
language: python
4141
types: [file]

0 commit comments

Comments
 (0)