chore: finalize repo audit hygiene (#257)

This commit is contained in:
Elliot Chen
2026-06-06 13:59:12 +08:00
committed by GitHub
parent ab23e40b28
commit 00f1dfaec5
27 changed files with 459 additions and 199 deletions

View File

@ -21,9 +21,7 @@ ALLOWED_TYPES = (
"ci",
"revert",
)
TITLE_RE = re.compile(
rf"^({'|'.join(ALLOWED_TYPES)})(\([A-Za-z0-9._/-]+\))?(!)?: .+"
)
TITLE_RE = re.compile(rf"^({'|'.join(ALLOWED_TYPES)})(\([A-Za-z0-9._/-]+\))?(!)?: .+")
MAX_TITLE_LENGTH = 72
@ -33,7 +31,9 @@ def _run_git(args: list[str]) -> str:
def _default_range() -> str:
event_name = os.getenv("GITHUB_EVENT_NAME", "")
before = os.getenv("GITHUB_EVENT_BEFORE", "") or os.getenv("GITHUB_EVENT_BEFORE_SHA", "")
before = os.getenv("GITHUB_EVENT_BEFORE", "") or os.getenv(
"GITHUB_EVENT_BEFORE_SHA", ""
)
after = os.getenv("GITHUB_SHA", "HEAD")
pr_base = os.getenv("GITHUB_PR_BASE_SHA", "")
@ -83,7 +83,8 @@ def _validate(commit_range: str) -> list[str]:
short = commit[:12]
if len(subject) > MAX_TITLE_LENGTH:
failures.append(
f"{short}: subject is {len(subject)} chars; max is {MAX_TITLE_LENGTH}: {subject}"
f"{short}: subject is {len(subject)} chars; "
f"max is {MAX_TITLE_LENGTH}: {subject}"
)
continue

View File

@ -0,0 +1,90 @@
"""Block deprecated product names in tracked repository text."""
from __future__ import annotations
import re
import subprocess
from dataclasses import dataclass
from pathlib import Path
from typing import Iterable
DEPRECATED_NAME_RE = re.compile(r"\bever[\s_-]*core\b", flags=re.IGNORECASE)
SKIP_SUFFIXES = frozenset(
{
".avif",
".bmp",
".gif",
".heic",
".heif",
".icns",
".ico",
".jpeg",
".jpg",
".mov",
".mp4",
".png",
".webp",
}
)
@dataclass(frozen=True)
class Violation:
path: str
line_number: int
line: str
def find_violations(files: Iterable[tuple[str, str]]) -> list[Violation]:
violations: list[Violation] = []
for path, text in files:
for line_number, line in enumerate(text.splitlines(), start=1):
if DEPRECATED_NAME_RE.search(line):
violations.append(
Violation(path=path, line_number=line_number, line=line.strip())
)
return violations
def _tracked_paths() -> list[Path]:
result = subprocess.run(
["git", "ls-files", "-z"],
check=True,
stdout=subprocess.PIPE,
text=False,
)
return [
Path(raw.decode("utf-8"))
for raw in result.stdout.split(b"\0")
if raw
]
def _tracked_text_files() -> Iterable[tuple[str, str]]:
for path in _tracked_paths():
if path.suffix.lower() in SKIP_SUFFIXES:
continue
try:
text = path.read_text(encoding="utf-8")
except UnicodeDecodeError:
continue
yield path.as_posix(), text
def main() -> int:
violations = find_violations(_tracked_text_files())
if not violations:
print("Deprecated-name check passed.")
return 0
print(
"Deprecated-name check failed.\n"
"Use EverOS or EverMind Cloud. Do not use deprecated product naming.\n"
)
for violation in violations:
print(f"- {violation.path}:{violation.line_number}: {violation.line}")
return 1
if __name__ == "__main__":
raise SystemExit(main())

View File

@ -3,7 +3,6 @@
from __future__ import annotations
import re
import sys
from pathlib import Path
SKIP_DIRS = {".git", "node_modules", ".venv", ".uv-cache"}

View File

@ -3,10 +3,9 @@
from __future__ import annotations
import subprocess
import sys
from collections.abc import Iterable
from dataclasses import dataclass
from pathlib import PurePosixPath
from typing import Iterable
BLOCKED_DIR_NAMES = frozenset(
{
@ -94,11 +93,7 @@ def _tracked_paths() -> list[str]:
stdout=subprocess.PIPE,
text=False,
)
return [
raw.decode("utf-8")
for raw in result.stdout.split(b"\0")
if raw
]
return [raw.decode("utf-8") for raw in result.stdout.split(b"\0") if raw]
def main() -> int: