-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathchangelog.py
More file actions
80 lines (57 loc) · 2.43 KB
/
Copy pathchangelog.py
File metadata and controls
80 lines (57 loc) · 2.43 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python3
import argparse
import logging
import re
import sys
from argparse import RawTextHelpFormatter
from lib.changelog import *
def main():
"""
Download the brave-browser/CHANGELOG.md file, parse it, and
return either markdown or html for a particular Brave tag.
Example:
python script/changelog.py -t refs/tags/v1.5.51 \
-u https://raw.githubusercontent.com/brave/brave-browser/master/CHANGELOG.md -o markdown
## [1.5.51](https://github.com/brave/brave-browser/releases/tag/v1.5.51)
- Added new setting that allows Brave Rewards icon in the URL to be hidden if Rewards \
is inactive. ([#2975](https://github.com/brave/brave-browser/issues/2975))
"""
args = parse_args()
if args.debug:
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
changelog_url = args.url
tag = args.tag
if not re.match(r'^refs/tags/', tag) and not re.match(r'^v', tag):
logging.error(" Tag prefix must contain {} or {}".format(
"\"refs/tags/\"", "\"v\""))
exit(1)
match = re.match(r'^refs/tags/(.*)$', tag)
if match:
tag = match.group(1)
match = re.match(r'^v(.*)$', tag)
if match:
version = match.group(1)
logging.debug("CHANGELOG_URL: {}".format(changelog_url))
logging.debug("TAG: {}".format(tag))
logging.debug("VERSION: {}".format(version))
changelog_txt = download_from_url(args, logging, changelog_url)
if args.output == 'markdown':
print(render_markdown(changelog_txt, version, logging))
elif args.output == 'html':
print(render_html(changelog_txt, version, logging))
def parse_args():
desc = "Parse Brave Browser changelog and return changes for a tag"
parser = argparse.ArgumentParser(
description=desc, formatter_class=RawTextHelpFormatter)
parser.add_argument('-d', '--debug', action='store_true',
help='Print debug statements')
parser.add_argument(
'-o', '--output', help='Output format: markdown or html (required)', required=True)
parser.add_argument('-t', '--tag',
help='Brave version tag (allowed format: "v1.5.45" or "refs/tags/v1.5.45") (required)',
required=True)
parser.add_argument(
'-u', '--url', help='URL for Brave Browser raw markdown file (required)', required=True)
return parser.parse_args()
if __name__ == '__main__':
sys.exit(main())