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

Filter file comparisons by flags #129

Merged
merged 4 commits into from
Sep 14, 2023

Conversation

adrian-codecov
Copy link
Contributor

Purpose/Motivation

We need to filter out file comparisons by flags. This PR introduces that logic

What does this PR do?

  • Adjusts impacted files to filter out those without relevant flags
  • Adds param to gql to add flags
  • Adds tests
  • Add readonly report to head_report in Comparison class

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

@@ -701,7 +704,9 @@ def base_report(self):
@cached_property
def head_report(self):
try:
report = report_service.build_report_from_commit(self.head_commit)
report = report_service.build_report_from_commit(
self.head_commit, report_class=ReadOnlyReport
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be unsafe?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the API does any report modification so this seems like a good move to me.

parameter = filters.get("ordering", {}).get("parameter")
direction = filters.get("ordering", {}).get("direction")
if parameter and direction:
impacted_files = self.sort_impacted_files(
impacted_files, parameter, direction
)
flags = filters.get("flags", [])
if flags and comparison:
head_commit_report = comparison.head_report
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brought the comparison all the way down here to only compute the head_report if the flags are provided

@codecov
Copy link

codecov bot commented Sep 13, 2023

Codecov Report

Merging #129 (e71b2e4) into main (59e53ab) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##            main    #129     +/-   ##
=======================================
+ Coverage   95.34   95.35   +0.01     
=======================================
  Files        702     702             
  Lines      14946   14958     +12     
=======================================
+ Hits       14250   14262     +12     
  Misses       696     696             
Flag Coverage Δ
unit 95.46% <100.00%> (-0.07%) ⬇️
unit-latest-uploader 95.46% <100.00%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
compare/commands/compare/compare.py 100.00% <100.00%> (ø)
...mmands/compare/interactors/fetch_impacted_files.py 98.24% <100.00%> (+0.28%) ⬆️
graphql_api/types/commit/commit.py 100.00% <100.00%> (ø)
graphql_api/types/comparison/comparison.py 100.00% <100.00%> (ø)
services/comparison.py 99.33% <100.00%> (+<0.01%) ⬆️

@codecov-staging
Copy link

codecov-staging bot commented Sep 13, 2023

Codecov Report

Patch coverage is 100.00% of modified lines.

❗ Current head c54acca differs from pull request most recent head e71b2e4. Consider uploading reports for the commit e71b2e4 to get more accurate results

Files Changed Coverage
compare/commands/compare/compare.py 100.00%
...mmands/compare/interactors/fetch_impacted_files.py 100.00%
graphql_api/types/commit/commit.py 100.00%
graphql_api/types/comparison/comparison.py 100.00%
services/comparison.py 100.00%

📢 Thoughts on this report? Let us know!.

def fetch_impacted_files(
self,
comparison_report: ComparisonReport,
comparison: Union[PullRequestComparison, Comparison],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just Comparison is fine here since PullRequestComparison inherits from Comparison and we're not using anything specific to PullRequestComparison.

def _apply_filters(
self,
impacted_files: Optional[List[ImpactedFile]],
comparison: Union[PullRequestComparison, Comparison],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here - can just be Comparison

files = files_belonging_to_flags(
commit_report=head_commit_report, flags=flags
)
impacted_files = list(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might read a little easier:

impacted_files = [
    file
    for file in impacted_files
    if file.head_name in files
]

@@ -701,7 +704,9 @@ def base_report(self):
@cached_property
def head_report(self):
try:
report = report_service.build_report_from_commit(self.head_commit)
report = report_service.build_report_from_commit(
self.head_commit, report_class=ReadOnlyReport
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the API does any report modification so this seems like a good move to me.

@adrian-codecov adrian-codecov merged commit 1941ee7 into main Sep 14, 2023
18 of 19 checks passed
@adrian-codecov adrian-codecov deleted the 453-add-flags-filter-for-comparisons branch September 14, 2023 00:26
scott-codecov added a commit that referenced this pull request Sep 14, 2023
* main: (74 commits)
  Fix indentation error (#133)
  Add cache cleanup (#130)
  Feature/lint pre commit (#134)
  feat: trigger label analysis task after update (#131)
  Filter file comparisons by flags (#129)
  chore: Remove hard-coded dev BB redirect URL (#132)
  feat: Validate OIDC ID token during Sentry OAuth flow (#52)
  Adding beginnings of GHA CI (#127)
  feat: Filter flags by flags for pathContents (#128)
  Create checkbox in Owner form in Django admin to set uses_invoice (#109)
  build(deps): bump certifi from 2020.6.20 to 2023.7.22 (#32)
  Feature/no compile (#126)
  Bump django from 4.2.2 to 4.2.3 (#42)
  Don't compile since source is available (#106)
  feat: Add firstPull resolver to GraphQL pull type (#108)
  chore: Upgrade requests and redis dependencies (#124)
  Update LICENSE (#122)
  Attempt migration (#121)
  359 adjust monthly uploads for trialled customers (#119)
  Add changes for monthly uploads to account for trialing customer (#101)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants