-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathupdate_readme.py
More file actions
executable file
·80 lines (64 loc) · 2.77 KB
/
Copy pathupdate_readme.py
File metadata and controls
executable file
·80 lines (64 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python3
"""
update_readme_devices.py
This script updates the `README.md` file in the Dasharo Issues repository by generating
a section that lists supported devices and links each one to its open issues on GitHub.
It should be executed each time we add a new device (or drop existing one), to make sure
the list is up to date.
It:
- Loads the `.github/advanced-issue-labeler.yml` policy file.
- Extracts all device labels and their associated keys.
- Generates a Markdown list of device names linking to GitHub issue searches.
- Replaces the content between `<!-- BEGIN DEVICE ISSUES -->` and `<!-- END DEVICE ISSUES -->`
in `README.md` with this list.
Usage:
Run this script from the root of the repository:
python3 update_readme_devices.py
"""
import yaml
import urllib.parse
import re
REPO = "dasharo/dasharo-issues"
YAML_PATH = ".github/advanced-issue-labeler.yml"
README_PATH = "README.md"
START_MARKER = "<!-- BEGIN DEVICE ISSUES -->"
END_MARKER = "<!-- END DEVICE ISSUES -->"
def load_policy_yaml(path):
with open(path, "r") as f:
return yaml.safe_load(f)
def extract_device_entries(policy):
entries = []
for section in policy.get("policy", []):
for sec in section.get("section", []):
if sec.get("id") == ["device"] and "other" in sec.get("block-list", []):
for item in sec.get("label", []):
label_name = item["name"]
for key in item.get("keys", []):
entries.append((key, label_name))
return entries
def generate_issue_search_url(repo, label_name):
quoted = urllib.parse.quote(f'"{label_name}"')
return f"https://github.com/{repo}/issues?q=is%3Aissue+state%3Aopen+label%3A{quoted}"
def generate_readme_section(entries):
lines = ["## Issues per device", "\nBelow is a list of open issues affecting specific devices:"]
for device_name, label_name in sorted(entries, key=lambda x: x[0].lower()):
url = generate_issue_search_url(REPO, label_name)
lines.append(f"- [{device_name}]({url})")
return "\n".join(lines)
def update_readme(readme_path, new_section):
with open(readme_path, "r") as f:
content = f.read()
pattern = re.compile(rf"{START_MARKER}.*?{END_MARKER}", re.DOTALL)
replacement = f"{START_MARKER}\n{new_section}\n{END_MARKER}"
if pattern.search(content):
updated = pattern.sub(replacement, content)
else:
updated = content.strip() + "\n\n" + replacement
with open(readme_path, "w") as f:
f.write(updated)
if __name__ == "__main__":
policy = load_policy_yaml(YAML_PATH)
entries = extract_device_entries(policy)
section = generate_readme_section(entries)
update_readme(README_PATH, section)
print("README.md updated with flat device issue links.")