mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 22:05:59 +00:00
Include PR descriptions and queue catalog updates (#421)
* Include a short PR description in build announcements * Queue catalog refreshes without cancelling publishing runs
This commit is contained in:
1 parent
e0fc8362b8
commit
679948e792
3 files changed
+49
-2
No files matched your search
@@ -83,9 +83,29 @@ def plain_title(title):
|
||||
return re.sub(r"([\\`*_~|\[\]<>])", r"\\\1", title)
|
||||
|
||||
|
||||
def build_content(repo, number, title, sha, apk, release):
|
||||
def description_excerpt(body):
|
||||
body = re.sub(r"<!--.*?-->", "", body or "", flags=re.DOTALL)
|
||||
body = re.sub(r"```.*?```", "", body, flags=re.DOTALL)
|
||||
for paragraph in re.split(r"\n\s*\n", body):
|
||||
lines = [line.strip() for line in paragraph.splitlines()]
|
||||
lines = [line for line in lines if line and not re.match(r"^(#{1,6}\s|[-*]\s+\[[ xX]\]|🤖)", line)]
|
||||
text = " ".join(lines)
|
||||
if not text or text.strip("*_` :.").lower() in (
|
||||
"summary", "description", "checklist", "testing", "n/a", "none",
|
||||
"please describe your changes here", "describe your changes"):
|
||||
continue
|
||||
text = re.sub(r"\[([^\]]+)\]\([^)]+\)", r"\1", text)
|
||||
if len(text) > 300:
|
||||
text = text[:297].rsplit(" ", 1)[0] + "..."
|
||||
return plain_title(text)
|
||||
return ""
|
||||
|
||||
|
||||
def build_content(repo, number, title, sha, apk, release, description=None):
|
||||
excerpt = description_excerpt(description)
|
||||
return (f"**Signed PR test build** `pr-{number}` · `{sha[:7]}`\n"
|
||||
f"[#{number}](https://github.com/{repo}/pull/{number}): {plain_title(title)}\n"
|
||||
+ (f"\n{excerpt}\n\n" if excerpt else "") +
|
||||
"_Not merged — for testing._\n"
|
||||
f"Download: [standard APK](<{apk}>) · [all variants](<{release}>)")
|
||||
|
||||
@@ -123,7 +143,7 @@ def sync(mode, repo, number, discord, sha="", apk="", release=""):
|
||||
{"content": retired_content(message["content"], pull.get("merged", False)),
|
||||
"allowed_mentions": {"parse": []}, "flags": 4})
|
||||
return
|
||||
content = build_content(repo, number, pull["title"], sha, apk, release)
|
||||
content = build_content(repo, number, pull["title"], sha, apk, release, pull.get("body"))
|
||||
if len(content) > 1800:
|
||||
raise RuntimeError("Discord announcement is too long")
|
||||
payload = {"content": content, "allowed_mentions": {"parse": []}, "flags": 4}
|
||||
|
||||
@@ -127,6 +127,32 @@ class PrDiscordTest(unittest.TestCase):
|
||||
self.assertIn(r"\~\~Retired\~\~", content)
|
||||
self.assertLessEqual(len(module.retired_content(content, True)), 2000)
|
||||
|
||||
def test_description_uses_first_useful_paragraph(self):
|
||||
body = "## Summary\n\n<!-- private template guidance -->\n\nFixes the [Store import](https://example.com).\n\nMore implementation detail."
|
||||
content = module.build_content("Droid-Deck/DroidDeck", "400", "Store import", "a" * 40, "apk", "release", body)
|
||||
self.assertIn("\n\nFixes the Store import.\n\n", content)
|
||||
self.assertNotIn("private template", content)
|
||||
self.assertNotIn("More implementation", content)
|
||||
|
||||
def test_empty_and_template_descriptions_are_omitted(self):
|
||||
for body in (None, "", "## Summary\n\n<!-- fill this out -->\n\n- [ ] Tests\n- [x] Code review", "N/A"):
|
||||
self.assertEqual("", module.description_excerpt(body))
|
||||
|
||||
def test_description_cannot_override_status_or_ping(self):
|
||||
self.pull["body"] = "~~Closed~~ @everyone\n\n```\nsecret template code\n```"
|
||||
self.publish()
|
||||
payload = self.discord.request.call_args.args[2]
|
||||
self.assertIn(r"\~\~Closed\~\~ @everyone", payload["content"])
|
||||
self.assertNotIn("secret template", payload["content"])
|
||||
self.assertEqual({"parse": []}, payload["allowed_mentions"])
|
||||
|
||||
def test_long_description_leaves_room_for_retirement(self):
|
||||
content = module.build_content("Droid-Deck/DroidDeck", "410", "*" * 300, "a" * 40,
|
||||
"https://github.com/Droid-Deck/DroidDeck-CI/releases/download/pr-410/build.apk",
|
||||
"https://github.com/Droid-Deck/DroidDeck-CI/releases/tag/pr-410", "~" * 10000)
|
||||
self.assertLessEqual(len(content), 1800)
|
||||
self.assertLessEqual(len(module.retired_content(content, True)), 2000)
|
||||
|
||||
|
||||
original_report = module.report_comment
|
||||
|
||||
|
||||
Reference in new issue
Block a user