|
| 1 | +from subprocess import run as _run, STDOUT, PIPE |
| 2 | +import re |
| 3 | + |
| 4 | + |
| 5 | +def run(cmd) -> str: |
| 6 | + return _run(cmd.split(" "), stdout=PIPE, stderr=STDOUT, encoding="utf8").stdout |
| 7 | + |
| 8 | + |
| 9 | +def process_line(s: str, repo: str) -> str: |
| 10 | + """Generates links from commit and issue references (like 0c14d77, #123) to correct repo and such""" |
| 11 | + s = re.sub(r"#([0-9]+)", rf"[#\1](https://github.com/ActivityWatch/{repo}/issues/\1)", s) |
| 12 | + return s |
| 13 | + |
| 14 | + |
| 15 | +def commit_linkify(commitid: str, repo: str) -> str: |
| 16 | + return f"[`{commitid}`](https://github.com/ActivityWatch/{repo}/commit/{commitid})" |
| 17 | + |
| 18 | + |
| 19 | +def build(): |
| 20 | + prev_release = run("git describe --tags --abbrev=0").strip() |
| 21 | + summary_bundle = run(f"git log {prev_release}...master --oneline --decorate") |
| 22 | + print("### activitywatch (bundle repo)") |
| 23 | + for line in summary_bundle.split("\n"): |
| 24 | + if line: |
| 25 | + commit = line.split(" ")[0] |
| 26 | + line = ' '.join(line.split(' ')[1:]) |
| 27 | + commit_link = commit_linkify(commit, 'activitywatch') |
| 28 | + line = f" - {line} ({commit_link})" |
| 29 | + print(process_line(line, "activitywatch")) |
| 30 | + |
| 31 | + summary_subrepos = run(f"git submodule summary {prev_release}") |
| 32 | + for s in summary_subrepos.split("\n\n"): |
| 33 | + lines = s.split("\n") |
| 34 | + header = lines[0] |
| 35 | + if header.strip(): |
| 36 | + _, name, commitrange, count = header.split(" ") |
| 37 | + name = name.strip(".").strip("/") |
| 38 | + print(f"\n### {name} {commitrange}") |
| 39 | + commits = [process_line(" - " + l.strip(" ").strip(">").strip(" "), name) for l in lines[1:]] |
| 40 | + print("\n".join(commits)) |
| 41 | + |
| 42 | + |
| 43 | +if __name__ == "__main__": |
| 44 | + build() |
0 commit comments