Merge pull request #8025 from emirplus/fix-pr-overlap-markdown-links

fix(tools): recognize markdown links and pull request URLs in pr_overlap dependencies
This commit is contained in:
Dean authored and GitHub committed 2026-10-22 14:24:04 +13:00
commit 94fbb8cea8
2 files changed
+24 -1

No files matched your search

+6 -1
View File
@@ -41,10 +41,15 @@ def upstream():
def depends_on(body):
body = re.sub(r"<!--.*?-->", "", body or "", flags=re.S)
repo = re.escape(globals().get("REPO", "boykopovar/AnyPS5"))
repo_pattern = rf"(?:{repo}|boykopovar/AnyPS5)"
body = re.sub(rf"\[([^\]]*)\]\(https?://github\.com/{repo_pattern}/pull/(\d+)(?:[#/?][^)\s]*)?\)", r"#\2", body, flags=re.IGNORECASE)
body = re.sub(rf"\[([^\]]*)\]\(https?://github\.com/(?!{repo_pattern}/)[^/\s]+/[^/\s]+/pull/\d+[^)\s]*\)", "", body, flags=re.IGNORECASE)
body = re.sub(r"\[([^\]]+)\]\([^)]+\)", r"\1", body)
body = re.sub(rf"https?://github\.com/{repo_pattern}/pull/(\d+)\b(?:/[^\s]*)?", r"#\1", body, flags=re.IGNORECASE)
match = next((match for match in DEPENDS.finditer(body) if match.group(1).strip()), None) or PLAIN_DEPENDS.search(body)
return {int(n) for n in re.findall(r"#(\d+)", match.group(1))} if match else set()
def open_prs(base):
query = urlencode({"state": "open", "base": base, "per_page": 100})
out = gh("api", "--paginate", f"repos/{REPO}/pulls?{query}")
@@ -47,6 +47,24 @@ class DependencyTests(unittest.TestCase):
with self.subTest(body=body):
self.assertEqual(pull_requests(body)[1]["depends"], {2, 3})
def test_markdown_links_and_full_urls(self):
for body in (
"- [x] Depends on: [#2](https://github.com/owner/repo/pull/2)",
"- [x] Depends on: https://github.com/owner/repo/pull/2",
"- [x] Depends on: [PR #2](https://github.com/owner/repo/pull/2)",
"- [x] Depends on: https://github.com/owner/repo/pull/2/files",
"- [x] Depends on: https://github.com/owner/repo/pull/2#issuecomment-1",
"- [x] Depends on: https://github.com/BOYKOPOVAR/AnyPS5/pull/2",
"Depends on: [#2](https://github.com/owner/repo/pull/2), [#3](https://github.com/owner/repo/pull/3)",
"Depends on:\n- [#2](https://github.com/owner/repo/pull/2)\n- [#3](https://github.com/owner/repo/pull/3)",
"- [x] Depends on: [none](https://example.com)",
"- [x] Depends on: https://github.com/shadps4-emu/shadPS4/pull/1234",
"- [x] Depends on: [#1234](https://github.com/shadps4-emu/shadPS4/pull/1234)",
):
with self.subTest(body=body):
expected = set() if "none" in body or "shadps4" in body else ({2, 3} if "3" in body else {2})
self.assertEqual(pull_requests(body)[1]["depends"], expected)
def test_later_references_are_not_dependencies(self):
for newline in ("\n", "\r\n"):
for declaration in ("Depends on #2.", "Depends on: #2"):