Skip to content

Commit 790c544

Browse files
committed
Hacky solution to add topic labels
1 parent c0a03ff commit 790c544

File tree

1 file changed

+39
-12
lines changed

1 file changed

+39
-12
lines changed

dev/releases/release_notes.py

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
import json
1515
import os
16+
import re
17+
import copy
1618
import subprocess
1719
import sys
1820
from datetime import datetime
@@ -137,8 +139,7 @@ def get_tag_date(tag: str) -> str:
137139

138140

139141
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}'
142143
print("query: ", query)
143144
res = subprocess.run(
144145
[
@@ -167,19 +168,23 @@ def pr_to_md(pr: Dict[str, Any]) -> str:
167168
title = pr["title"]
168169
mdstring = f"- [#{k}](https://github.com/oscar-system/Oscar.jl/pull/{k}) {title}\n"
169170
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)
180172
mdstring = mdstring.replace("- ", f"- [#{k}](https://github.com/oscar-system/Oscar.jl/pull/{k}) ")
181173
return mdstring
182174

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+
183188

184189
def has_label(pr: Dict[str, Any], label: str) -> bool:
185190
return any(x["name"] == label for x in pr["labels"])
@@ -327,6 +332,27 @@ def changes_overview(
327332
# finally copy over this new file to changelog.md
328333
os.rename(newfile, finalfile)
329334

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
330356

331357
def main(new_version: str) -> None:
332358
major, minor, patchlevel = map(int, new_version.split("."))
@@ -373,6 +399,7 @@ def main(new_version: str) -> None:
373399

374400
print("Downloading filtered PR list")
375401
prs = get_pr_list(startdate, extra)
402+
prs = split_pr_into_changelog(prs)
376403
# print(json.dumps(prs, sort_keys=True, indent=4))
377404

378405
# reset changelog file to state tracked in git

0 commit comments

Comments
 (0)