[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
Wed Dec 6 08:08:30 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:
Sorry, I missed your comments on this PR. I think the status quo is fine, we can start like this (with a warning) and if we think it's annoying, we can change it later. Without experience with the hook, I'm not really sure what behavior we want so whatever we decide would be a coin flip.
https://github.com/llvm/llvm-project/pull/73957
More information about the llvm-commits
mailing list