Skip to content

Commit 0d1b625

Browse files
committed
Add release notes functionality
1 parent 6aa2013 commit 0d1b625

File tree

4 files changed

+94
-15
lines changed

4 files changed

+94
-15
lines changed

docs/index.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ You can find the [resulting markdown here](sample_notebook_activity).
5757
For repositories that use multiple branches, it may be necessary to filter PRs by a branch name. This can be done using the `--branch` parameter in the CLI. Other git references can be used as well in place of a branch name.
5858
```
5959

60-
### Splitting PRs by tags and prefixes
60+
### Split PRs by tags and prefixes
6161

6262
Often you wish to split your PRs into multiple categories so that they are easier
6363
to scan and parse. You may also _only_ want to keep some PRs (e.g. features, or API
@@ -80,6 +80,22 @@ You can choose to *remove* some types of PRs from your changelog by passing the
8080
left-most column above.
8181
```
8282

83+
## Pull release notes from PR descriptions
84+
85+
You can optionally include snippets of release notes directly from the descriptions of Pull Requests.
86+
These will be included just underneath the bullet point text for each PR in the markdown output.
87+
88+
To do so, follow these steps:
89+
90+
1. In your PR description, include a markdown header that begins with `# Release notes`.
91+
The header can be of any level, and capitalization does not matter.
92+
All subsequent text in the PR description will be treated as the release notes, until a header of equal or lesser level is encountered.
93+
2. Use the `--include-release-notes` flag. For example:
94+
95+
```
96+
github-activity --include-release-notes
97+
```
98+
8399
## Use a GitHub API token
84100

85101
`github-activity` uses the GitHub API to pull information about a repository's activity.

github_activity/github_activity.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
import shlex
66
import subprocess
77
import sys
8-
import urllib
98
from pathlib import Path
109
from subprocess import PIPE
1110
from subprocess import run
1211
from tempfile import TemporaryDirectory
12+
from textwrap import indent
1313

1414
import dateutil
1515
import numpy as np
@@ -176,6 +176,7 @@ def generate_all_activity_md(
176176
tags=None,
177177
include_issues=False,
178178
include_opened=False,
179+
include_release_notes=False,
179180
strip_brackets=False,
180181
branch=None,
181182
):
@@ -207,6 +208,8 @@ def generate_all_activity_md(
207208
Include Issues in the markdown output. Default is False.
208209
include_opened : bool
209210
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.
210213
strip_brackets : bool
211214
If True, strip any text between brackets at the beginning of the issue/PR title.
212215
E.g., [MRG], [DOC], etc.
@@ -548,20 +551,24 @@ def generate_activity_md(
548551

549552
# Search the description for release notes and add them if they exist
550553
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+
554570
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(), " ")
565572
items["md"].append(this_md)
566573

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

tests/test_cli.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,19 @@ def test_cli_all(tmpdir, file_regression):
8080
md = path_output.read_text()
8181
index = md.index("## v0.2.0")
8282
file_regression.check(md[index:], extension=".md")
83+
84+
85+
def test_release_notes(tmpdir, file_regression):
86+
"""Release notes that are automatically pulled from PR descriptions."""
87+
path_tmp = Path(tmpdir)
88+
path_output = path_tmp.joinpath("out.md")
89+
url = "https://github.com/executablebooks/jupyter-book"
90+
91+
# This release range covers PRs with
92+
cmd = f"github-activity {url} -s v0.7.1 -u v0.7.3 --include-release-notes -o {path_output}"
93+
94+
run(cmd.split(), check=True)
95+
96+
md = path_output.read_text()
97+
test_md = md[md.index("## New features added"): md.index("## Bugs fixed")]
98+
file_regression.check(test_md, extension=".md")

tests/test_cli/test_release_notes.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## New features added
2+
3+
- ✨ NEW: Adding - chapter entries to _toc.yml [#817](https://github.com/executablebooks/jupyter-book/pull/817) ([@choldgraf](https://github.com/choldgraf))
4+
5+
Here's an example of the TOC structure:
6+
7+
```yaml
8+
- file: intro
9+
numbered: true
10+
11+
- chapter: Get started
12+
sections:
13+
- file: start/overview
14+
- file: start/build
15+
16+
- chapter: Book pages and types
17+
sections:
18+
- file: content/markdown
19+
- file: content/notebooks
20+
21+
- chapter: Reference and test pages
22+
sections:
23+
- file: test_pages/test
24+
sections:
25+
- file: test_pages/layout_elements
26+
- file: test_pages/equations
27+
```
28+
29+
## Enhancements made
30+
31+
- 👌 IMPROVE: improving numbered sections [#826](https://github.com/executablebooks/jupyter-book/pull/826) ([@choldgraf](https://github.com/choldgraf))
32+
- checking for toc modification time [#772](https://github.com/executablebooks/jupyter-book/pull/772) ([@choldgraf](https://github.com/choldgraf))
33+
34+
This is an attempt at checking for the modification time of the table of contents file and forcing a re-build of all pages if this happens. We need to do this because otherwise people could change the toc, but Sphinx won't know to re-build some pages and these TOC changes won't be reflected.
35+
36+
#### This heading will be included in release notes
37+
38+
Here's a sub-heading
39+
- first pass toc directive [#757](https://github.com/executablebooks/jupyter-book/pull/757) ([@choldgraf](https://github.com/choldgraf))
40+

0 commit comments

Comments
 (0)