feat: add option to exclude specific files from language stats totals
Co-authored-by: aider (o3) <aider@aider.chat>
This commit is contained in:
@@ -30,6 +30,12 @@ if not BASE_URL or not TOKEN or not USERNAME:
|
|||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
session.headers["Authorization"] = f"token {TOKEN}"
|
session.headers["Authorization"] = f"token {TOKEN}"
|
||||||
|
|
||||||
|
# List of files whose byte-counts should be excluded from the totals.
|
||||||
|
# Each tuple: (repository_name, file_path, language_name)
|
||||||
|
EXCLUDE_FILES: list[tuple[str, str, str]] = [
|
||||||
|
("ar-scavenger-hunt", "static/aframe.js", "JavaScript"),
|
||||||
|
]
|
||||||
|
|
||||||
# ---------- collect repositories ----------
|
# ---------- collect repositories ----------
|
||||||
page = 1
|
page = 1
|
||||||
repos = []
|
repos = []
|
||||||
@@ -57,6 +63,20 @@ for repo in repos:
|
|||||||
for lang, bytes_ in langs.items():
|
for lang, bytes_ in langs.items():
|
||||||
totals[lang] += bytes_
|
totals[lang] += bytes_
|
||||||
|
|
||||||
|
# ---------- subtract excluded files ----------
|
||||||
|
for repo_name, file_path, language in EXCLUDE_FILES:
|
||||||
|
try:
|
||||||
|
meta = session.get(
|
||||||
|
f"{BASE_URL}/api/v1/repos/{USERNAME}/{repo_name}/contents/{file_path}",
|
||||||
|
timeout=30,
|
||||||
|
)
|
||||||
|
if meta.ok:
|
||||||
|
size = meta.json().get("size", 0)
|
||||||
|
totals[language] = max(0, totals[language] - size)
|
||||||
|
except requests.RequestException:
|
||||||
|
# Ignore failures – continue with best-effort stats
|
||||||
|
pass
|
||||||
|
|
||||||
total_bytes = sum(totals.values())
|
total_bytes = sum(totals.values())
|
||||||
if total_bytes == 0:
|
if total_bytes == 0:
|
||||||
sys.exit("No language data returned from API.")
|
sys.exit("No language data returned from API.")
|
||||||
|
|||||||
Reference in New Issue
Block a user