| 5 |
| from release_caption import ( |
| 6 | CAPTION_BUDGET, |
| 7 | is_changelog_ignored, |
| 8 | linkify_prs, |
| 9 | read_apk_version, |
| 10 | read_gradle_property, |
| 11 | render_test_caption, |
| 12 | visible_length, |
| 13 | ) |
| 14 |
| 15 |
| 16 | class ReleaseCaptionTest(unittest.TestCase): |
| 17 | def test_renders_conventional_commit_with_link_and_escaping(self): |
| 18 | caption = render_test_caption( |
| 19 | "feat(ci): improve <test> notification", |
| 20 | "12.9.0", |
| 21 | "1241", |
| 22 | "abcdef123456", |
| 23 | "https://github.com/NextAlone/Nagram", |
| 24 | ) |
| 25 |
| 26 | self.assertIn( |
| 27 | "🧪 <b>Nagram</b> <code>12.9.0</code> <i>(1241)</i> · <b>Test Version</b>", |
| 28 | caption, |
| 29 | ) |
| 30 | self.assertIn("✨ <b>Features</b>", caption) |
| 31 | self.assertIn( |
| 32 | '<a href="https://github.com/NextAlone/Nagram/commit/abcdef123456">[abcdef1]</a>', |
| 33 | caption, |
| 34 | ) |
| 35 | self.assertIn("improve <test> notification", caption) |
| 36 |
| 37 | def test_uses_merge_and_other_groups_and_stays_within_caption_budget(self): |
| 38 | merge_caption = render_test_caption("Merge branch 'main'", "test", "1") |
| 39 | caption = render_test_caption("release " + "<&>" * 1000, "test", "1") |
| 40 |
| 41 | self.assertIn("🔀 <b>Merge</b>", merge_caption) |
| 42 | self.assertIn("📌 <b>Other</b>", caption) |
| 43 | self.assertLessEqual(visible_length(caption), CAPTION_BUDGET) |
| 44 | self.assertTrue(caption.endswith("…")) |
| 45 |
| 46 | def test_omits_commit_marked_ignore_from_changelog(self): |
| 47 | commit_message = "chore: regenerate artifacts\n\ninternal only [ignore]" |
| 48 | caption = render_test_caption( |
| 49 | commit_message, |
| 50 | "12.9.0", |
| 51 | "1241", |
| 52 | "abcdef123456", |
| 53 | "https://github.com/NextAlone/Nagram", |
| 54 | ) |
| 55 |
| 56 | self.assertTrue(is_changelog_ignored(commit_message)) |
| 57 | self.assertEqual( |
| 58 | "🧪 <b>Nagram</b> <code>12.9.0</code> <i>(1241)</i> · <b>Test Version</b>", |
| 59 | caption, |
| 60 | ) |
| 61 |
| 62 | def test_reads_gradle_property(self): |
| 63 | with TemporaryDirectory() as directory: |
| 64 | path = Path(directory) / "gradle.properties" |
| 65 | path.write_text("APP_VERSION_NAME=12.9.0\n", encoding="utf-8") |
| 66 |
| 67 | self.assertEqual("12.9.0", read_gradle_property("APP_VERSION_NAME", path)) |
| 68 | self.assertEqual("Unknown", read_gradle_property("APP_VERSION_CODE", path)) |
| 69 |
| 70 | def test_reads_actual_nagram_version_from_apk_filename(self): |
| 71 | path = Path("Nagram-v12.9.0(1241)-arm64-v8a.apk") |
| 72 |
| 73 | self.assertEqual(("12.9.0", 1241), read_apk_version(path)) |
| 74 |
| 75 | with self.assertRaisesRegex(ValueError, "Cannot read version"): |
| 76 | read_apk_version(Path("app.apk")) |
| 77 |
| 78 |
| 79 | def test_linkifies_parenthesized_pr_ref_in_subject(self): |
| 80 | caption = render_test_caption( |
| 81 | "feat: add configurable switch style (#156)", |
| 82 | "12.9.0", |
| 83 | "1241", |
| 84 | "abcdef123456", |
| 85 | "https://github.com/NextAlone/Nagram", |
| 86 | ) |
| 87 |
| 88 | self.assertIn( |
| 89 | '(<a href="https://github.com/NextAlone/Nagram/pull/156">#156</a>)', |
| 90 | caption, |
| 91 | ) |
| 92 |
| 93 |
| 94 | def test_linkifies_pr_ref_in_detail_body(self): |
| 95 | caption = render_test_caption( |
| 96 | "fix(AyuFilter): NPE when rebuilding regex filter cache\n\nSee (#173) for more context.", |
| 97 | "12.9.0", |
| 98 | "1241", |
| 99 | "abcdef123456", |
| 100 | "https://github.com/NextAlone/Nagram", |
| 101 | ) |
| 102 |
| 103 | self.assertIn( |
| 104 | '(<a href="https://github.com/NextAlone/Nagram/pull/173">#173</a>)', |
| 105 | caption, |
| 106 | ) |
| 107 |
| 108 | def test_no_link_when_repository_url_missing(self): |
| 109 | result = linkify_prs("fix (#99)", "") |
| 110 | self.assertEqual("fix (#99)", result) |
| 111 |
| 112 | if __name__ == "__main__": |
| 113 | unittest.main() |
| 114 |