Skip to content

Commit 2d92334

Browse files
CopilotricardoV94
andcommitted
Add PR link formatting to publish_release_notes_to_discourse.py
Co-authored-by: ricardoV94 <[email protected]>
1 parent 5715729 commit 2d92334

File tree

2 files changed

+138
-1
lines changed

2 files changed

+138
-1
lines changed

scripts/publish_release_notes_to_discourse.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22

33
import os
4+
import re
45

56
import requests
67

@@ -58,6 +59,15 @@ def find_category_id(config: dict[str, str]) -> int:
5859
def format_release_content(config: dict[str, str]) -> tuple[str, str]:
5960
title = f"🚀 Release {config['RELEASE_TAG']}"
6061
repo_name = config["REPO_NAME"].split("/")[1]
62+
63+
# Format PR links in the release body
64+
# Replace https://github.com/pymc-devs/pymc/pull/123 with [#123](https://github.com/pymc-devs/pymc/pull/123)
65+
release_body = re.sub(
66+
r'https://github\.com/pymc-devs/pymc/pull/(\d+)',
67+
r'[#\1](\g<0>)',
68+
config["RELEASE_BODY"]
69+
)
70+
6171
content = f"""A new release of **{repo_name}** is now available!
6272
6373
## 📦 Release Information
@@ -69,7 +79,7 @@ def format_release_content(config: dict[str, str]) -> tuple[str, str]:
6979
7080
## 📋 Release Notes
7181
72-
{config["RELEASE_BODY"]}
82+
{release_body}
7383
7484
---
7585
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Copyright 2024 - present The PyMC Developers
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
import re
15+
16+
from publish_release_notes_to_discourse import format_release_content
17+
18+
19+
class TestFormatReleaseContent:
20+
def test_pr_links_are_formatted(self):
21+
"""Test that PR links are formatted correctly in the release body."""
22+
# Realistic release body from v5.26.0
23+
release_body = """<!-- Release notes generated using configuration in .github/release.yml at main -->
24+
25+
## What's Changed
26+
### Major Changes 🛠
27+
* Bump PyTensor dependency and drop support for NumPy <2.0, and Python 3.10 by @ricardoV94 in https://github.com/pymc-devs/pymc/pull/7910
28+
* Functions that try to infer inputs of the graph fail with more than one input. This includes `Model.compile_fn`, `gradient`, `jacobian` and `hessian_diag`.
29+
* `Model.compile_logp` now expects all model variables as input, even when only a subset of the logp terms is requested.
30+
* Many pytensor functions from moved from `pytensor.graph.basic` to `pytensor.graph.traversal`, including `ancestors`, `graph_inputs`, and toposort related functions.
31+
* Remove deprecated `noise` parameter for GPs by @williambdean in https://github.com/pymc-devs/pymc/pull/7886
32+
33+
### New Features 🎉
34+
* Implement `logcdf` for `CensoredRV` by @asifzubair in https://github.com/pymc-devs/pymc/pull/7884
35+
* Derive logprob for Split operation by @ricardoV94 in https://github.com/pymc-devs/pymc/pull/7875
36+
### Bugfixes 🪲
37+
* Fix bug in mixture logprob inference with `None` indices by @asifzubair in https://github.com/pymc-devs/pymc/pull/7877
38+
### Documentation 📖
39+
* Add model_to_mermaid to docs by @williambdean in https://github.com/pymc-devs/pymc/pull/7868
40+
* Use rst code-block over code:: by @williambdean in https://github.com/pymc-devs/pymc/pull/7882
41+
### Maintenance 🔧
42+
* Show more digits of step size in progress_bar by @ricardoV94 in https://github.com/pymc-devs/pymc/pull/7870
43+
* Allow for specification of 'var_names' in 'mock_sample' by @tomicapretto in https://github.com/pymc-devs/pymc/pull/7906
44+
45+
## New Contributors
46+
* @asifzubair made their first contribution in https://github.com/pymc-devs/pymc/pull/7871
47+
48+
**Full Changelog**: https://github.com/pymc-devs/pymc/compare/v5.25.1...v5.26.0"""
49+
50+
config = {
51+
"RELEASE_TAG": "v5.26.0",
52+
"REPO_NAME": "pymc-devs/pymc",
53+
"RELEASE_BODY": release_body,
54+
"RELEASE_URL": "https://github.com/pymc-devs/pymc/releases/tag/v5.26.0",
55+
}
56+
57+
title, content = format_release_content(config)
58+
59+
# Check that the title is correct
60+
assert title == "🚀 Release v5.26.0"
61+
62+
# Check that PR links in pymc-devs/pymc are formatted correctly
63+
assert "[#7910](https://github.com/pymc-devs/pymc/pull/7910)" in content
64+
assert "[#7886](https://github.com/pymc-devs/pymc/pull/7886)" in content
65+
assert "[#7884](https://github.com/pymc-devs/pymc/pull/7884)" in content
66+
assert "[#7875](https://github.com/pymc-devs/pymc/pull/7875)" in content
67+
assert "[#7877](https://github.com/pymc-devs/pymc/pull/7877)" in content
68+
assert "[#7868](https://github.com/pymc-devs/pymc/pull/7868)" in content
69+
assert "[#7882](https://github.com/pymc-devs/pymc/pull/7882)" in content
70+
assert "[#7870](https://github.com/pymc-devs/pymc/pull/7870)" in content
71+
assert "[#7906](https://github.com/pymc-devs/pymc/pull/7906)" in content
72+
assert "[#7871](https://github.com/pymc-devs/pymc/pull/7871)" in content
73+
74+
# Check that the raw PR link format is not present
75+
assert "https://github.com/pymc-devs/pymc/pull/7910" in content # it's still in the formatted link
76+
# But NOT as a standalone link (which would appear without the [#xxx](...) wrapper)
77+
# We can verify this by checking the pattern doesn't match the raw format
78+
# Find raw PR links (not inside markdown link syntax)
79+
raw_pr_links = re.findall(
80+
r'(?<!\()\bhttps://github\.com/pymc-devs/pymc/pull/\d+(?!\))',
81+
content
82+
)
83+
assert len(raw_pr_links) == 0, f"Found raw PR links: {raw_pr_links}"
84+
85+
# Check that other links remain unchanged (e.g., the Full Changelog link)
86+
assert "**Full Changelog**: https://github.com/pymc-devs/pymc/compare/v5.25.1...v5.26.0" in content
87+
88+
def test_non_pymc_links_unchanged(self):
89+
"""Test that PR links from other repositories are not affected."""
90+
release_body = """Some changes:
91+
* Feature from external repo in https://github.com/other-org/other-repo/pull/123
92+
* Our feature in https://github.com/pymc-devs/pymc/pull/456
93+
"""
94+
95+
config = {
96+
"RELEASE_TAG": "v1.0.0",
97+
"REPO_NAME": "pymc-devs/pymc",
98+
"RELEASE_BODY": release_body,
99+
"RELEASE_URL": "https://github.com/pymc-devs/pymc/releases/tag/v1.0.0",
100+
}
101+
102+
title, content = format_release_content(config)
103+
104+
# Check that pymc-devs/pymc PR link is formatted
105+
assert "[#456](https://github.com/pymc-devs/pymc/pull/456)" in content
106+
107+
# Check that other repo PR link is unchanged
108+
assert "https://github.com/other-org/other-repo/pull/123" in content
109+
assert "[#123](https://github.com/other-org/other-repo/pull/123)" not in content
110+
111+
def test_release_structure(self):
112+
"""Test that the overall release structure is correct."""
113+
config = {
114+
"RELEASE_TAG": "v1.2.3",
115+
"REPO_NAME": "pymc-devs/pymc",
116+
"RELEASE_BODY": "Test body with PR https://github.com/pymc-devs/pymc/pull/999",
117+
"RELEASE_URL": "https://github.com/pymc-devs/pymc/releases/tag/v1.2.3",
118+
}
119+
120+
title, content = format_release_content(config)
121+
122+
assert title == "🚀 Release v1.2.3"
123+
assert "A new release of **pymc** is now available!" in content
124+
assert "**Version:** `v1.2.3`" in content
125+
assert "**Repository:** [pymc-devs/pymc](https://github.com/pymc-devs/pymc)" in content
126+
assert "**Release Page:** https://github.com/pymc-devs/pymc/releases/tag/v1.2.3" in content
127+
assert "[#999](https://github.com/pymc-devs/pymc/pull/999)" in content

0 commit comments

Comments
 (0)