refactor: simplify script to output language stats markdown to stdout

Co-authored-by: aider (o3) <aider@aider.chat>
This commit is contained in:
Mark Eaton
2025-08-13 11:58:07 -04:00
co-authored by aider
parent 22260907cf
commit 89cbb2d581
+5 -21
View File
@@ -1,9 +1,9 @@
#!/usr/bin/env python3
"""
Gitea Language Stats Action
Gitea Language Stats
Calculates the percentage of every programming language used
in all repositories of a given account and writes / updates
a markdown table inside `.profile/README.md` delimited by the
in all repositories of a given account and prints a markdown
table to stdout, delimited by the
markers <!--LANG_STATS_START--> … <!--LANG_STATS_END-->.
Required environment variables
@@ -76,21 +76,5 @@ for lang, nbytes in pairs:
block = "<!--LANG_STATS_START-->\n" + "".join(lines) + "<!--LANG_STATS_END-->\n"
# ---------- patch .profile/README.md ----------
readme_path = ".profile/README.md"
os.makedirs(".profile", exist_ok=True)
if not os.path.exists(readme_path):
with open(readme_path, "w", encoding="utf-8") as fh:
fh.write(block)
else:
with open(readme_path, "r+", encoding="utf-8") as fh:
content = fh.read()
if "<!--LANG_STATS_START-->" in content and "<!--LANG_STATS_END-->" in content:
pre = content.split("<!--LANG_STATS_START-->")[0]
post = content.split("<!--LANG_STATS_END-->")[-1]
content = pre + block + post
else:
content = content.rstrip() + "\n\n" + block
fh.seek(0)
fh.write(content)
fh.truncate()
# ---------- output markdown block ----------
print(block)