-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathchangelog.py
executable file
·42 lines (32 loc) · 1.07 KB
/
changelog.py
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
#!/usr/bin/env python3
import argparse
import pathlib
import re
def add_missing_links(changelog):
"""Ensure that all the changelog conforms to our common format."""
# Ensure that all launchpad issues are hyperlinks
changelog = re.sub(
r"(?!\[)\blp:?(?P<lpid>\d+)\b(?!\])",
r"[lp:\g<lpid>](https://bugs.launchpad.net/mixxx/+bug/\g<lpid>)",
changelog,
)
# Ensure that all GitHub PRs are hyperlinks
changelog = re.sub(
r"(?!\[)#\b(?P<ghid>\d+)\b(?!\])",
r"[#\g<ghid>](https://github.com/mixxxdj/mixxx/pull/\g<ghid>)",
changelog,
)
return changelog
def main(argv=None):
parser = argparse.ArgumentParser()
parser.add_argument("file", type=pathlib.Path)
args = parser.parse_args(argv)
# Fetch changelog and convert to RST
with args.file.open("r") as fp:
changelog = fp.read()
fixed_changelog = add_missing_links(changelog)
if changelog != fixed_changelog:
with args.file.open("w") as fp:
fp.write(fixed_changelog)
if __name__ == "__main__":
main()