-
-
Notifications
You must be signed in to change notification settings - Fork 7
feat: capture and output clang version used #124
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #124 +/- ##
===========================================
+ Coverage 99.88% 100.00% +0.11%
===========================================
Files 24 24
Lines 1798 1826 +28
===========================================
+ Hits 1796 1826 +30
+ Misses 2 0 -2 ☔ View full report in Codecov by Sentry. |
also fix some errors: 1. about filter files per clang tool 2. merged suggestions' file name must match exactly
when tool was not used at all OR review was not requested from a particular tool
WalkthroughThe changes in this pull request involve significant updates across multiple files in the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 6
🧹 Outside diff range and nitpick comments (12)
tests/test_comment_length.py (2)
19-20
: Consider using a more realistic version string.While the current implementation works, using a placeholder version "x.y.z" might not fully represent real-world scenarios. Consider using a more realistic version string (e.g., "10.0.0") to ensure the test covers actual use cases.
versions = ClangVersions() -versions.format = "x.y.z" +versions.format = "10.0.0"
26-26
: LGTM: Clang versions parameter added correctly.The
clang_versions
parameter has been consistently added to bothmake_comment
calls, which aligns with the PR objective to display the clang version used in the output.Consider renaming the
versions
variable toclang_versions
for clarity:-versions = ClangVersions() -versions.format = "x.y.z" +clang_versions = ClangVersions() +clang_versions.format = "x.y.z" thread_comment = GithubApiClient.make_comment( files=files, format_checks_failed=format_checks_failed, tidy_checks_failed=0, - clang_versions=versions, + clang_versions=clang_versions, len_limit=abs_limit, ) step_summary = GithubApiClient.make_comment( files=files, format_checks_failed=format_checks_failed, tidy_checks_failed=0, - clang_versions=versions, + clang_versions=clang_versions, len_limit=None, )Also applies to: 35-35
cpp_linter/__init__.py (1)
81-81
: LGTM: Outputting clang versions in feedbackThe change correctly passes the captured clang versions to the
post_feedback
method, ensuring that this information will be included in the feedback. This modification aligns well with the PR objective of displaying the clang version used in thread comments, step summaries, and PR review summaries.Consider updating the docstring of the
post_feedback
method to reflect the newclang_versions
parameter. This will help maintain clear documentation for future developers.tests/capture_tools_output/test_database_path.py (2)
99-99
: Consider adding type annotation forclang_versions
To improve code clarity and catch potential type-related issues early, consider adding a type annotation for the
clang_versions
variable. Based on the AI-generated summary, it seems thatcapture_clang_tools_output
now returns aList[str]
.You could update the line as follows:
clang_versions: List[str] = capture_clang_tools_output(files, args=args)Don't forget to import
List
fromtyping
if it's not already imported.
Line range hint
99-115
: Consider adding an assertion forclang_versions
To ensure that the
capture_clang_tools_output
function is correctly returning the clang version information, it would be beneficial to add an assertion that checks the content ofclang_versions
.You could add an assertion like this after line 99:
assert clang_versions, "Clang versions should not be empty" assert all(isinstance(version, str) for version in clang_versions), "All clang versions should be strings"This will verify that
clang_versions
is not empty and contains only string values.tests/comments/test_comments.py (3)
69-69
: LGTM! Consider addressing file filtering issues.The changes correctly implement the capture and passing of clang tool versions, which aligns with the PR objective. The test structure remains valid, ensuring that the new functionality is properly tested.
However, the PR objectives mention addressing errors in file filtering (
ignore-tidy
andignore-format
). Consider adding or modifying tests to cover these scenarios as well.Would you like assistance in creating additional test cases for the file filtering functionality?
Also applies to: 172-172
Line range hint
1-172
: Consider adding tests for suggestion merging issue.The PR objectives mention an issue with merging suggestions in PR reviews, particularly affecting tests due to the duplication of the demo.cpp file. It would be beneficial to add test cases that cover this scenario to ensure the fix is properly implemented and to prevent regression.
Would you like assistance in drafting test cases for the suggestion merging functionality?
Line range hint
1-172
: Summary: Changes look good, consider addressing additional PR objectives.The implemented changes correctly capture and use the clang tool versions, which is a key objective of this PR. The test structure remains robust and valid.
To fully address all PR objectives:
- Add tests for the file filtering functionality (
ignore-tidy
andignore-format
).- Implement tests for the suggestion merging issue, particularly for cases with duplicated files.
- Consider adding a test to verify that the PR review summary correctly reports tool output, addressing the mentioned inaccuracy.
These additions will ensure comprehensive coverage of all the changes mentioned in the PR objectives.
Would you like assistance in implementing any of these suggested test cases or modifications?
tests/capture_tools_output/test_tools_output.py (2)
70-72
: LGTM with suggestion: ClangVersions integrationThe addition of the
ClangVersions
object and its usage in themake_comment
function aligns with the PR objective. However, setting both format and tidy versions to "x.y.z" seems to be a placeholder.Consider updating these placeholders with actual version information or a method to dynamically fetch the correct versions.
Also applies to: 77-77
Line range hint
1-1
: Suggestion: Add tests for clang version outputWhile the changes align with the PR objective of capturing and outputting clang version information, I noticed that no new tests were added specifically for this functionality.
Consider adding new test cases to verify the correct capture and output of clang version information. This will ensure the new feature is working as expected and prevent potential regressions in the future.
cpp_linter/clang_tools/__init__.py (1)
85-86
: Simplify subprocess output handling withtext=True
By setting
text=True
in thesubprocess.run
call, the output will be returned as a string, eliminating the need to decodestdout
manually.Apply this diff:
-version_out = subprocess.run([cmd, "--version"], capture_output=True, check=True) -output = version_out.stdout.decode() +version_out = subprocess.run([cmd, "--version"], capture_output=True, check=True, text=True) +output = version_out.stdoutcpp_linter/rest_api/__init__.py (1)
181-181
: Ensure Docstring Consistency with Method Parameters.The docstring now includes the
:param clang_versions:
description. Confirm that the docstring accurately reflects the method's parameters and usage.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (11)
- cpp_linter/init.py (1 hunks)
- cpp_linter/clang_tools/init.py (3 hunks)
- cpp_linter/clang_tools/clang_tidy.py (1 hunks)
- cpp_linter/clang_tools/patcher.py (6 hunks)
- cpp_linter/rest_api/init.py (7 hunks)
- cpp_linter/rest_api/github_api.py (8 hunks)
- tests/capture_tools_output/test_database_path.py (2 hunks)
- tests/capture_tools_output/test_tools_output.py (2 hunks)
- tests/comments/test_comments.py (2 hunks)
- tests/reviews/test_pr_review.py (3 hunks)
- tests/test_comment_length.py (3 hunks)
🔇 Additional comments (34)
tests/test_comment_length.py (2)
6-6
: LGTM: Import statement added correctly.The new import for
ClangVersions
is appropriately placed and aligns with the changes in the test function.
Line range hint
1-51
: Verify if additional changes are needed for other PR objectives.The changes in this file successfully implement the display of clang versions in the output. However, the PR objectives mention addressing several other issues:
- Incorrect assignment of file filters (
ignore-tidy
andignore-format
).- Merging of suggestions in PR reviews not ensuring exact file name matches.
- Inaccurate PR review summary for tools not configured to provide PR review suggestions.
These issues don't seem to be addressed in this file.
Could you confirm if these issues are addressed in other files or if additional changes are needed here? Here's a script to check for related changes:
cpp_linter/__init__.py (2)
78-78
: LGTM: Capturing clang versions as intendedThe change correctly implements the feature to capture clang versions used. The variable name
clang_versions
is descriptive and follows Python naming conventions. This modification aligns well with the PR objective of displaying the version number of the clang tools utilized.
Line range hint
1-87
: Verify status of additional issues mentioned in PR objectivesThe changes reviewed successfully implement the capture and output of clang versions. However, the PR objectives also mention addressing several other issues:
- Incorrect assignment of file filters (
ignore-tidy
for clang-format andignore-format
for clang-tidy).- Issues with merging suggestions in PR reviews, particularly affecting tests due to duplicated demo.cpp files.
- Inaccurate PR review summary indicating no reports from tools not configured to provide PR review suggestions.
Could you please confirm if these issues have been addressed in other files not included in this review? If not, additional changes may be required to fully meet the PR objectives.
To help verify this, you can run the following script:
✅ Verification successful
Verify status of additional issues mentioned in PR objectives
The shell scripts have identified that the additional issues mentioned in the PR objectives have been addressed in other parts of the codebase:
Incorrect assignment of file filters (
ignore-tidy
andignore-format
):
- Files:
tests/test_cli_args.py
cpp_linter/cli.py
Issues with merging suggestions in PR reviews:
- Files:
cpp_linter/clang_tools/patcher.py
Inaccurate PR review summary generation:
- Files:
tests/reviews/test_pr_review.py
cpp_linter/rest_api/github_api.py
cpp_linter/clang_tools/clang_tidy.py
These findings confirm that the additional PR objectives have been adequately addressed across the relevant files.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Search for changes related to file filters and PR review logic # Check for changes to file filter logic echo "Checking for file filter changes:" rg --type python -e "ignore-tidy|ignore-format" -g "!cpp_linter/__init__.py" # Check for changes to PR review suggestion merging echo "Checking for PR review suggestion merging changes:" rg --type python -e "merge.*suggestion|suggestion.*merge" -g "!cpp_linter/__init__.py" # Check for changes to PR review summary generation echo "Checking for PR review summary changes:" rg --type python -e "review.*summary|summary.*review" -g "!cpp_linter/__init__.py"Length of output: 622
Script:
#!/bin/bash # Description: Search for changes related to file filters and PR review logic using file extensions # Check for changes to file filter logic echo "Checking for file filter changes:" rg -g "*.py" -e "ignore-tidy|ignore-format" -- '!cpp_linter/__init__.py' # Check for changes to PR review suggestion merging echo "Checking for PR review suggestion merging changes:" rg -g "*.py" -e "merge.*suggestion|suggestion.*merge" -- '!cpp_linter/__init__.py' # Check for changes to PR review summary generation rg -g "*.py" -e "review.*summary|summary.*review" -- '!cpp_linter/__init__.py'Length of output: 620
Script:
#!/bin/bash # Description: Search for changes related to file filters and PR review logic using file extensions with correct exclusion syntax # Check for changes to file filter logic echo "Checking for file filter changes:" rg -g "*.py" -e "ignore-tidy|ignore-format" --glob '!cpp_linter/__init__.py' # Check for changes to PR review suggestion merging echo "Checking for PR review suggestion merging changes:" rg -g "*.py" -e "merge.*suggestion|suggestion.*merge" --glob '!cpp_linter/__init__.py' # Check for changes to PR review summary generation echo "Checking for PR review summary changes:" rg -g "*.py" -e "review.*summary|summary.*review" --glob '!cpp_linter/__init__.py'Length of output: 2087
tests/capture_tools_output/test_database_path.py (2)
99-99
: LGTM: Changes align with PR objectivesThe modifications to capture and pass the clang versions align well with the PR objective of displaying the version number of the clang tools used. This change will help in providing more detailed information in thread comments, step summaries, and PR review summaries.
Also applies to: 115-115
Line range hint
1-115
: Verify if other PR objectives are addressed in separate filesThe changes in this file successfully implement the capturing and passing of clang version information. However, the PR objectives also mention addressing issues related to file filter assignment and suggestion merging. These don't appear to be handled in this file.
Could you confirm if these additional issues are addressed in other files not included in this review? If so, it might be helpful to include those files in the PR description or add comments referencing where these changes can be found.
To help verify this, you can run the following script to search for relevant changes in other files:
This will help ensure all objectives mentioned in the PR are properly addressed.
✅ Verification successful
All PR objectives are addressed across the codebase.
The initial file
tests/capture_tools_output/test_database_path.py
handles capturing clang versions, while other files manage file filter assignments and suggestion merging:
tests/test_cli_args.py
andcpp_linter/cli.py
include configurations forignore-tidy
andignore-format
.cpp_linter/clang_tools/patcher.py
manages the merging of suggestions.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for changes related to file filters and suggestion merging echo "Searching for file filter changes:" rg --type python -i "ignore-tidy|ignore-format" echo "\nSearching for suggestion merging changes:" rg --type python -i "merge.*suggestion|suggestion.*merge"Length of output: 347
Script:
#!/bin/bash # Search for changes related to file filters and suggestion merging echo "Searching for file filter changes:" rg --glob "*.py" -i "ignore-tidy|ignore-format" echo "\nSearching for suggestion merging changes:" rg --glob "*.py" -i "merge.*suggestion|suggestion.*merge"Length of output: 1034
tests/capture_tools_output/test_tools_output.py (2)
19-19
: LGTM: Import added for ClangVersionsThe addition of
ClangVersions
import is consistent with the PR objective to capture and output clang version information.
Line range hint
1-1
: LGTM: Changes align with PR objectivesThe modifications in this file are consistent with the PR objective of capturing and outputting clang version information. The implementation seems correct and doesn't introduce any apparent issues.
To further improve the changes:
- Consider updating the "x.y.z" placeholders with actual version information or a method to dynamically fetch the correct versions.
- Add new test cases to verify the correct capture and output of clang version information.
These suggestions will enhance the robustness and maintainability of the new feature.
cpp_linter/clang_tools/__init__.py (1)
85-85
: Capture both stdout and stderr in subprocess outputSome tools may output version information to
stderr
. To ensure you capture all possible outputs, combinestdout
andstderr
by settingstderr=subprocess.STDOUT
.Consider modifying the subprocess call:
-version_out = subprocess.run([cmd, "--version"], capture_output=True, check=True, text=True) +version_out = subprocess.run( + [cmd, "--version"], + capture_output=True, + check=True, + text=True, + stderr=subprocess.STDOUT +)This change ensures that both
stdout
andstderr
are captured inversion_out.stdout
.tests/reviews/test_pr_review.py (4)
154-155
: Appropriate disabling of clang-tidy checks whentidy_review
is FalseSetting
args.tidy_checks
to "-*
" whentidy_review
isFalse
effectively disables all clang-tidy checks. This ensures that clang-tidy does not run when a tidy review is not requested, aligning with the intended behavior.
170-170
: Captureclang_versions
for inclusion in feedbackBy capturing
clang_versions
fromcapture_clang_tools_output
, you're now able to pass the clang version information togh_client.post_feedback
. This change supports the PR objective of displaying the clang version used in the feedback, enhancing transparency.
174-178
: Correct assertions based ontidy_review
flagThe updated assertions accurately verify the presence or absence of
tidy_advice
depending on the value oftidy_review
. Specifically:
- When
tidy_review
isTrue
, it asserts thattidy_advice
exists and its length does not exceed the number of files.- When
tidy_review
isFalse
, it asserts thattidy_advice
does not exist.This ensures that the test behavior aligns with the expected outcomes for the tidy review process.
197-197
: Updategh_client.post_feedback
to includeclang_versions
Passing
clang_versions
togh_client.post_feedback
necessitates updating the method signature ofpost_feedback
to accept this new parameter. Ensure that thepost_feedback
method inGithubApiClient
is modified accordingly to handleclang_versions
.cpp_linter/clang_tools/patcher.py (4)
53-56
: Initialize 'tool_total' with 'None' values to represent unused toolsThe change to initialize
self.tool_total
withNone
and updating its type toDict[str, Optional[int]]
appropriately allows for tools that were not requested to be indicated asNone
. This enhances the clarity of whether a tool was used in the review process.
77-78
: Enhance merging logic by including 'file_name' in conditionAdding
known.file_name == suggestion.file_name
to the merge condition inmerge_similar_suggestion
ensures that only suggestions from the same file are merged. This prevents unintended merging of suggestions from different files, improving the accuracy of the merge logic.
85-90
: Update method signature to include tool version parametersThe addition of
tidy_version
andformat_version
parameters toserialize_to_github_payload
allows the inclusion of version information in the serialized GitHub payload. This enhancement provides better context in the summaries generated for the PR reviews.
Line range hint
186-217
: Verify the handling of 'tool_total' when tools are not usedWhen
review_comments.tool_total[tool_name]
isNone
, initializingtool_total
to0
and incrementing it may unintentionally indicate that the tool was used. Please ensure that this logic accurately reflects whether a tool was utilized and thattool_total
correctly represents the number of concerns per tool.To verify the handling of
tool_total
, consider reviewing the usage oftool_total
throughout the codebase to confirm thatNone
values are appropriately managed and do not lead to misleading summaries.cpp_linter/clang_tools/clang_tidy.py (1)
136-139
: Ensure Suggestions Are Merged Only for the Same FileThe added condition
known.file_name == suggestion.file_name
ensures that suggestions are merged only when they belong to the same file. This prevents cross-file suggestion conflicts and enhances the accuracy of the suggestion handling logic.cpp_linter/rest_api/github_api.py (8)
28-28
: ImportingClangVersions
fromclang_tools
The addition of the
ClangVersions
import is necessary for passing Clang tool version information throughout the API client.
191-191
: Updatingpost_feedback
method signature to includeclang_versions
Adding
clang_versions: ClangVersions
as a parameter allows the method to include Clang version information in the feedback, enhancing the context provided to users.
203-203
: Passingclang_versions
tomake_comment
inpost_feedback
By passing
clang_versions
tomake_comment
, you ensure that the Clang version details are included in the generated comments, providing clearer feedback.
231-231
: Ensuringclang_versions
is passed when reconstructing commentsIn cases where the comment needs to be regenerated due to length constraints, passing
clang_versions
maintains consistency in the feedback content.
260-260
: Passingclang_versions
topost_review
Including
clang_versions
when callingpost_review
allows Clang tool version information to be integrated into the review process, improving transparency.
396-396
: Updatingpost_review
method signature to includeclang_versions
Adding
clang_versions: ClangVersions
as a parameter enables the method to utilize Clang version information when posting reviews.
428-432
: Passing Clang versions toserialize_to_github_payload
By providing
tidy_version
andformat_version
fromclang_versions
, you ensure that the version details are included in the serialized payload for GitHub, enhancing the review comments.
436-436
: Correctly determining the review event based on tool totalsThe condition accurately checks if there are any issues reported by summing the integer values in
review_comments.tool_total
. This ensures the appropriate review event (REQUEST_CHANGES
orAPPROVE
) is selected based on the presence of tool findings.cpp_linter/rest_api/__init__.py (8)
15-15
: Add Missing Import forClangVersions
.The import statement for
ClangVersions
is added, which suggests that this class or function is used elsewhere in the code. Ensure thatClangVersions
is correctly defined and imported from the appropriate module.
226-228
: Correct Formatting of the Clang Format Version in the Comment.The
comment
string now includes the version information. Check that the version is correctly formatted and displayed when the version is provided.
252-254
: Correct Formatting of the Clang Tidy Version in the Comment.The
comment
string in_make_tidy_comment
now includes the version information. Verify that the version displays correctly in the generated comments.
205-205
: Pass Correct Clang Format Version to_make_format_comment
.The
version
parameter is passed asclang_versions.format
. Ensure thatclang_versions.format
correctly retrieves the clang-format version and that it's properly formatted as a string.Run the following script to verify the usage of
clang_versions.format
:#!/bin/bash # Description: Check where `clang_versions.format` is set and its type. # Search for assignments to `clang_versions.format`. rg --type py 'clang_versions\.format\s*='
249-249
: Update Method Signature of_make_tidy_comment
to Includeversion
.The
_make_tidy_comment
method now includes an optionalversion
parameter. Ensure that any subclasses overriding this method are updated accordingly.Run the following script to find overrides of
_make_tidy_comment
:#!/bin/bash # Description: Find any subclasses that override `_make_tidy_comment`. # Search for definitions of `_make_tidy_comment` in subclass files. rg --type py 'def _make_tidy_comment\('
290-290
:⚠️ Potential issueUpdate Method Signature of
post_feedback
to Includeclang_versions
.The
post_feedback
method now requiresclang_versions
. Ensure that all calls to this method pass the required parameter and that subclasses implement this change.Apply this diff to update method calls:
-def post_feedback( - self, - files: List[FileObj], - args: Args, -): +def post_feedback( + self, + files: List[FileObj], + args: Args, + clang_versions: ClangVersions, +):Run the following script to find all calls to
post_feedback
and ensure they are updated:#!/bin/bash # Description: Verify that all calls to `post_feedback` include `clang_versions`. # Search for calls to `post_feedback` in Python files. rg --type py --word-regexp -A 2 'post_feedback\('Would you like assistance in updating the method calls throughout the codebase?
212-212
: Pass Correct Clang Tidy Version to_make_tidy_comment
.Similarly, the
version
parameter is passed asclang_versions.tidy
. Verify thatclang_versions.tidy
correctly retrieves the clang-tidy version and is properly formatted.Run the following script to verify the usage of
clang_versions.tidy
:✅ Verification successful
Clang Tidy Version Passed Correctly
Verified that
clang_versions.tidy
is properly assigned and formatted as a version string. No issues found with its usage in_make_tidy_comment
.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check where `clang_versions.tidy` is set and its type. # Search for assignments to `clang_versions.tidy`. rg --type py 'clang_versions\.tidy\s*='Length of output: 480
Script:
#!/bin/bash # Description: Locate definitions and imports of 'clang_versions' to understand the structure of 'tidy'. # Search for assignments to 'clang_versions' rg --type py 'clang_versions\s*=' # Search for import statements involving 'clang_versions' rg --type py 'import .*clang_versions' || rg --type py 'from .* import .*clang_versions' # If 'clang_versions' is a class or function, extract its definition ast-grep --lang python --pattern $'class clang_versions { $$$ }' || ast-grep --lang python --pattern $'def clang_versions($$$) { $$$ }' # Optionally, list all attributes of 'clang_versions' if it's a class or a module rg --type py 'clang_versions\.'Length of output: 3124
223-223
: Update Method Signature of_make_format_comment
to Includeversion
.The
_make_format_comment
method now accepts an optionalversion
parameter. Ensure that this change does not break any overrides or implementations in subclasses.Run the following script to find overrides of
_make_format_comment
:✅ Verification successful
Verification Successful: No Overrides Found for
_make_format_comment
.
The update to include theversion
parameter in the_make_format_comment
method does not break any overrides or implementations in subclasses.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Find any subclasses that override `_make_format_comment`. # Search for definitions of `_make_format_comment` in subclass files. rg --type py 'def _make_format_comment\('Length of output: 480
Script:
#!/bin/bash # Description: Corrected script to find any subclasses that override `_make_format_comment`. # Search for definitions of `_make_format_comment` in Python files. rg --type py 'def _make_format_comment\('Length of output: 105
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (6)
tests/capture_tools_output/test_database_path.py (2)
99-99
: LGTM: Capturing clang versions in test_ninja_databaseThe modification to capture the return value of
capture_clang_tools_output
asclang_versions
is consistent with the PR objectives and the updated import statement. The use of type annotationClangVersions
is commendable for improved code readability and type checking.Consider adding an assertion to verify that
clang_versions
is not empty orNone
to ensure the function call succeeded in capturing version information.
115-115
: LGTM: Including clang versions in GithubApiClient.make_commentThe addition of
clang_versions
as an argument toGithubApiClient.make_comment
is a positive change that aligns with the PR objectives. This modification ensures that the captured clang version information is included in the generated comment.For consistency with other arguments, consider moving
clang_versions
to be on the same line as the method call, if line length permits. This would improve readability and maintain a consistent style throughout the function call.cpp_linter/clang_tools/__init__.py (2)
83-96
: Consider adding unit tests for_capture_tool_version
The new function
_capture_tool_version
is crucial for capturing the versions of the clang tools. Adding unit tests would ensure its reliability, especially when dealing with different version output formats or handling exceptions.Would you like assistance in writing these unit tests or opening a GitHub issue to track this task?
93-93
: Remove unnecessary use ofcast
Since
matched.group(1)
returns a string when a match is found, the use ofcast
is unnecessary here.Apply this diff:
-ver = cast(str, matched.group(1)) +ver = matched.group(1)cpp_linter/clang_tools/patcher.py (2)
94-95
: Correct parameter descriptions to match singular parameter namesThe descriptions for
tidy_version
andformat_version
use plural phrasing ("version numbers"), but the parameters represent a single version number each. Please update the descriptions for clarity and consistency.Apply this diff to adjust the parameter descriptions:
- :param tidy_version: The version numbers of the clang-tidy used. - :param format_version: The version numbers of the clang-format used. + :param tidy_version: The version number of the clang-tidy used. + :param format_version: The version number of the clang-format used.
Line range hint
186-217
: HandleNone
values when updatingtool_total
When
review_comments.tool_total[tool_name]
isNone
, it indicates that the tool was not used. Incrementingtool_total
in this case may overwrite theNone
value. Consider adding a check to ensure that you only updatetool_total
when the tool is used.Apply this diff to address the issue:
assert tool_name in review_comments.tool_total - tool_total = review_comments.tool_total[tool_name] or 0 + if review_comments.tool_total[tool_name] is not None: + tool_total = review_comments.tool_total[tool_name] or 0 for hunk in patch.hunks: tool_total += 1 if summary_only: continue # ...rest of the code... + if review_comments.tool_total[tool_name] is not None: review_comments.tool_total[tool_name] = tool_total
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (6)
- cpp_linter/clang_tools/init.py (3 hunks)
- cpp_linter/clang_tools/patcher.py (6 hunks)
- cpp_linter/rest_api/init.py (7 hunks)
- cpp_linter/rest_api/github_api.py (8 hunks)
- tests/capture_tools_output/test_database_path.py (3 hunks)
- tests/test_comment_length.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- cpp_linter/rest_api/github_api.py
- tests/test_comment_length.py
🧰 Additional context used
📓 Learnings (1)
cpp_linter/rest_api/__init__.py (1)
Learnt from: 2bndy5 PR: cpp-linter/cpp-linter#124 File: cpp_linter/rest_api/__init__.py:172-172 Timestamp: 2024-10-05T05:55:32.758Z Learning: In `tests/capture_tools_output/test_tools_output.py`, when test functions call alias functions defined in the same module that correctly include required parameters, it is acceptable even if the parameters are not explicitly passed in the test calls.
🔇 Additional comments (14)
tests/capture_tools_output/test_database_path.py (2)
14-14
: LGTM: Import statement updated to include ClangVersionsThe addition of
ClangVersions
to the import statement aligns with the PR objective to capture and output the clang version used. This change suggests that thecapture_clang_tools_output
function now returns version information, which is a positive step towards improving the tool's output.
Line range hint
1-124
: Overall assessment: Changes align well with PR objectivesThe modifications in this file successfully implement the capture and output of clang version information, addressing the main objective of the PR. The changes are consistent and well-integrated into the existing test structure.
Key points:
- The import statement now includes
ClangVersions
, enabling type checking for the captured version information.- The
test_ninja_database
function now captures and passes clang version data to theGithubApiClient.make_comment
method.- Indentation issues mentioned in the PR objectives appear to have been resolved.
These changes contribute to improving the quality and informativeness of the tool's output, particularly in thread comments, step summaries, and PR review summaries.
To ensure that the changes are consistent across the codebase, please run the following verification script:
This script will help ensure that the changes related to clang version capture and usage are consistently applied across the project.
✅ Verification successful
Verification Successful: Consistent usage of
ClangVersions
confirmedAll relevant files correctly import and utilize
ClangVersions
andclang_versions
as intended. No inconsistencies were found in the usage ofGithubApiClient.make_comment
across the codebase.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify consistent usage of ClangVersions and clang version capture # Test 1: Check for consistent import of ClangVersions echo "Checking for consistent import of ClangVersions:" rg --type python "from cpp_linter\.clang_tools import .*ClangVersions.*" # Test 2: Check for consistent usage of capture_clang_tools_output with version capture echo "\nChecking for consistent usage of capture_clang_tools_output with version capture:" rg --type python "clang_versions.*=.*capture_clang_tools_output\(" # Test 3: Check for consistent usage of clang_versions in GithubApiClient.make_comment echo "\nChecking for consistent usage of clang_versions in GithubApiClient.make_comment:" rg --type python "GithubApiClient\.make_comment\(.*clang_versions.*\)"Length of output: 768
Script:
#!/bin/bash # Description: Verify consistent usage of ClangVersions and clang version capture with corrected file type # Test 1: Check for consistent import of ClangVersions echo "Checking for consistent import of ClangVersions:" rg --type py "from cpp_linter\.clang_tools import .*ClangVersions.*" # Test 2: Check for consistent usage of capture_clang_tools_output with version capture echo "\nChecking for consistent usage of capture_clang_tools_output with version capture:" rg --type py "clang_versions.*=.*capture_clang_tools_output\(" # Test 3: Check for consistent usage of clang_versions in GithubApiClient.make_comment echo "\nChecking for consistent usage of clang_versions in GithubApiClient.make_comment:" rg --type py "GithubApiClient\.make_comment\(.*clang_versions.*\)"Length of output: 1417
cpp_linter/rest_api/__init__.py (7)
15-15
: LGTM: Import statement for ClangVersions added.The new import statement for
ClangVersions
is correctly placed and uses the appropriate relative import syntax, consistent with the existing code style.
172-173
: LGTM: Updated make_comment method signature.The addition of the
clang_versions
parameter aligns with the PR objectives. Makinglen_limit
optional with a default value ofNone
is a good practice for maintaining backward compatibility.
181-181
: LGTM: Updated make_comment method docstring.The docstring has been appropriately updated to include a description of the new
clang_versions
parameter. The description is concise and clear.
205-205
: LGTM: Updated _make_format_comment method call.The
version
parameter has been correctly added to the_make_format_comment
method call, usingclang_versions.format
. This is consistent with the changes made to the method signature and aligns with the PR objectives.
212-212
: LGTM: Updated _make_tidy_comment method call.The
version
parameter has been correctly added to the_make_tidy_comment
method call, usingclang_versions.tidy
. This is consistent with the changes made to the method signature and aligns with the PR objectives.
290-290
: LGTM: Updated post_feedback method signature and docstring.The
clang_versions
parameter has been correctly added to thepost_feedback
method signature, and the docstring has been appropriately updated to include a description of the new parameter. These changes are consistent with the PR objectives.Also applies to: 296-296
15-15
: Overall assessment: Changes successfully implement clang version reporting.The modifications to this file consistently implement the addition of clang version information across relevant methods. The changes include:
- Importing the
ClangVersions
class.- Updating method signatures to include
clang_versions
orversion
parameters.- Modifying method calls to pass version information.
- Updating docstrings to reflect the new parameters.
These changes align well with the PR objectives and will enable the display of clang tool versions in the linter's output. The implementation is consistent and well-documented throughout the file.
Also applies to: 172-173, 181-181, 205-205, 212-212, 290-290, 296-296
cpp_linter/clang_tools/__init__.py (2)
Line range hint
104-179
: Updates tocapture_clang_tools_output
are appropriateThe modifications to
capture_clang_tools_output
effectively capture and return the versions of the clang tools using theClangVersions
class, aligning with the PR objectives to output the versions used.
80-80
: Verify thatVERSION_PATTERN
handles all version output formatsEnsure that the
VERSION_PATTERN
regular expression matches all possible version output formats fromclang-format --version
andclang-tidy --version
, as outputs can vary between versions or platforms.Run the following script to test the regex against actual version outputs:
cpp_linter/clang_tools/patcher.py (3)
53-56
: Initializetool_total
withNone
to represent unused toolsThe change correctly updates
self.tool_total
to allowNone
values, indicating that a review was not requested from the corresponding tool.
77-78
: Addfile_name
check when merging suggestionsIncluding
known.file_name == suggestion.file_name
in themerge_similar_suggestion
method ensures that suggestions are only merged when they pertain to the same file. This prevents incorrect merging of suggestions from different files.
85-90
: Update method to include tool version parametersAdding
tidy_version
andformat_version
as parameters to theserialize_to_github_payload
method enhances its functionality by allowing it to include version information of the clang tools in the serialized output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (4)
cpp_linter/clang_tools/__init__.py (4)
80-80
: LGTM: Well-defined regex pattern for version extraction.The
VERSION_PATTERN
is well-defined for capturing version numbers. Consider adding word boundaries\b
at the start and end of the pattern to ensure it doesn't match partial words:VERSION_PATTERN = re.compile(r"\bversion\s(\d+\.\d+\.\d+)\b")This change would prevent matching something like "subversion 1.2.3" or "version 1.2.3suffix".
83-95
: LGTM: Well-implemented version capture function.The
_capture_tool_version
function is well-implemented, with proper subprocess handling, version extraction, and logging. Consider adding a try-except block to handle potentialsubprocess.CalledProcessError
:def _capture_tool_version(cmd: str) -> str: """Get version number from output for executable used.""" try: version_out = subprocess.run( [cmd, "--version"], capture_output=True, check=True, text=True ) except subprocess.CalledProcessError as e: raise RuntimeError(f"Failed to execute `{cmd} --version`: {e}") from e matched = VERSION_PATTERN.search(version_out.stdout) if matched is None: raise RuntimeError( f"Failed to get version numbers from `{cmd} --version` output" ) ver = cast(str, matched.group(1)) logger.info("`%s --version`: %s", cmd, ver) return verThis change would provide more specific error information if the command execution fails.
98-101
: LGTM: Good encapsulation of version information.The
ClangVersions
class provides a clean way to encapsulate version information for clang tools. Consider using Python 3.10+ syntax for optional attributes to improve type hinting:from typing import Optional class ClangVersions: def __init__(self) -> None: self.tidy: str | None = None self.format: str | None = NoneThis change makes the type hints more explicit and future-proof.
104-104
: LGTM: Well-integrated version capture functionality.The changes to
capture_clang_tools_output
effectively integrate the new version capture functionality. The error handling for missing executables is appropriate. For consistency, consider moving theFileNotFoundError
checks right after theassemble_version_exec
calls:if args.style: format_cmd = assemble_version_exec("clang-format", args.version) if format_cmd is None: raise FileNotFoundError("clang-format executable was not found") clang_versions.format = _capture_tool_version(format_cmd) format_filter = FormatFileFilter( extensions=args.extensions, ignore_value=args.ignore_format, ) if args.tidy_checks != "-*": tidy_cmd = assemble_version_exec("clang-tidy", args.version) if tidy_cmd is None: raise FileNotFoundError("clang-tidy executable was not found") clang_versions.tidy = _capture_tool_version(tidy_cmd) tidy_filter = TidyFileFilter( extensions=args.extensions, ignore_value=args.ignore_tidy, )This change improves the flow and readability of the code.
Also applies to: 114-114, 117-119, 127-129, 179-179
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (6)
- cpp_linter/clang_tools/init.py (3 hunks)
- cpp_linter/clang_tools/patcher.py (6 hunks)
- cpp_linter/rest_api/init.py (7 hunks)
- cpp_linter/rest_api/github_api.py (8 hunks)
- tests/capture_tools_output/test_database_path.py (3 hunks)
- tests/test_comment_length.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
- cpp_linter/clang_tools/patcher.py
- cpp_linter/rest_api/init.py
- cpp_linter/rest_api/github_api.py
- tests/capture_tools_output/test_database_path.py
- tests/test_comment_length.py
🔇 Additional comments (2)
cpp_linter/clang_tools/__init__.py (2)
4-4
: LGTM: Import changes are appropriate.The addition of the
re
module import and the reorganization of thetyping
imports are appropriate for the new functionality introduced in this file.Also applies to: 6-6
Line range hint
1-179
: Overall, excellent improvements to version handling and error management.The changes introduced in this file significantly enhance the version capture and management for clang tools. The new
ClangVersions
class,_capture_tool_version
function, and modifications tocapture_clang_tools_output
are well-implemented and integrated.Key improvements:
- Robust version extraction using regex.
- Clear error handling for missing executables.
- Encapsulation of version information in
ClangVersions
class.- Consistent integration of version capture in the main workflow.
The minor suggestions provided in the review comments will further refine the code's robustness and readability. Great work on enhancing the functionality of the cpp-linter tool!
This idea was brought up in discussion #123
Shows the clang tools' version number which was used to the generated the feedback.
Affects thread-comments, step-summary, and PR review summary.
I also fixed some errors that I noticed when verifying test results:
ignore-tidy
was used for clang-format andignore-format
was used for clang-tidy..cpp
file and again as a.c
file).Summary by CodeRabbit
Release Notes
New Features
ClangVersions
added to encapsulate version details for clang tools.Bug Fixes
Documentation
Chores