port_publish: read gh's and Kira's output as UTF-8

gh() and kira() ran subprocess with text=True and no encoding, so on
Windows Python decoded their UTF-8 output with the code page: an issue
body's → came back as →, and merged() wrote it back on the next update.
Follows d3grando's review on #3587.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
GIGABAIT93andClaude Opus 5.5 committed 2026-10-30 08:24:38 +02:00
1 parent 68f036059e
commit 6ffe36494e
2 files changed
+14 -2

No files matched your search

+11
View File
@@ -1,3 +1,4 @@
import json
from pathlib import Path
import unittest
from unittest import mock
@@ -93,6 +94,16 @@ class PublishTests(unittest.TestCase):
self.assertIn("- [ ] #101 [26.4] Protocol", bodies["[26.4] Port to Minecraft 26.4"])
self.assertFalse([c for c in calls if c[:2] == ("label", "create")])
def test_gh_and_kira_read_utf8_whatever_the_code_page(self):
# gh and node print UTF-8; without an encoding, Windows decodes it with the code page (cp1252 here).
def run(command, **kwargs):
out = json.dumps({"body": "a → b"}, ensure_ascii=False).encode("utf-8")
return mock.Mock(stdout=out.decode(kwargs.get("encoding") or "cp1252"))
with mock.patch.object(publish.subprocess, "run", side_effect=run):
self.assertEqual(json.loads(publish.gh("issue", "view"))["body"], "a → b")
self.assertEqual(publish.kira("board_list", {})["body"], "a → b")
if __name__ == "__main__":
unittest.main()
+3 -2
View File
@@ -191,7 +191,8 @@ def plan(report, diff, store_path, open_issues):
# --- GitHub and Kira (only with --yes) ---------------------------------------------------------------------
def gh(*args):
return subprocess.run(["gh", *args], capture_output=True, text=True, check=True).stdout
# gh prints UTF-8, whatever the system's code page.
return subprocess.run(["gh", *args], capture_output=True, encoding="utf-8", check=True).stdout
def open_version_port_issues():
@@ -241,7 +242,7 @@ def issue(action, name, text, number, new):
def kira(tool, arguments):
return json.loads(subprocess.run(["node", str(KIRA), tool, json.dumps(arguments)], capture_output=True,
text=True, check=True).stdout or "null")
encoding="utf-8", check=True).stdout or "null")
def kira_card(new, url):