-
-
Notifications
You must be signed in to change notification settings - Fork 163
Expand file tree
/
Copy pathrelease-notes.py
More file actions
executable file
·43 lines (33 loc) · 1 KB
/
release-notes.py
File metadata and controls
executable file
·43 lines (33 loc) · 1 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
#!/usr/bin/env python3
import argparse
import re
import pathlib
import sys
_STDIO = pathlib.Path("-")
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--input", type=pathlib.Path, default="CHANGELOG.md")
parser.add_argument("--tag", required=True)
parser.add_argument("-o", "--output", type=pathlib.Path, required=True)
args = parser.parse_args()
if args.input == _STDIO:
lines = sys.stdin.readlines()
else:
with args.input.open() as fh:
lines = fh.readlines()
version = args.tag.lstrip("v")
note_lines = []
for line in lines:
if line.startswith("## ") and version in line:
note_lines.append(line)
elif note_lines and line.startswith("## "):
break
elif note_lines:
note_lines.append(line)
notes = "".join(note_lines).strip()
if args.output == _STDIO:
print(notes)
else:
args.output.write_text(notes)
if __name__ == "__main__":
main()