from unidiff import PatchSet
pr_regex = re.compile(r'(\/(\/|\*)|[Cc*!])\s+(?P<pr>PR [a-z+-]+\/[0-9]+)')
+prnum_regex = re.compile(r'PR (?P<comp>[a-z+-]+)/(?P<num>[0-9]+)')
dr_regex = re.compile(r'(\/(\/|\*)|[Cc*!])\s+(?P<dr>DR [0-9]+)')
dg_regex = re.compile(r'{\s+dg-(error|warning)')
identifier_regex = re.compile(r'^([a-zA-Z0-9_#].*)')
script_folder = os.path.realpath(__file__)
root = os.path.dirname(os.path.dirname(script_folder))
+firstpr = ''
+
def find_changelog(path):
folder = os.path.split(path)[0]
prs = []
out = ''
diff = PatchSet(data)
+ global firstpr
for file in diff:
# skip files that can't be parsed
# Found dg-warning/dg-error line
break
+ if prs:
+ firstpr = prs[0]
+
if fill_pr_titles:
out += get_pr_titles(prs)
start = list(takewhile(lambda l: not l.startswith('#'), lines))
end = lines[len(start):]
with open(args.changelog, 'w') as f:
+ if not start or not start[0]:
+ # initial commit subject line 'component: [PRnnnnn]'
+ m = prnum_regex.match(firstpr)
+ if m:
+ title = f'{m.group("comp")}: [PR{m.group("num")}]'
+ start.insert(0, title)
if start:
- # appent empty line
+ # append empty line
if start[-1] != '':
start.append('')
else: