Skip to content

Commit

Permalink
Get username from PR to use in google-readability-todo
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bwrsandman committed Jan 16, 2024
1 parent 0dd8d19 commit 8292677
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion post/clang_tidy_review/clang_tidy_review/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand All @@ -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}"
Expand Down Expand Up @@ -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"""

Expand Down Expand Up @@ -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,
Expand All @@ -784,6 +797,7 @@ def create_review(
clang_tidy_binary,
config_file,
files,
username,
)

# Read and parse the CLANG_TIDY_FIXES file
Expand Down

0 comments on commit 8292677

Please sign in to comment.