diff --git a/.github/actions/prepare-telegram-issue-message/prepare.py b/.github/actions/prepare-telegram-issue-message/prepare.py index a5474cf..a983aa2 100644 --- a/.github/actions/prepare-telegram-issue-message/prepare.py +++ b/.github/actions/prepare-telegram-issue-message/prepare.py @@ -58,10 +58,10 @@ def body_excerpt(value, limit=ISSUE_BODY_LIMIT): def format_closed(repository, issue, actor): - label = escape_markdown(f"Issue #{issue['number']}") + label = escape_markdown(f"issue {issue['number']}") link = f"[{label}]({escape_link_url(issue['url'])})" parts = [ - escape_markdown(repository), + f"*{escape_markdown(repository)}*", f"{link} closed", f"*{escape_markdown(issue['title'])}*", escape_markdown(actor), diff --git a/.github/actions/prepare-telegram-pr-message/prepare.py b/.github/actions/prepare-telegram-pr-message/prepare.py index 5ab438a..63f44d9 100644 --- a/.github/actions/prepare-telegram-pr-message/prepare.py +++ b/.github/actions/prepare-telegram-pr-message/prepare.py @@ -28,7 +28,7 @@ def escape_link_url(value): def pull_request_link(pull_request): - label = escape_markdown(f"PR #{pull_request['number']}") + label = escape_markdown(f"PR {pull_request['number']}") url = escape_link_url(pull_request["url"]) return f"[{label}]({url})" @@ -43,14 +43,14 @@ def format_opened(repository, pull_request, event_action): } event = events.get(event_action, "opened") return ( - f"{escape_markdown(repository)} · {pull_request_link(pull_request)} {event} · " + f"*{escape_markdown(repository)}* · {pull_request_link(pull_request)} {event} · " f"*{escape_markdown(pull_request['title'])}* · {escape_markdown(author_login(pull_request))}" ) def format_merged(repository, pull_request): return ( - f"{escape_markdown(repository)} · {pull_request_link(pull_request)} merged · " + f"*{escape_markdown(repository)}* · {pull_request_link(pull_request)} merged · " f"*{escape_markdown(pull_request['title'])}* · {escape_markdown(author_login(pull_request))}" ) @@ -66,7 +66,7 @@ def format_digest(repository, pull_requests, now=None): now = now or datetime.now(timezone.utc) count = len(pull_requests) - header = f"{escape_markdown(repository)} · {count} open {'PR' if count == 1 else 'PRs'}" + header = f"*{escape_markdown(repository)}* · {count} open {'PR' if count == 1 else 'PRs'}" lines = [] for pull_request in pull_requests[:DIGEST_PR_LIMIT]: age = max(0, (now - parse_github_time(pull_request["createdAt"])).days) diff --git a/test/test_telegram_notifications.py b/test/test_telegram_notifications.py index 1cc1355..4e62557 100644 --- a/test/test_telegram_notifications.py +++ b/test/test_telegram_notifications.py @@ -38,13 +38,13 @@ def test_formats_opened_pull_request(self): self.assertEqual( message, - "owner/repo · [PR \\#42](https://github.com/owner/repo/pull/42) opened · " + "*owner/repo* · [PR 42](https://github.com/owner/repo/pull/42) opened · " "*feat: add notifications* · octocat", ) def test_formats_ready_and_reopened_pull_request_actions(self): - self.assertIn("[PR \\#42](https://github.com/owner/repo/pull/42) ready", PR_TELEGRAM.format_opened("owner/repo", self.pull_request, "ready_for_review")) - self.assertIn("[PR \\#42](https://github.com/owner/repo/pull/42) reopened", PR_TELEGRAM.format_opened("owner/repo", self.pull_request, "reopened")) + self.assertIn("[PR 42](https://github.com/owner/repo/pull/42) ready", PR_TELEGRAM.format_opened("owner/repo", self.pull_request, "ready_for_review")) + self.assertIn("[PR 42](https://github.com/owner/repo/pull/42) reopened", PR_TELEGRAM.format_opened("owner/repo", self.pull_request, "reopened")) def test_skips_draft_pull_request(self): self.pull_request["isDraft"] = True @@ -56,7 +56,7 @@ def test_formats_merged_pull_request(self): self.assertEqual( message, - "owner/repo · [PR \\#42](https://github.com/owner/repo/pull/42) merged · " + "*owner/repo* · [PR 42](https://github.com/owner/repo/pull/42) merged · " "*feat: add notifications* · octocat", ) @@ -78,7 +78,7 @@ def test_open_pull_request_digest_excludes_drafts_and_reports_age(self): ) self.assertIn("1 open PR", message) - self.assertTrue(message.startswith("owner/repo")) + self.assertTrue(message.startswith("*owner/repo*")) self.assertIn("octocat · 2d", message) self.assertNotIn("#41", message) self.assertNotIn("more", message) @@ -100,8 +100,8 @@ def test_open_pull_request_digest_lists_at_most_ten_pull_requests(self): message = PR_TELEGRAM.format_digest("owner/repo", pull_requests) self.assertIn("12 open PRs", message) - self.assertIn(r"[PR \#10](https://github.com/owner/repo/pull/10) *feat: add notifications*", message) - self.assertNotIn(r"[PR \#11](https://github.com/owner/repo/pull/11) *feat: add notifications*", message) + self.assertIn("[PR 10](https://github.com/owner/repo/pull/10) *feat: add notifications*", message) + self.assertNotIn("[PR 11](https://github.com/owner/repo/pull/11) *feat: add notifications*", message) self.assertIn(r"[\.\.\.and 2 more](https://github.com/owner/repo/pulls)", message) def test_open_pull_request_digest_stays_within_telegram_limit(self): @@ -142,7 +142,7 @@ def test_closed_issue_includes_body(self): self.assertEqual( message, - "owner/repo · [Issue \\#12](https://github.com/owner/repo/issues/12) closed · " + "*owner/repo* · [issue 12](https://github.com/owner/repo/issues/12) closed · " "*Move notifications* · octocat\nResolution summary\\.", )