Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get username from PR to use in google-readability-todo #106

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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