Skip to content

Commit e79166c

Browse files
fix(KONFLUX-14326): fix PR links in update-infra-deployments (konflux-ci#832)
Rewrite bare #<num> PR references in changelog commit messages to full markdown links pointing to the source repository. Without this, github renders them as links to the infra-deployments repo instead. Assisted-by: Claude Code Signed-off-by: Filip Nikolovski <fnikolov@redhat.com>
1 parent bbf27db commit e79166c

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

scripts/python/helpers/vcs/github.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import base64
77
import json
88
import os
9+
import re
910
import stat
1011
import subprocess
1112
import tempfile
@@ -277,6 +278,11 @@ def compare_changelog(
277278
sha = commit_info["sha"][:7]
278279
url = commit_info["html_url"]
279280
message = commit_info["commit"]["message"].split("\n", 1)[0]
281+
message = re.sub(
282+
r"#(\d+)",
283+
rf"[#\1](https://github.com/{owner_repo}/pull/\1)",
284+
message,
285+
)
280286
author = commit_info.get("author")
281287
login = author.get("login") if isinstance(author, dict) else None
282288
if login:

scripts/python/helpers/vcs/test_github.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,33 @@ def test_compare_changelog_without_github_login() -> None:
378378
assert "@" not in out.split("\n", 1)[1]
379379

380380

381+
def test_compare_changelog_rewrites_pr_references() -> None:
382+
"""Rewrite bare #<num> PR references to full markdown links."""
383+
session = _session()
384+
payload = {
385+
"commits": [
386+
{
387+
"sha": "c" * 40,
388+
"html_url": "https://github.com/org/repo/commit/ccc",
389+
"commit": {
390+
"message": "chore(deps): update dependencies (#453)",
391+
"author": {"name": "Bot"},
392+
},
393+
"author": {"login": "bot"},
394+
}
395+
]
396+
}
397+
with mock.patch.object(github, "_get_json", return_value=payload):
398+
out = github.compare_changelog(
399+
session,
400+
"https://github.com/org/repo",
401+
"old",
402+
"new",
403+
)
404+
assert "[#453](https://github.com/org/repo/pull/453)" in out
405+
assert "#453)" not in out.replace("[#453]", "")
406+
407+
381408
def test_update_pull_request_body() -> None:
382409
"""PATCH the pull request description and return the updated JSON."""
383410
session = _session()

0 commit comments

Comments
 (0)