1
0
mirror of https://codeberg.org/fediverse/fep.git synced 2026-08-05 11:46:04 +00:00

Automate things (#117)

This pull requests contains the basic automation scripts as described in `ISSUE_TEMPLATES/README.md`.

Feps needed to be changed to continue links to their tracking issues.

- [x] Description of how to best merge a pull request still missing
- [x] Rename folder ISSUE_TEMPLATES to something better.

Co-authored-by: Helge <helge.krueger@gmail.com>
Reviewed-on: https://codeberg.org/fediverse/fep/pulls/117
This commit is contained in:
helge
2023-07-16 07:43:02 +00:00
parent e28f96265b
commit 16acf44939
33 changed files with 416 additions and 72 deletions
+75
View File
@@ -0,0 +1,75 @@
import glob
def get_fep_ids():
for fep in glob.glob("fep/*"):
yield fep.removeprefix("fep/")
class FepFile:
def __init__(self, fep):
self.fep = fep
with open(self.filename) as f:
self.frontmatter, self.content = FepFile.parsefile(f)
@property
def filename(self):
return f"fep/{self.fep}/fep-{self.fep}.md"
@property
def summary(self):
result = []
is_summary = False
for x in self.content:
if is_summary:
if x.startswith("##"):
return "\n".join(result)
result.append(x)
elif x == "## Summary":
is_summary = True
def write(self):
with open(self.filename, "w") as f:
f.write("---\n")
for x in self.frontmatter:
f.write(x + "\n")
f.write("---\n")
for x in self.content:
f.write(x + "\n")
@property
def parsed_frontmatter(self):
split = [x.split(":", 1) for x in self.frontmatter]
return {a: b.strip() for a, b in split}
@property
def title(self):
titles = [x for x in self.content if x.startswith("# ")]
assert len(titles) > 0
title = titles[0]
begin_title = f"# FEP-{self.fep}: "
assert title.startswith(begin_title)
true_title = title.removeprefix(begin_title)
return true_title
@staticmethod
def parsefile(f):
lines = f.readlines()
status = 0
frontmatter = []
content = []
for line in lines:
if line == "---\n" and status <= 2:
status += 1
elif status == 1:
frontmatter.append(line.removesuffix("\n"))
elif status >= 2:
content.append(line.removesuffix("\n"))
return frontmatter, content
+34
View File
@@ -0,0 +1,34 @@
import pytest
import hashlib
from scripts.tools import get_fep_ids, FepFile
@pytest.mark.parametrize("fep", get_fep_ids())
def test_fep(fep):
fep_file = FepFile(fep)
content = fep_file.content
parsed_frontmatter = fep_file.parsed_frontmatter
assert "status" in parsed_frontmatter
assert parsed_frontmatter["status"] in ["DRAFT", "FINAL"]
assert parsed_frontmatter["slug"] == f'"{fep}"'
assert "authors" in parsed_frontmatter
assert "## Summary" in content
assert "## Copyright" in content
titles = [x for x in content if x.startswith("# ")]
assert len(titles) > 0
title = titles[0]
begin_title = f"# FEP-{fep}: "
assert title.startswith(begin_title)
true_title = title.removeprefix(begin_title)
expected_slug = hashlib.sha256(true_title.encode("utf-8")).hexdigest()[:4]
assert expected_slug == fep