|
13 | 13 |
|
14 | 14 | import json |
15 | 15 | import os |
| 16 | +import re |
| 17 | +import copy |
16 | 18 | import subprocess |
17 | 19 | import sys |
18 | 20 | from datetime import datetime |
@@ -137,8 +139,7 @@ def get_tag_date(tag: str) -> str: |
137 | 139 |
|
138 | 140 |
|
139 | 141 | def get_pr_list(date: str, extra: str) -> List[Dict[str, Any]]: |
140 | | - #query = f'merged:>={date} -label:"release notes: not needed" -label:"release notes: added" base:master {extra}' |
141 | | - query = '5271' |
| 142 | + query = f'merged:>={date} -label:"release notes: not needed" -label:"release notes: added" base:master {extra}' |
142 | 143 | print("query: ", query) |
143 | 144 | res = subprocess.run( |
144 | 145 | [ |
@@ -167,19 +168,23 @@ def pr_to_md(pr: Dict[str, Any]) -> str: |
167 | 168 | title = pr["title"] |
168 | 169 | mdstring = f"- [#{k}](https://github.com/oscar-system/Oscar.jl/pull/{k}) {title}\n" |
169 | 170 | if has_label(pr,'release notes: use body'): |
170 | | - body = pr['body'] |
171 | | - index1 = body.lower().find("## release notes") |
172 | | - if index1 == -1: |
173 | | - ## not found |
174 | | - ## complain and return fallback |
175 | | - print(f"Release notes section not found in PR number {pr['number']}!!") |
176 | | - return mdstring |
177 | | - index2 = body.find('---', index1) |
178 | | - # there are 17 characters from index 1 until the next line |
179 | | - mdstring = body[index1+17:index2] |
| 171 | + mdstring = body_to_release_notes(pr) |
180 | 172 | mdstring = mdstring.replace("- ", f"- [#{k}](https://github.com/oscar-system/Oscar.jl/pull/{k}) ") |
181 | 173 | return mdstring |
182 | 174 |
|
| 175 | +def body_to_release_notes(pr): |
| 176 | + body = pr['body'] |
| 177 | + index1 = body.lower().find("## release notes") |
| 178 | + if index1 == -1: |
| 179 | + ## not found |
| 180 | + ## complain and return fallback |
| 181 | + print(f"Release notes section not found in PR number {pr['number']}!!") |
| 182 | + return mdstring |
| 183 | + index2 = body.find('---', index1) |
| 184 | + # there are 17 characters from index 1 until the next line |
| 185 | + mdstring = body[index1+17:index2] |
| 186 | + return mdstring |
| 187 | + |
183 | 188 |
|
184 | 189 | def has_label(pr: Dict[str, Any], label: str) -> bool: |
185 | 190 | return any(x["name"] == label for x in pr["labels"]) |
@@ -327,6 +332,27 @@ def changes_overview( |
327 | 332 | # finally copy over this new file to changelog.md |
328 | 333 | os.rename(newfile, finalfile) |
329 | 334 |
|
| 335 | +def split_pr_into_changelog(prs: List): |
| 336 | + childprlist = [] |
| 337 | + for pr in prs: |
| 338 | + if has_label(pr, 'release notes: use body'): |
| 339 | + mdstring = body_to_release_notes(pr).strip() |
| 340 | + mdlines = mdstring.split('\r\n') |
| 341 | + pattern = r'\{package: .*\}' |
| 342 | + for line in mdlines: |
| 343 | + if not '{package: ' in line: |
| 344 | + continue |
| 345 | + mans = re.search(pattern, line) |
| 346 | + packagestring = mans.group()[1:-1] |
| 347 | + cpr = copy.deepcopy(pr) |
| 348 | + mindex = line.find('{package:') |
| 349 | + line = line[0:mindex] |
| 350 | + cpr['labels'].append({'name': packagestring}) |
| 351 | + cpr['body'] = f'---\r\n## Release Notes\r\n{line}\r\n---' |
| 352 | + childprlist.append(cpr) |
| 353 | + prs.remove(pr) |
| 354 | + prs.extend(childprlist) |
| 355 | + return prs |
330 | 356 |
|
331 | 357 | def main(new_version: str) -> None: |
332 | 358 | major, minor, patchlevel = map(int, new_version.split(".")) |
@@ -373,6 +399,7 @@ def main(new_version: str) -> None: |
373 | 399 |
|
374 | 400 | print("Downloading filtered PR list") |
375 | 401 | prs = get_pr_list(startdate, extra) |
| 402 | + prs = split_pr_into_changelog(prs) |
376 | 403 | # print(json.dumps(prs, sort_keys=True, indent=4)) |
377 | 404 |
|
378 | 405 | # reset changelog file to state tracked in git |
|
0 commit comments