Skip to content

Commit e3b2bb2

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

File tree

4 files changed

+91
-15
lines changed

4 files changed

+91
-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: 18 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
@@ -548,20 +548,24 @@ def generate_activity_md(
548548

549549
# Search the description for release notes and add them if they exist
550550
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()]
551+
release_notes = []
552+
in_release_notes = False
553+
for ii in description.split("\n"):
554+
if in_release_notes:
555+
# If we detect a header of equal or lesser level, stop looking
556+
if ii.startswith("#") and len(ii.split(" ")[0]) <= n_levels:
557+
break
558+
# Otherwise append the line and keep going
559+
release_notes.append(ii)
560+
elif "# release notes" in ii.lower():
561+
# When we detect a release notes header,
562+
# start collecting lines underneath and define the header
563+
# level so we know when to stop
564+
in_release_notes = True
565+
n_levels = len(ii.split(" ")[0])
566+
554567
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}"
568+
this_md += "\n\n" + indent("\n".join(release_notes).strip(), " ")
565569
items["md"].append(this_md)
566570

567571
# 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)