Merge pull request #3903 from GalaxyGamingFR/fix/conventions-body-bom

fix(conventions): read the PR body file with utf-8-sig
This commit is contained in:
Adrià 2026-10-13 13:30:34 +02:00 committed by GitHub
commit e99a1b0aa9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 54 additions and 1 deletions

View File

@ -104,6 +104,8 @@ if(BUILD_TESTING)
set_tests_properties(pad_input PROPERTIES TIMEOUT 20)
add_test(NAME trace_digest COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/tools/tests/test_trace_digest.py)
add_test(NAME conventions_body_bom COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/tools/tests/test_check_conventions_body_bom.py)
endif()
endif()

View File

@ -397,5 +397,5 @@ if __name__ == "__main__":
if pr:
check.pull_request(pr["title"], pr["body"])
elif args.title is not None or args.body:
check.pull_request(args.title or "", open(args.body, encoding="utf-8").read() if args.body else "")
check.pull_request(args.title or "", open(args.body, encoding="utf-8-sig").read() if args.body else "")
raise SystemExit(output(check, os.environ.get("GITHUB_REPOSITORY", "boykopovar/AnyPS5")))

View File

@ -0,0 +1,51 @@
import os
import subprocess
import sys
import tempfile
import unittest
from pathlib import Path
BODY = (
"### What\nFix x.\n\n### Tested\nNot tested.\n\n### Checklist\n"
"- [x] Depends on: none\n- [x] AI-assisted: no\n"
)
class BodyBomTests(unittest.TestCase):
def run_checker(self, body):
checker = Path(__file__).resolve().parents[1] / "check_conventions.py"
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
def git(*args):
return subprocess.run(
["git", "-c", "user.name=Conventions Test", "-c", "user.email=test@example.com",
"-c", "commit.gpgsign=false", *args],
cwd=root, capture_output=True, text=True, check=True,
)
git("init", "-q")
(root / "README.md").write_text("# Example\n", encoding="utf-8")
git("add", ".")
git("commit", "-qm", "docs: add readme")
(root / "body.md").write_bytes(body)
return subprocess.run(
[sys.executable, "-I", str(checker), "--base", "HEAD", "--head", "HEAD",
"--title", "fix: x", "--body", "body.md"],
cwd=root, capture_output=True, text=True, encoding="utf-8",
env={key: value for key, value in os.environ.items()
if key not in ("GITHUB_EVENT_PATH", "GITHUB_STEP_SUMMARY", "GITHUB_ACTIONS")},
)
def test_body_with_utf8_bom_keeps_its_first_section(self):
result = self.run_checker(b"\xef\xbb\xbf" + BODY.encode("utf-8"))
self.assertNotIn("section 'What' is missing", result.stdout)
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
def test_body_without_bom_passes(self):
result = self.run_checker(BODY.encode("utf-8"))
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
if __name__ == "__main__":
unittest.main()