-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease_note_diff.py
More file actions
50 lines (38 loc) · 1.49 KB
/
Copy pathrelease_note_diff.py
File metadata and controls
50 lines (38 loc) · 1.49 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
import argparse
from pathlib import Path
IMPORTANT_WORDS = ["fix", "fixed", "launch", "launched", "deprecate", "deprecated", "limit", "support", "breaking"]
def read_lines(path):
return [line.strip() for line in Path(path).read_text().splitlines() if line.strip()]
def diff_lines(old_lines, new_lines):
old_set = set(old_lines)
new_set = set(new_lines)
added = [line for line in new_lines if line not in old_set]
removed = [line for line in old_lines if line not in new_set]
important = [line for line in added if any(word in line.lower() for word in IMPORTANT_WORDS)]
return {
"added": added,
"removed": removed,
"important": important,
}
def format_report(result):
lines = []
lines.append(f"Added: {len(result['added'])}")
lines.append(f"Removed: {len(result['removed'])}")
lines.append(f"Important additions: {len(result['important'])}")
if result["important"]:
lines.append("")
lines.append("Important additions:")
for item in result["important"]:
lines.append(f"- {item}")
return "\n".join(lines)
def main():
parser = argparse.ArgumentParser(description="Diff two release note files.")
parser.add_argument("old_file")
parser.add_argument("new_file")
args = parser.parse_args()
old_lines = read_lines(args.old_file)
new_lines = read_lines(args.new_file)
result = diff_lines(old_lines, new_lines)
print(format_report(result))
if __name__ == "__main__":
main()