diff --git a/metagpt/ext/cr/actions/code_review.py b/metagpt/ext/cr/actions/code_review.py index db9893aee..ae6086f11 100644 --- a/metagpt/ext/cr/actions/code_review.py +++ b/metagpt/ext/cr/actions/code_review.py @@ -166,6 +166,8 @@ class CodeReview(Action): async def cr_by_points(self, patch: PatchSet, points: list[Point]): comments = [] for patched_file in patch: + if not patched_file: + continue if patched_file.path.endswith(".py"): points = [p for p in points if p.language == "Python"] elif patched_file.path.endswith(".java"): @@ -180,10 +182,11 @@ class CodeReview(Action): resp = await self.llm.aask(prompt) json_str = parse_json_code_block(resp)[0] comments_batch = json.loads(json_str) - patched_file_path = patched_file.path - for c in comments_batch: - c["commented_file"] = patched_file_path - comments += comments_batch + if comments_batch: + patched_file_path = patched_file.path + for c in comments_batch: + c["commented_file"] = patched_file_path + comments += comments_batch return comments diff --git a/metagpt/tools/libs/cr.py b/metagpt/tools/libs/cr.py index f802af620..ea6acf654 100644 --- a/metagpt/tools/libs/cr.py +++ b/metagpt/tools/libs/cr.py @@ -30,7 +30,7 @@ class CodeReview: Args: patch_path: The local path of the patch file or the url of the pull request. Example: "/data/xxx-pr-1.patch", "https://github.com/xx/XX/pull/1362" cr_output_file: Output file path where code review comments will be saved. Example: "cr/xxx-pr-1.json" - cr_point_file: File path for specifying code review points. Set `None` to use a predefined file. + cr_point_file: File path for specifying code review points. If not specified, this parameter is not passed.. """ patch = await self._get_patch_content(patch_path) cr_point_file = cr_point_file if cr_point_file else Path(metagpt.ext.cr.__file__).parent / "points.json"