Skip to content

Commit 6aa2013

Browse files
committed
ENH: Add release notes functionality
1 parent 2851438 commit 6aa2013

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

github_activity/cli.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@
8181
action="store_true",
8282
help="Include a list of opened items in the markdown output",
8383
)
84+
parser.add_argument(
85+
"--include-release-notes",
86+
default=False,
87+
action="store_true",
88+
help="Include the `# release notes` block of each PR in the output markdown.",
89+
)
8490
parser.add_argument(
8591
"--strip-brackets",
8692
default=False,
@@ -165,6 +171,7 @@ def main():
165171
tags=tags,
166172
include_issues=bool(args.include_issues),
167173
include_opened=bool(args.include_opened),
174+
include_release_notes=bool(args.include_release_notes),
168175
strip_brackets=bool(args.strip_brackets),
169176
branch=args.branch,
170177
)

github_activity/github_activity.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ def generate_activity_md(
300300
tags=None,
301301
include_issues=False,
302302
include_opened=False,
303+
include_release_notes=False,
303304
strip_brackets=False,
304305
heading_level=1,
305306
branch=None,
@@ -338,6 +339,9 @@ def generate_activity_md(
338339
Include Issues in the markdown output. Default is False.
339340
include_opened : bool
340341
Include a list of opened items in the markdown output. Default is False.
342+
include_release_notes : bool
343+
Search PR descriptions for a `# Release Notes` block. If found, include
344+
the contents of this block with the changelog output for the PR.
341345
strip_brackets : bool
342346
If True, strip any text between brackets at the beginning of the issue/PR title.
343347
E.g., [MRG], [DOC], etc.
@@ -537,9 +541,27 @@ def generate_activity_md(
537541
for irow, irowdata in items["data"].iterrows():
538542
author = irowdata["author"]
539543
ititle = irowdata["title"]
544+
description = irowdata["body"]
540545
if strip_brackets and ititle.strip().startswith("[") and "]" in ititle:
541546
ititle = ititle.split("]", 1)[-1].strip()
542547
this_md = f"- {ititle} [#{irowdata['number']}]({irowdata['url']}) ([@{author}](https://github.com/{author}))"
548+
549+
# Search the description for release notes and add them if they exist
550+
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+
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}"
543565
items["md"].append(this_md)
544566

545567
# Get functional GitHub references: any git reference or master@{YY-mm-dd}

github_activity/graphql.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
id
2828
title
2929
url
30+
body
3031
createdAt
3132
updatedAt
3233
closedAt

0 commit comments

Comments
 (0)