Debian Codegraph @

contrib/relnotes

raw
1 #!/usr/bin/env python3
2 """Generate release notes from our commit log.
3
4 This uses the relnotes extension directives when they're available,
5 and falls back to our old pre-relnotes logic that used to live in the
6 release-tools repo.
7 """
8 import argparse
9 import re
10 import subprocess
11
12 rules = {
13 # keep
14 r"\(issue": 100,
15 r"\(BC\)": 100,
16 r"\(API\)": 100,
17 r"\(SEC\)": 100,
18 # core commands, bump up
19 r"(commit|files|log|pull|push|patch|status|tag|summary)(|s|es):": 20,
20 r"(annotate|alias|branch|bookmark|clone|graft|import|verify).*:": 20,
21 # extensions, bump up
22 r"(mq|shelve|rebase):": 20,
23 # newsy
24 r": deprecate": 20,
25 r": new.*(extension|flag|module)": 10,
26 r"( ability|command|feature|option|support)": 10,
27 # experimental
28 r"hg-experimental": 20,
29 r"(from|graduate).*experimental": 15,
30 r"(hide|mark).*experimental": -10,
31 # bug-like?
32 r"(fix|don't break|improve)": 7,
33 r"(not|n't|avoid|fix|prevent).*crash": 10,
34 r"vulnerab": 10,
35 # boring stuff, bump down
36 r"^contrib": -5,
37 r"debug": -5,
38 r"help": -5,
39 r"minor": -5,
40 r"(doc|metavar|bundle2|obsolete|obsmarker|rpm|setup|debug\S+:)": -15,
41 r"(check-code|check-commit|check-config|import-checker)": -20,
42 r"(flake8|lintian|pyflakes|pylint)": -20,
43 # cleanups and refactoring
44 r"(clean ?up|white ?space|spelling|quoting)": -20,
45 r"(flatten|dedent|indent|nesting|unnest)": -20,
46 r"(typo|hint|note|comment|TODO|FIXME)": -20,
47 r"(style:|convention|one-?liner)": -20,
48 r"(argument|absolute_import|attribute|assignment|mutable)": -15,
49 r"(scope|True|False)": -10,
50 r"(unused|useless|unnecessar|superfluous|duplicate|deprecated)": -10,
51 r"(redundant|pointless|confusing|uninitialized|meaningless|dead)": -10,
52 r": (drop|remove|delete|rip out)": -10,
53 r": (inherit|rename|simplify|naming|inline)": -10,
54 r"(correct doc|docstring|document .* method)": -20,
55 r"(abstract|factor|extract|prepare|split|replace| import)": -20,
56 r": add.*(function|method|implementation|example)": -10,
57 r": (move|extract) .* (to|into|from|out of)": -20,
58 r": implement ": -5,
59 r": use .* implementation": -20,
60 r": use .* instead of": -20,
61 # code
62 r"_": -10,
63 r"__": -5,
64 r"\(\)": -5,
65 r"\S\S\S+\.\S\S\S\S+": -5,
66 # dumb keywords
67 r"\S+/\S+:": -10,
68 r"\S+\.\S+:": -10,
69 # python compatibility
70 r"[Pp]y(|thon) ?[23]": -20,
71 r"pycompat": -20,
72 r"(coerce|convert|encode) .*to (byte|sys|)(s|str|string)": -20,
73 # tests
74 r"^test(|s|ing|runner|-\S+):": -20,
75 r"^(f|hghave|run-tests):": -20,
76 r"add.* tests?": -20,
77 r"(buildbot|fuzz|mock|ratchet)": -10,
78 # drop
79 r"^i18n-": -50,
80 r"^i18n:.*(hint|comment)": -50,
81 r"perf:": -50,
82 r"Added.*for changeset": -50,
83 r"^_": -50,
84 }
85
86 cutoff = 10
87 commits = []
88
89 groupings = [
90 (r"util|parsers|repo|ctx|context|revlog|filelog|alias|cmdutil", "core"),
91 (r"revset|template|ui|dirstate|hook|i18n|transaction|wire|vfs", "core"),
92 (r"dispatch|exchange|localrepo|streamclone|color|pager", "core"),
93 (r"hgweb|paper|coal|gitweb|monoblue|spartan", "hgweb"),
94 (r"pull|push|revert|resolve|annotate|bookmark|branch|clone", "commands"),
95 (r"commands|commit|config|files|graft|import|log|merge|patch", "commands"),
96 (r"phases|status|summary|amend|tag|help|verify", "commands"),
97 (r"rebase|mq|convert|eol|histedit|largefiles", "extensions"),
98 (r"shelve|unshelve", "extensions"),
99 ]
100
101
102 def wikify(desc):
103 desc = desc.replace("(issue", "(Bts:issue")
104 desc = re.sub(r"\b([0-9a-f]{12})\b", r"Cset:\1", desc)
105 # stop ParseError from being recognized as a (nonexistent) wiki page
106 desc = re.sub(r" ([A-Z][a-z]+[A-Z][a-z]+)\b", r" !\1", desc)
107 # prevent wiki markup of magic methods
108 desc = re.sub(r"\b(\S*__\S*)\b", r"`\1`", desc)
109 return desc
110
111
112 def main():
113 desc = "example: %(prog)s 4.7.2 --stoprev 4.8rc0"
114 ap = argparse.ArgumentParser(description=desc)
115 ap.add_argument(
116 "startrev",
117 metavar="REV",
118 type=str,
119 help=(
120 "Starting revision for the release notes. This revision "
121 "won't be included, but later revisions will."
122 ),
123 )
124 ap.add_argument(
125 "--stoprev",
126 metavar="REV",
127 type=str,
128 default="@",
129 help=(
130 "Stop revision for release notes. This revision will be included,"
131 " but no later revisions will. This revision needs to be "
132 "a descendant of startrev."
133 ),
134 )
135 args = ap.parse_args()
136 fromext = subprocess.check_output(
137 [
138 "hg",
139 "--config",
140 "extensions.releasenotes=",
141 "releasenotes",
142 "-r",
143 "only(%s, %s)" % (args.stoprev, args.startrev),
144 ]
145 ).decode("utf-8")
146 # Find all release notes from un-relnotes-flagged commits.
147 for entry in sorted(
148 subprocess.check_output(
149 [
150 "hg",
151 "log",
152 "-r",
153 "only(%s, %s) - merge()" % (args.stoprev, args.startrev),
154 "-T",
155 r"{desc|firstline}\n",
156 ]
157 )
158 .decode("utf-8")
159 .splitlines()
160 ):
161 desc = entry.replace("`", "'")
162
163 score = 0
164 for rule, val in rules.items():
165 if re.search(rule, desc):
166 score += val
167
168 if score >= cutoff:
169 commits.append(wikify(desc))
170 # Group unflagged notes.
171 groups = {}
172 bcs = []
173 apis = []
174
175 for d in commits:
176 if "(BC)" in d:
177 bcs.append(d)
178 if "(API)" in d:
179 apis.append(d)
180 for rule, g in groupings:
181 if re.match(rule, d):
182 groups.setdefault(g, []).append(d)
183 break
184 else:
185 groups.setdefault("unsorted", []).append(d)
186 print(fromext)
187 # print legacy release notes sections
188 for g in sorted(groups):
189 print("\n=== %s ===" % g)
190 for d in sorted(groups[g]):
191 print(" * %s" % d)
192
193 if bcs:
194 print("\n=== Behavior Changes ===\n")
195
196 for d in sorted(bcs):
197 print(" * %s" % d)
198
199 if apis:
200 print("\n=== Internal API Changes ===\n")
201
202 for d in sorted(apis):
203 print(" * %s" % d)
204
205
206 if __name__ == "__main__":
207 main()