From 8292677a7fe91e657a4f3ed27ba9f35633a49a06 Mon Sep 17 00:00:00 2001 From: Sandy Carter Date: Tue, 16 Jan 2024 14:41:27 -0500 Subject: [PATCH] Get username from PR to use in `google-readability-todo` Improves the recommendation for `google-readability-todo` by providing a proper name which would previously be `TODO(docker)` or `TODO(unknown)`. If for whatever reason, the name cannot be found, it will default to `TODO(your name here)`. Implements #102 without the need for a new parameter. --- .../clang_tidy_review/__init__.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/post/clang_tidy_review/clang_tidy_review/__init__.py b/post/clang_tidy_review/clang_tidy_review/__init__.py index 7b2475b..c119ca1 100644 --- a/post/clang_tidy_review/clang_tidy_review/__init__.py +++ b/post/clang_tidy_review/clang_tidy_review/__init__.py @@ -65,6 +65,7 @@ def build_clang_tidy_warnings( clang_tidy_binary: pathlib.Path, config_file, files, + username: str, ) -> None: """Run clang-tidy on the given files and save output into FIXES_FILE""" @@ -88,7 +89,13 @@ def build_clang_tidy_warnings( start = datetime.datetime.now() try: with message_group(f"Running:\n\t{args}"): - subprocess.run(args, capture_output=True, check=True, encoding="utf-8") + subprocess.run( + args, + capture_output=True, + check=True, + encoding="utf-8", + env={"USER": username}, + ) except subprocess.CalledProcessError as e: print( f"\n\nclang-tidy failed with return code {e.returncode} and error:\n{e.stderr}\nOutput was:\n{e.stdout}" @@ -204,6 +211,10 @@ def get_pr_diff(self) -> List[unidiff.PatchSet]: diff = [unidiff.PatchSet(str(file))[0] for file in unidiff.PatchSet(diffs)] return diff + def get_pr_author(self) -> str: + """Get the username of the PR author. This is used in google-readability-todo""" + return self.pull_request.user.login + def get_pr_comments(self): """Download the PR review comments using the comfort-fade preview headers""" @@ -776,6 +787,8 @@ def create_review( print(f"Line filter for clang-tidy:\n{line_ranges}\n") + username = pull_request.get_pr_author() or "your name here" + # Run clang-tidy with the configured parameters and produce the CLANG_TIDY_FIXES file build_clang_tidy_warnings( line_ranges, @@ -784,6 +797,7 @@ def create_review( clang_tidy_binary, config_file, files, + username, ) # Read and parse the CLANG_TIDY_FIXES file