Skip to content

Commit

Permalink
add require_bundle_changes to yaml (#226)
Browse files Browse the repository at this point in the history
* add require_bundle_changes to yaml

* add property to calculate total_size_delta for BA comparison
  • Loading branch information
adrian-codecov authored May 24, 2024
1 parent ae6e12f commit 4b51e8a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions shared/bundle_analysis/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ def bundle_changes(self) -> Iterator[BundleChange]:
size_delta=-base_bundle_report.total_size(),
)

@property
def total_size_delta(self) -> int:
return sum(bundle_change.size_delta for bundle_change in self.bundle_changes())

def bundle_comparison(self, bundle_name: str) -> BundleComparison:
"""
More detailed comparison (about asset changes) for a particular bundle that
Expand Down
1 change: 1 addition & 0 deletions shared/validation/user_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@
"nullable": True,
},
"require_changes": {"type": "boolean"},
"require_bundle_changes": {"type": "boolean"},
"require_base": {"type": "boolean"},
"require_head": {"type": "boolean"},
"show_critical_paths": {"type": "boolean"},
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/bundle_analysis/test_bundle_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,35 @@ def test_bundle_analysis_comparison():

with pytest.raises(MissingBundleError):
comparison.bundle_comparison("new")


def test_bundle_analysis_total_size_delta():
loader = BundleAnalysisReportLoader(
storage_service=MemoryStorageService({}),
repo_key="testing",
)

comparison = BundleAnalysisComparison(
loader=loader,
base_report_key="base-report",
head_report_key="head-report",
)

base_report = BundleAnalysisReport()
base_report.ingest(base_report_bundle_stats_path)

old_bundle = Bundle(name="old")
base_report.db_session.add(old_bundle)
base_report.db_session.commit()

head_report = BundleAnalysisReport()
head_report.ingest(head_report_bundle_stats_path)

new_bundle = Bundle(name="new")
head_report.db_session.add(new_bundle)
head_report.db_session.commit()

loader.save(base_report, "base-report")
loader.save(head_report, "head-report")

assert comparison.total_size_delta == 1100

0 comments on commit 4b51e8a

Please sign in to comment.