Skip to content

Commit 4bef2d6

Browse files
committed
Add ability to splice github release entry
1 parent 2d0b599 commit 4bef2d6

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

jupyter_releaser/changelog.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,40 @@ def check_entry(
285285
Path(output).write_text(final_entry, encoding="utf-8")
286286

287287

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+
288322
def extract_current(changelog_path):
289323
"""Extract the current changelog entry"""
290324
body = ""

jupyter_releaser/tests/test_functions.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,29 @@ def test_get_empty_changelog(py_package, mocker):
196196
assert not ("...None" in resp)
197197

198198

199+
def test_splice_github_entry(py_package, mocker):
200+
version = util.get_version()
201+
202+
mocked_gen = mocker.patch("jupyter_releaser.changelog.generate_activity_md")
203+
mocked_gen.return_value = testutil.CHANGELOG_ENTRY
204+
branch = "foo"
205+
util.run("git branch baz/bar")
206+
util.run("git tag v1.0.0 baz/bar")
207+
util.run("git tag v1.1.0a0 baz/bar")
208+
ref = "heads/baz/bar"
209+
resp = changelog.get_version_entry(ref, branch, "baz/bar", version, since_last_stable=True)
210+
211+
updated = changelog.splice_github_entry(resp, testutil.GITHUB_CHANGELOG_ENTRY)
212+
213+
assert "Defining contributions" in updated
214+
215+
preamble = "# My title\nmy content\n"
216+
updated = changelog.splice_github_entry(resp, preamble + testutil.GITHUB_CHANGELOG_ENTRY)
217+
218+
assert "Defining contributions" in updated
219+
assert preamble in updated
220+
221+
199222
def test_compute_sha256(py_package):
200223
assert len(util.compute_sha256(py_package / "CHANGELOG.md")) == 64
201224

jupyter_releaser/tests/util.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@
5353
5454
"""
5555

56+
GITHUB_CHANGELOG_ENTRY = """
57+
## What's Changed
58+
* Some improvements to `since` and opened issues list @choldgraf in https://github.com/executablebooks/github-activity/pull/8
59+
* Defining contributions by @choldgraf in https://github.com/executablebooks/github-activity/pull/14
60+
* Fixing link to changelog with refs by @choldgraf in https://github.com/executablebooks/github-activity/pull/11
61+
62+
63+
**Full Changelog**: https://github.com/executablebooks/github-activity/compare/479cc4b2f5504945021e3c4ee84818a10fabf810...ed7f1ed78b523c6b9fe6b3ac29e834087e299296
64+
"""
65+
5666

5767
def setup_cfg_template(package_name="foo", module_name=None):
5868
return f"""

0 commit comments

Comments
 (0)