Skip to content

Commit 0ff428b

Browse files
CopilotricardoV94
andcommitted
Improve regex to prevent double-formatting already-formatted links
Co-authored-by: ricardoV94 <[email protected]>
1 parent 2d92334 commit 0ff428b

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

scripts/publish_release_notes_to_discourse.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ def format_release_content(config: dict[str, str]) -> tuple[str, str]:
6262

6363
# Format PR links in the release body
6464
# Replace https://github.com/pymc-devs/pymc/pull/123 with [#123](https://github.com/pymc-devs/pymc/pull/123)
65+
# Use negative lookbehind to avoid formatting already-formatted links
6566
release_body = re.sub(
66-
r'https://github\.com/pymc-devs/pymc/pull/(\d+)',
67+
r'(?<!\()\bhttps://github\.com/pymc-devs/pymc/pull/(\d+)\b',
6768
r'[#\1](\g<0>)',
6869
config["RELEASE_BODY"]
6970
)

scripts/test_publish_release_notes.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,27 @@ def test_release_structure(self):
125125
assert "**Repository:** [pymc-devs/pymc](https://github.com/pymc-devs/pymc)" in content
126126
assert "**Release Page:** https://github.com/pymc-devs/pymc/releases/tag/v1.2.3" in content
127127
assert "[#999](https://github.com/pymc-devs/pymc/pull/999)" in content
128+
129+
def test_already_formatted_links_not_double_formatted(self):
130+
"""Test that already-formatted PR links are not double-formatted."""
131+
release_body = """Some changes:
132+
* Already formatted: [#123](https://github.com/pymc-devs/pymc/pull/123)
133+
* Raw link: https://github.com/pymc-devs/pymc/pull/456
134+
"""
135+
136+
config = {
137+
"RELEASE_TAG": "v1.0.0",
138+
"REPO_NAME": "pymc-devs/pymc",
139+
"RELEASE_BODY": release_body,
140+
"RELEASE_URL": "https://github.com/pymc-devs/pymc/releases/tag/v1.0.0",
141+
}
142+
143+
title, content = format_release_content(config)
144+
145+
# Already formatted link should remain unchanged
146+
assert "[#123](https://github.com/pymc-devs/pymc/pull/123)" in content
147+
# Should NOT be double-formatted
148+
assert "[#123]([#123](https://github.com/pymc-devs/pymc/pull/123))" not in content
149+
150+
# Raw link should be formatted
151+
assert "[#456](https://github.com/pymc-devs/pymc/pull/456)" in content

0 commit comments

Comments
 (0)