@@ -285,6 +285,40 @@ def check_entry(
285
285
Path (output ).write_text (final_entry , encoding = "utf-8" )
286
286
287
287
288
+ def splice_github_entry (orig_entry , github_entry ):
289
+ """Splice an entry created on GitHub into one created by build_entry"""
290
+
291
+ # Override PR titles
292
+ gh_regex = re .compile (r"^\* (.*?) by @.*?/pull/(\d+)$" , flags = re .MULTILINE )
293
+ cl_regex = re .compile (r"^- (.*?) \[#(\d+)\]" )
294
+
295
+ lut = {}
296
+ for title , pr in re .findall (gh_regex , github_entry ):
297
+ lut [pr ] = title
298
+
299
+ lines = orig_entry .splitlines ()
300
+ for (ind , line ) in enumerate (lines ):
301
+ match = re .match (cl_regex , line )
302
+ if not match :
303
+ continue
304
+ title , pr = re .findall (cl_regex , line )[0 ]
305
+ if pr in lut :
306
+ lines [ind ] = line .replace (title , lut [pr ])
307
+
308
+ # Handle preamble
309
+ preamble_index = github_entry .index ("## What's Changed" )
310
+ if preamble_index > 0 :
311
+ preamble = github_entry [:preamble_index ]
312
+ if preamble .startswith ("# " ):
313
+ preamble = preamble .replace ("# " , "## " )
314
+ if preamble .startswith ("## " ):
315
+ preamble = preamble .replace ("## " , "### " )
316
+
317
+ lines = preamble .splitlines () + ["" ] + lines
318
+
319
+ return "\n " .join (lines )
320
+
321
+
288
322
def extract_current (changelog_path ):
289
323
"""Extract the current changelog entry"""
290
324
body = ""
0 commit comments