Skip to content

Commit

Permalink
Bundle Analysis: associate past assets to current parsed bundle (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
JerrySentry authored Jun 4, 2024
1 parent 4fe84f0 commit 13a87ce
Show file tree
Hide file tree
Showing 26 changed files with 983 additions and 655 deletions.
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
https://github.com/codecov/shared/archive/bef1d469b14f19d530c60993872045ce538dd3aa.tar.gz#egg=shared
https://github.com/codecov/shared/archive/57e53e8dee5cc499a72ece349a66f4174c8af236.tar.gz#egg=shared
https://github.com/codecov/opentelem-python/archive/refs/tags/v0.0.4a1.tar.gz#egg=codecovopentelem
https://github.com/codecov/test-results-parser/archive/5515e960d5d38881036e9127f86320efca649f13.tar.gz#egg=test-results-parser
boto3>=1.34
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ sentry-sdk==1.40.0
# via
# -r requirements.in
# shared
shared @ https://github.com/codecov/shared/archive/bef1d469b14f19d530c60993872045ce538dd3aa.tar.gz
shared @ https://github.com/codecov/shared/archive/57e53e8dee5cc499a72ece349a66f4174c8af236.tar.gz
# via -r requirements.in
six==1.16.0
# via
Expand Down
2 changes: 1 addition & 1 deletion services/ai_pr_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ async def perform(self) -> Optional[int]:
if len(self.review_ids) > 0:
comments_to_update = []
async for comment in self.pull_wrapper.fetch_review_comments():
if not (comment["pull_request_review_id"] in self.review_ids):
if comment["pull_request_review_id"] not in self.review_ids:
continue

line_info = LineInfo(
Expand Down
40 changes: 40 additions & 0 deletions services/bundle_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,41 @@ async def initialize_and_save_report(
db_session.flush()
return commit_report

def _previous_bundle_analysis_report(
self, bundle_loader: BundleAnalysisReportLoader, commit: Commit
) -> Optional[BundleAnalysisReport]:
"""
Helper function to fetch the parent commit's BAR for the purpose of matching previous bundle's
Assets to the current one being parsed.
"""
if commit.parent_commit_id is None:
return None

db_session = commit.get_db_session()
parent_commit = (
db_session.query(Commit)
.filter_by(
commitid=commit.parent_commit_id,
repository=commit.repository,
)
.first()
)
if parent_commit is None:
return None

parent_commit_report = (
db_session.query(CommitReport)
.filter_by(
commit_id=parent_commit.id_,
report_type=ReportType.BUNDLE_ANALYSIS.value,
)
.first()
)
if parent_commit_report is None:
return None

return bundle_loader.load(parent_commit_report.external_id)

@sentry_sdk.trace
def process_upload(self, commit: Commit, upload: Upload) -> ProcessingResult:
"""
Expand Down Expand Up @@ -151,6 +186,11 @@ def process_upload(self, commit: Commit, upload: Upload) -> ProcessingResult:
# load the downloaded data into the bundle report
session_id = bundle_report.ingest(local_path)

# Retrieve previous commit's BAR and associate past Assets
prev_bar = self._previous_bundle_analysis_report(bundle_loader, commit)
if prev_bar:
bundle_report.associate_previous_assets(prev_bar)

# save the bundle report back to storage
bundle_loader.save(bundle_report, commit_report.external_id)
except FileNotInStorageError:
Expand Down
4 changes: 2 additions & 2 deletions services/notification/notifiers/checks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def get_upgrade_message(self, comparison: Comparison) -> str:
[
f"The author of this PR, {author_username}, is not an activated member of this organization on Codecov.",
f"Please [activate this user on Codecov]({links['members_url']}) to display a detailed status check.",
f"Coverage data is still being uploaded to Codecov.io for purposes of overall coverage calculations.",
f"Please don't hesitate to email us at [email protected] with any questions.",
"Coverage data is still being uploaded to Codecov.io for purposes of overall coverage calculations.",
"Please don't hesitate to email us at [email protected] with any questions.",
]
)

Expand Down
12 changes: 6 additions & 6 deletions services/notification/notifiers/comment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ def _create_reached_upload_limit_message(self, comparison):
f"This org is currently on the free Basic Plan; which includes 250 free private repo uploads each rolling month.\
This limit has been reached and additional reports cannot be generated. For unlimited uploads,\
upgrade to our [pro plan]({links['plan_url']}).",
f"",
f"**Do you have questions or need help?** Connect with our sales team today at ` [email protected] `",
"",
"**Do you have questions or need help?** Connect with our sales team today at ` [email protected] `",
]

def _create_upgrade_message(self, comparison):
Expand All @@ -430,15 +430,15 @@ def _create_upgrade_message(self, comparison):
return [
f"The author of this PR, {author_username}, is not an activated member of this organization on Codecov.",
f"Please [activate this user on Codecov]({links['members_url_cloud']}) to display this PR comment.",
f"Coverage data is still being uploaded to Codecov.io for purposes of overall coverage calculations.",
f"Please don't hesitate to email us at [email protected] with any questions.",
"Coverage data is still being uploaded to Codecov.io for purposes of overall coverage calculations.",
"Please don't hesitate to email us at [email protected] with any questions.",
]
else:
return [
f"The author of this PR, {author_username}, is not activated in your Codecov Self-Hosted installation.",
f"Please [activate this user]({links['members_url_self_hosted']}) to display this PR comment.",
f"Coverage data is still being uploaded to Codecov Self-Hosted for the purposes of overall coverage calculations.",
f"Please contact your Codecov On-Premises installation administrator with any questions.",
"Coverage data is still being uploaded to Codecov Self-Hosted for the purposes of overall coverage calculations.",
"Please contact your Codecov On-Premises installation administrator with any questions.",
]

def _create_processing_upload_message(self):
Expand Down
2 changes: 1 addition & 1 deletion services/notification/notifiers/mixins/message/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def get_middle_layout_section_names(self, settings):
def get_upper_section_names(self, settings):
sections = list(map(lambda l: l.strip(), (settings["layout"] or "").split(",")))
headers = ["newheader", "header", "condensed_header"]
if all(not x in sections for x in headers):
if all(x not in sections for x in headers):
sections.insert(0, "condensed_header")

return [
Expand Down
5 changes: 4 additions & 1 deletion services/notification/notifiers/mixins/message/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,10 @@ def _row(title, c1, c2, plus="+", minus="-", neutral=" "):
spacer = ["=" * row_w]

title = "@@%s@@" % "{text:{fill}{align}{width}}".format(
text="Coverage Diff", fill=" ", align="^", width=row_w - 4, strip=True
text="Coverage Diff",
fill=" ",
align="^",
width=row_w - 4,
)

table = (
Expand Down
2 changes: 1 addition & 1 deletion services/notification/notifiers/mixins/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ async def _apply_removals_only_behavior(
)
)
if no_added_no_unexpected_change and some_removed:
return ("success", f", passed because this change only removed code")
return ("success", ", passed because this change only removed code")
return None

async def _apply_adjust_base_behavior(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,12 +543,12 @@ async def test_notify_upload_limited(
assert result.notification_successful
assert result.explanation is None
expected_message = [
f"## [Codecov](https://app.codecov.io/plan/gh/test-acc9) upload limit reached :warning:",
f"This org is currently on the free Basic Plan; which includes 250 free private repo uploads each rolling month.\
"## [Codecov](https://app.codecov.io/plan/gh/test-acc9) upload limit reached :warning:",
"This org is currently on the free Basic Plan; which includes 250 free private repo uploads each rolling month.\
This limit has been reached and additional reports cannot be generated. For unlimited uploads,\
upgrade to our [pro plan](https://app.codecov.io/plan/gh/test-acc9).",
f"",
f"**Do you have questions or need help?** Connect with our sales team today at ` [email protected] `",
"",
"**Do you have questions or need help?** Connect with our sales team today at ` [email protected] `",
]
for exp, res in zip(result.data_sent["message"], expected_message):
assert exp == res
Expand Down
Loading

0 comments on commit 13a87ce

Please sign in to comment.