|
1 | 1 | import os |
2 | 2 | import sys |
3 | 3 | from glob import glob |
| 4 | +from pathlib import Path |
4 | 5 |
|
5 | 6 |
|
6 | 7 | def publisher(project): |
| 8 | + print(f"Generating {project} report...", end="") |
| 9 | + basedir = os.path.dirname(__file__) |
| 10 | + with open(os.path.join(basedir, "template.md")) as fh: |
| 11 | + template = fh.read() |
| 12 | + |
| 13 | + issues = glob(os.path.join(basedir, "reports/issues/*.md")) |
| 14 | + for issue in issues: |
| 15 | + with open(issue) as fh: |
| 16 | + issue_text = fh.read() |
| 17 | + issue_name = Path(issue).stem |
| 18 | + template = template.replace(f"{{{{ {issue_name} }}}}", issue_text) |
| 19 | + |
| 20 | + prs = glob(os.path.join(basedir, "reports/pull_requests/*.md")) |
| 21 | + for pr in prs: |
| 22 | + with open(pr) as fh: |
| 23 | + pr_text = fh.read() |
| 24 | + pr_name = Path(pr).stem |
| 25 | + template = template.replace(f"{{{{ {pr_name} }}}}", pr_text) |
| 26 | + |
| 27 | + template = template.replace("{{ project }}", project) |
| 28 | + |
7 | 29 | os.makedirs("_generated", exist_ok=True) |
8 | | - report_files = glob(os.path.join(os.path.dirname(__file__), "reports/*.md")) |
| 30 | + with open(f"_generated/{project}.md", "w") as fh: |
| 31 | + fh.write(template) |
9 | 32 |
|
10 | | - for report in report_files: |
11 | | - print(f"Generating {project} report...", end="") |
12 | | - with open(report) as fh: |
13 | | - template = fh.read() |
14 | | - with open(f"_generated/{project}.md", "w") as fh: |
15 | | - fh.write(template.replace("{{ project }}", project)) |
16 | | - print("OK") |
| 33 | + print("OK") |
0 commit comments