Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Conversation

@rohitvinnakota-codecov
Copy link
Contributor

Purpose/Motivation

What is the feature? Why is this being done?

Links to relevant tickets

What does this PR do?

Include a brief description of the changes in this PR. Bullet points are your friend.

Notes to Reviewer

Anything to note to the team? Any tips on how to review, or where to start?

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.

@seer-by-sentry
Copy link
Contributor

✅ Sentry found no issues in your recent changes ✅

@rohitvinnakota-codecov
Copy link
Contributor Author

@codecov-ai-reviewer test

@codecov-ai
Copy link
Contributor

codecov-ai bot commented Mar 26, 2025

On it! Codecov is generating unit tests for this PR.

@codecov
Copy link

codecov bot commented Mar 26, 2025

Codecov Report

Attention: Patch coverage is 23.40426% with 36 lines in your changes missing coverage. Please review.

Project coverage is 96.11%. Comparing base (bd0ad54) to head (7b91e67).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
graphs/views.py 21.73% 36 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1250      +/-   ##
==========================================
- Coverage   96.31%   96.11%   -0.21%     
==========================================
  Files         492      492              
  Lines       16846    16891      +45     
==========================================
+ Hits        16226    16235       +9     
- Misses        620      656      +36     
Flag Coverage Δ
unit 96.11% <23.40%> (-0.21%) ⬇️

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

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

@codecov-notifications
Copy link

codecov-notifications bot commented Mar 26, 2025

Codecov Report

Attention: Patch coverage is 23.40426% with 36 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
graphs/views.py 21.73% 36 Missing ⚠️

📢 Thoughts on this report? Let us know!

@rohitvinnakota-codecov
Copy link
Contributor Author

@codecov-ai-reviewer test

@codecov-ai
Copy link
Contributor

codecov-ai bot commented Mar 26, 2025

On it! Codecov is generating unit tests for this PR.

@rohitvinnakota-codecov
Copy link
Contributor Author

@codecov-ai-reviewer test

@codecov-ai
Copy link
Contributor

codecov-ai bot commented Mar 26, 2025

On it! Codecov is generating unit tests for this PR.

@codecov-ai codecov-ai bot mentioned this pull request Mar 26, 2025
@rohitvinnakota-codecov
Copy link
Contributor Author

@codecov-ai-reviewer test

@codecov-ai
Copy link
Contributor

codecov-ai bot commented Mar 26, 2025

On it! Codecov is generating unit tests for this PR.

@codecov-ai
Copy link
Contributor

codecov-ai bot commented Mar 26, 2025

Sentry has determined that unit tests are not necessary for this PR.

@rohitvinnakota-codecov
Copy link
Contributor Author

@codecov-ai-reviewer review

@codecov-ai
Copy link
Contributor

codecov-ai bot commented Mar 31, 2025

On it! We are reviewing the PR and will provide feedback shortly.

Comment on lines +228 to +277

def get_bundle_size(self) -> int | None:
try:
repo = self.repo
except Http404:
log.warning("Repo not found", extra=dict(repo=self.kwargs.get("repo_name")))
return None

if repo.private and repo.image_token != self.request.query_params.get("token"):
log.warning(
"Token provided does not match repo's image token",
extra=dict(repo=repo),
)
return None

branch_name = self.kwargs.get("branch") or repo.branch
branch = Branch.objects.filter(
name=branch_name, repository_id=repo.repoid
).first()

if branch is None:
log.warning(
"Branch not found", extra=dict(branch_name=branch_name, repo=repo)
)
return None

try:
commit: Commit = repo.commits.filter(commitid=branch.head).first()
except ObjectDoesNotExist:
log.warning("Commit not found", extra=dict(commit=branch.head))
return None

commit_bundles = load_report(commit)

if commit_bundles is None:
log.warning(
"Bundle analysis report not found for commit",
extra=dict(commit=branch.head),
)
return None

bundle_name = str(self.kwargs.get("bundle"))
bundle = commit_bundles.bundle_report(bundle_name)

if bundle is None:
log.warning(
"Bundle with provided name not found for commit",
extra=dict(commit=branch.head),
)
return None
Copy link
Contributor

Choose a reason for hiding this comment

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

The get_bundle_size method is quite long and handles multiple responsibilities (permission checking, repo validation, branch lookup, commit lookup, bundle loading). Consider breaking this down into smaller, more focused methods to improve readability and maintainability. This would also make it easier to test individual pieces of functionality.

Comment on lines +209 to +215
filename = "bundle-badge"

def get_object(self, request, *args, **kwargs):
# Validate precision query param
precision = self.request.query_params.get("precision", "2")
if precision not in self.precisions:
raise NotFound("Bundle size precision should be one of [ 0 || 1 || 2 ]")
Copy link
Contributor

Choose a reason for hiding this comment

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

The error handling for precision validation could be moved to a separate validation method, following the Single Responsibility Principle. Also, consider using Django's built-in validators or form validation for this.

Comment on lines +16 to +24
re_path(
"branch/(?P<branch>.+)/(graph|graphs)/bundle/(?P<bundle>.+)/badge.(?P<ext>[^/]+)",
BundleBadgeHandler.as_view(),
name="branch-bundle-badge",
),
re_path(
"(graph|graphs)/bundle/(?P<bundle>.+)/badge.(?P<ext>[^/]+)",
BundleBadgeHandler.as_view(),
name="default-bundle-badge",
Copy link
Contributor

Choose a reason for hiding this comment

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

The URL patterns for bundle badges are similar to existing patterns. Consider using Django's path() instead of re_path() for improved readability and maintainability. Also, the regex patterns could be simplified and constants could be used for repeated patterns.

Comment on lines +228 to +277

def get_bundle_size(self) -> int | None:
try:
repo = self.repo
except Http404:
log.warning("Repo not found", extra=dict(repo=self.kwargs.get("repo_name")))
return None

if repo.private and repo.image_token != self.request.query_params.get("token"):
log.warning(
"Token provided does not match repo's image token",
extra=dict(repo=repo),
)
return None

branch_name = self.kwargs.get("branch") or repo.branch
branch = Branch.objects.filter(
name=branch_name, repository_id=repo.repoid
).first()

if branch is None:
log.warning(
"Branch not found", extra=dict(branch_name=branch_name, repo=repo)
)
return None

try:
commit: Commit = repo.commits.filter(commitid=branch.head).first()
except ObjectDoesNotExist:
log.warning("Commit not found", extra=dict(commit=branch.head))
return None

commit_bundles = load_report(commit)

if commit_bundles is None:
log.warning(
"Bundle analysis report not found for commit",
extra=dict(commit=branch.head),
)
return None

bundle_name = str(self.kwargs.get("bundle"))
bundle = commit_bundles.bundle_report(bundle_name)

if bundle is None:
log.warning(
"Bundle with provided name not found for commit",
extra=dict(commit=branch.head),
)
return None
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding caching for bundle size calculations to improve performance, especially for frequently accessed badges. This could be implemented using Django's cache framework.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants