Skip to content

Refactor creating PR review comments #117

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

Merged
merged 12 commits into from
Sep 9, 2024
Merged

Refactor creating PR review comments #117

merged 12 commits into from
Sep 9, 2024

Conversation

2bndy5
Copy link
Contributor

@2bndy5 2bndy5 commented Sep 5, 2024

This abstracts the creation of PR review comments into its own module.

These changes are refactored from initial proposal in #115 but without the new dependency and changes from #116.

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Sep 5, 2024
@2bndy5 2bndy5 added the enhancement New feature or request label Sep 5, 2024
Copy link

codecov bot commented Sep 5, 2024

Codecov Report

Attention: Patch coverage is 98.72611% with 2 lines in your changes missing coverage. Please review.

Project coverage is 99.88%. Comparing base (854c662) to head (3bb8f33).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
cpp_linter/clang_tools/clang_tidy.py 94.59% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##              main     #117      +/-   ##
===========================================
- Coverage   100.00%   99.88%   -0.12%     
===========================================
  Files           23       24       +1     
  Lines         1732     1798      +66     
===========================================
+ Hits          1732     1796      +64     
- Misses           0        2       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@2bndy5
Copy link
Contributor Author

2bndy5 commented Sep 5, 2024

Everything seems correct in the test PR.

@2bndy5
Copy link
Contributor Author

2bndy5 commented Sep 5, 2024

I've got a new idea to merge the suggestions from both tools... Instead of each tool posting a separate review comment, I might be able to merge the comments from both tools if their line numbers match up. This idea is different from merging the patches from each tool.

@2bndy5 2bndy5 force-pushed the refactor-pr-reviews branch from ece5ac5 to b7146b6 Compare September 5, 2024 09:06
@shenxianpeng
Copy link
Contributor

I've got a new idea to merge the suggestions from both tools...

Good idea! Just to confirm, if the user only uses clang-format or clang-tidy, they can still work.

@2bndy5
Copy link
Contributor Author

2bndy5 commented Sep 5, 2024

if the user only uses clang-format or clang-tidy, they can still work.

Yes

@2bndy5
Copy link
Contributor Author

2bndy5 commented Sep 5, 2024

Just to illustrate these changes:

data structures (inheritence)

graph TD
  FileObj -- contains --> TidyAdvice -- inherits from --> PatchMixin
  FileObj -- contains --> FormatAdvice -- inherits from --> PatchMixin
Loading

review comment dataflow

Changes are captured

Note

The PatchMixin.patched member is specific to either TidyAdvice or FormatAdvice (as described in above inheritance graph).

flowchart TD
  cachePatch["save suggested changes
  to PatchMixin.patched"]
  capTidy["`run_clang_tidy()`"] --> cachePatch
  capFormat["`run_clang_format()`"] --> cachePatch
Loading

Review comments are created

Starting from GithubApiClient.post_feedback() which will appropriately call GithubApiClient.post_review().

Note

The PatchMixin.get_suggestions_from_patch() method is implemented by default, but TidyAdvice extends the definition for behavior specific to clang-tidy.

%%{init: {"flowchart": {"htmlLabels": false}} }%%
flowchart TD
  postReviews["post_reviews()"] --> getComments["create_review_comments()"]
  subgraph for each file in files
    getFmtSuggestion["FormatAdvice
    .get_suggestions_
    from_patch()."]
    getTidySuggestion["TidyAdvice
    .get_suggestions_
    from_patch()."]
    getFmtSuggestion o-- Here we merge suggestions with existing comments --o getTidySuggestion
  end
  serialize["serialize comments
  into JSON payload
  (review summary created here)"] --> post["post new review"]

  getComments -- if format-review is true --> getFmtSuggestion --> serialize
  getComments -- if tidy-review is true --> getTidySuggestion --> serialize
Loading

@2bndy5 2bndy5 force-pushed the refactor-pr-reviews branch from 550114e to e807f6e Compare September 5, 2024 21:26
@2bndy5
Copy link
Contributor Author

2bndy5 commented Sep 5, 2024

I've got a new idea to merge the suggestions from both tools...

Success! 🎉

There's still some edge cases where the suggestion comments cannot be merged, but I'm happier with the new results (compared to old/stable results).

There's also a couple lines that get missed in coverage. This is because the test conditions do not include a scenario where a clang-tidy diagnostic comment (with no suggested fix -- see below) cannot be merged into existing review comments.
image
I'm ok with the loss of coverage in this situation (for now).

@shenxianpeng
Copy link
Contributor

The diagram and the final picture look amazing!

@2bndy5
Copy link
Contributor Author

2bndy5 commented Sep 6, 2024

I realized I keep using dense/complex sentences (with double negatives), and the code is not super simple. That's why I created the graphs and picture.

@2bndy5 2bndy5 force-pushed the refactor-pr-reviews branch 2 times, most recently from 84c23f1 to 978b45f Compare September 8, 2024 21:42
@2bndy5 2bndy5 force-pushed the refactor-pr-reviews branch from 978b45f to 3bb8f33 Compare September 8, 2024 22:15
@2bndy5 2bndy5 merged commit 46f97d0 into main Sep 9, 2024
108 checks passed
@2bndy5 2bndy5 deleted the refactor-pr-reviews branch September 9, 2024 07:56
@shenxianpeng
Copy link
Contributor

I feel v1.10.1 might be a minor release insead of patch. It's amazing, no matter what. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants