|
38 | 38 | from crowdgit.services.base.base_service import BaseService |
39 | 39 | from crowdgit.services.maintainer.bedrock import invoke_bedrock |
40 | 40 | from crowdgit.services.maintainer.section_extractor import SectionExtractor |
41 | | -from crowdgit.services.utils import run_shell_command |
| 41 | +from crowdgit.services.utils import run_shell_command, safe_decode |
42 | 42 | from crowdgit.settings import MAINTAINER_RETRY_INTERVAL_DAYS, MAINTAINER_UPDATE_INTERVAL_HOURS |
43 | 43 |
|
44 | 44 |
|
@@ -140,6 +140,11 @@ class MaintainerService(BaseService): |
140 | 140 |
|
141 | 141 | _section_extractor = SectionExtractor() |
142 | 142 |
|
| 143 | + @staticmethod |
| 144 | + async def _read_text_file(file_path: str) -> str: |
| 145 | + async with aiofiles.open(file_path, "rb") as f: |
| 146 | + return safe_decode(await f.read()) |
| 147 | + |
143 | 148 | def make_role(self, title: str): |
144 | 149 | title = title.lower() |
145 | 150 | title = ( |
@@ -554,8 +559,7 @@ async def find_candidate_files( |
554 | 559 | for candidate_path in all_paths: |
555 | 560 | file_path = os.path.join(repo_path, candidate_path) |
556 | 561 | try: |
557 | | - async with aiofiles.open(file_path, "r", encoding="utf-8") as f: |
558 | | - content = await f.read() |
| 562 | + content = await self._read_text_file(file_path) |
559 | 563 | except Exception as e: |
560 | 564 | self.logger.warning(f"Failed to read candidate {candidate_path}: {repr(e)}") |
561 | 565 | continue |
@@ -638,9 +642,7 @@ async def try_saved_maintainer_file( |
638 | 642 | f"Saved maintainer file exists, reading content: '{saved_maintainer_file}'" |
639 | 643 | ) |
640 | 644 | try: |
641 | | - async with aiofiles.open(file_path, "r", encoding="utf-8") as f: |
642 | | - content = await f.read() |
643 | | - |
| 645 | + content = await self._read_text_file(file_path) |
644 | 646 | result = await self.analyze_and_build_result(saved_maintainer_file, content) |
645 | 647 | cost += result.total_cost |
646 | 648 | return result, cost |
@@ -784,8 +786,7 @@ def _attach_metadata(result: MaintainerResult) -> MaintainerResult: |
784 | 786 | ) |
785 | 787 | else: |
786 | 788 | try: |
787 | | - async with aiofiles.open(file_path, "r", encoding="utf-8") as f: |
788 | | - content = await f.read() |
| 789 | + content = await self._read_text_file(file_path) |
789 | 790 | result = await self.analyze_and_build_result(ai_file_name, content) |
790 | 791 | total_cost += result.total_cost |
791 | 792 | return _attach_metadata(result) |
|
0 commit comments