refactor: simplify script to output language stats markdown to stdout
Co-authored-by: aider (o3) <aider@aider.chat>
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
"""
|
"""
|
||||||
Gitea Language Stats Action
|
Gitea Language Stats
|
||||||
Calculates the percentage of every programming language used
|
Calculates the percentage of every programming language used
|
||||||
in all repositories of a given account and writes / updates
|
in all repositories of a given account and prints a markdown
|
||||||
a markdown table inside `.profile/README.md` delimited by the
|
table to stdout, delimited by the
|
||||||
markers <!--LANG_STATS_START--> … <!--LANG_STATS_END-->.
|
markers <!--LANG_STATS_START--> … <!--LANG_STATS_END-->.
|
||||||
|
|
||||||
Required environment variables
|
Required environment variables
|
||||||
@@ -76,21 +76,5 @@ for lang, nbytes in pairs:
|
|||||||
|
|
||||||
block = "<!--LANG_STATS_START-->\n" + "".join(lines) + "<!--LANG_STATS_END-->\n"
|
block = "<!--LANG_STATS_START-->\n" + "".join(lines) + "<!--LANG_STATS_END-->\n"
|
||||||
|
|
||||||
# ---------- patch .profile/README.md ----------
|
# ---------- output markdown block ----------
|
||||||
readme_path = ".profile/README.md"
|
print(block)
|
||||||
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()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user