|
5 | 5 | import shlex |
6 | 6 | import subprocess |
7 | 7 | import sys |
8 | | -import urllib |
9 | 8 | from pathlib import Path |
10 | 9 | from subprocess import PIPE |
11 | 10 | from subprocess import run |
12 | 11 | from tempfile import TemporaryDirectory |
| 12 | +from textwrap import indent |
13 | 13 |
|
14 | 14 | import dateutil |
15 | 15 | import numpy as np |
@@ -176,6 +176,7 @@ def generate_all_activity_md( |
176 | 176 | tags=None, |
177 | 177 | include_issues=False, |
178 | 178 | include_opened=False, |
| 179 | + include_release_notes=False, |
179 | 180 | strip_brackets=False, |
180 | 181 | branch=None, |
181 | 182 | ): |
@@ -207,6 +208,8 @@ def generate_all_activity_md( |
207 | 208 | Include Issues in the markdown output. Default is False. |
208 | 209 | include_opened : bool |
209 | 210 | Include a list of opened items in the markdown output. Default is False. |
| 211 | + include_release_notes : bool |
| 212 | + Include the release notes for any PRs with `# Release notes` in the description. |
210 | 213 | strip_brackets : bool |
211 | 214 | If True, strip any text between brackets at the beginning of the issue/PR title. |
212 | 215 | E.g., [MRG], [DOC], etc. |
@@ -548,20 +551,24 @@ def generate_activity_md( |
548 | 551 |
|
549 | 552 | # Search the description for release notes and add them if they exist |
550 | 553 | if include_release_notes: |
551 | | - lines = description.split("\n") |
552 | | - headers = [ii.startswith("#") for ii in lines] |
553 | | - release_notes = [ii for ii in headers if "# release notes" in ii.lower()] |
| 554 | + release_notes = [] |
| 555 | + in_release_notes = False |
| 556 | + for ii in description.split("\n"): |
| 557 | + if in_release_notes: |
| 558 | + # If we detect a header of equal or lesser level, stop looking |
| 559 | + if ii.startswith("#") and len(ii.split(" ")[0]) <= n_levels: |
| 560 | + break |
| 561 | + # Otherwise append the line and keep going |
| 562 | + release_notes.append(ii) |
| 563 | + elif "# release notes" in ii.lower(): |
| 564 | + # When we detect a release notes header, |
| 565 | + # start collecting lines underneath and define the header |
| 566 | + # level so we know when to stop |
| 567 | + in_release_notes = True |
| 568 | + n_levels = len(ii.split(" ")[0]) |
| 569 | + |
554 | 570 | if release_notes: |
555 | | - # Find the line of the next header to know when to stop |
556 | | - release_notes_line = release_notes[0] |
557 | | - next_header_ix = headers.index(release_notes_line) + 1 |
558 | | - next_header = headers[next_header_ix] |
559 | | - release_notes_start = lines.index(release_notes_line) |
560 | | - release_notes_stop = lines.index(next_header) |
561 | | - |
562 | | - # Append the release notes to our output markdown |
563 | | - release_notes = "\n".join(lines[release_notes_start:release_notes_stop]) |
564 | | - this_md += f"\n {release_notes}" |
| 571 | + this_md += "\n\n" + indent("\n".join(release_notes).strip(), " ") |
565 | 572 | items["md"].append(this_md) |
566 | 573 |
|
567 | 574 | # Get functional GitHub references: any git reference or master@{YY-mm-dd} |
|
0 commit comments