[llvm] code-format: Improve the code-format-helper to be able to run as a git hook (PR #73957)

Louis Dionne via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 1 06:30:28 PST 2023


================
@@ -85,17 +99,25 @@ def update_pr(
         elif create_new:
             pr.as_issue().create_comment(comment_text)
 
-    def run(self, changed_files: list[str], args: argparse.Namespace) -> bool:
+    def run(self, changed_files: list[str], args: FormatArgs) -> bool:
         diff = self.format_run(changed_files, args)
+        should_update_gh = args.token is not None and args.repo is not None
+
         if diff is None:
-            comment_text = f"""
-:white_check_mark: With the latest revision this PR passed the {self.friendly_name}.
-"""
-            self.update_pr(comment_text, args, create_new=False)
+            if should_update_gh:
+                comment_text = f"""
+    :white_check_mark: With the latest revision this PR passed the {self.friendly_name}.
+    """
+                self.update_pr(comment_text, args, create_new=False)
             return True
         elif len(diff) > 0:
-            comment_text = self.pr_comment_text_for_diff(diff)
-            self.update_pr(comment_text, args, create_new=True)
+            if should_update_gh:
+                comment_text = self.pr_comment_text_for_diff(diff)
+                self.update_pr(comment_text, args, create_new=True)
+            else:
+                print(
+                    f"Warning: {self.friendly_name}, {self.name} detected some issues with your code formatting..."
----------------
ldionne wrote:

Right now, the script prints `Warning: C/C++ code formatter, clang-format detected some issues with your code formatting...` when there are formatting issues, but it doesn't format automatically. Is that intended? Should we instead format the code automatically?

https://github.com/llvm/llvm-project/pull/73957


More information about the llvm-commits mailing list