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

Commit 5b18f31

Browse files
authored
Merge branch 'main' into array-pagination
2 parents 7c433bf + 022c44b commit 5b18f31

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+388
-365
lines changed

codecov_auth/admin.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,6 @@ def is_stale(user: dict) -> bool:
379379
)
380380

381381
stale_users = {user.ownerid for user in resolved_users if is_stale(user)}
382-
383-
# TODO: the existing stale user cleanup script clears the `oauth_token`, though the reason for that is not clear?
384-
# Owner.objects.filter(ownerid__in=stale_users).update(oauth_token=None)
385-
386382
affected_orgs = {
387383
org for org in orgs if stale_users.intersection(set(org.plan_activated_users))
388384
}

codecov_auth/authentication/helpers.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@ class UploadInfo(NamedTuple):
1313
def get_upload_info_from_request_path(request: HttpRequest) -> UploadInfo | None:
1414
path_info = request.get_full_path_info()
1515
# The repo part comes from https://stackoverflow.com/a/22312124
16-
upload_views_prefix_regex = (
17-
r"\/upload\/(\w+)\/([\w\.@:_/\-~]+)\/commits(?:\/([a-f0-9]{40}))?"
18-
)
16+
upload_views_prefix_regex = r"\/upload\/(\w+)\/([\w\.@:_/\-~]+)\/(commits|upload-coverage)(?:\/([a-f0-9]{40}))?"
1917
match = re.search(upload_views_prefix_regex, path_info)
2018

2119
if match is None:
2220
return None
2321

2422
service = match.group(1)
2523
encoded_slug = match.group(2)
26-
commitid = match.group(3)
24+
if match.group(3) == "commits":
25+
commitid = match.group(4)
26+
else:
27+
commitid = None
2728

2829
return UploadInfo(service, encoded_slug, commitid)

codecov_auth/commands/owner/interactors/set_yaml_on_owner.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from typing import Optional
33

44
import yaml
5+
from shared.django_apps.core.models import Repository
6+
from shared.django_apps.utils.model_utils import get_ownerid_if_member
57
from shared.validation.exceptions import InvalidYamlException
68
from shared.yaml.validation import validate_yaml
79

@@ -50,13 +52,45 @@ def convert_yaml_to_dict(self, yaml_input: str) -> Optional[dict]:
5052
message = f"Error at {str(e.error_location)}: {e.error_message}"
5153
raise ValidationError(message)
5254

55+
def yaml_side_effects(self, old_yaml: dict, new_yaml: dict):
56+
old_yaml_branch = old_yaml and old_yaml.get("codecov", {}).get("branch")
57+
new_yaml_branch = new_yaml and new_yaml.get("codecov", {}).get("branch")
58+
59+
# Update all repositories from owner if branch is updated in yaml
60+
if new_yaml_branch != old_yaml_branch:
61+
repos = Repository.objects.filter(author_id=self.owner.ownerid)
62+
repos.update(
63+
branch=new_yaml_branch or old_yaml_branch
64+
) # Keeps old_branch if new_branch is None
65+
66+
old_yaml_bot = old_yaml and old_yaml.get("codecov", {}).get("bot")
67+
new_yaml_bot = new_yaml and new_yaml.get("codecov", {}).get("bot")
68+
69+
# Update owner's bot column if bot is updated in yaml
70+
if new_yaml_bot != old_yaml_bot:
71+
new_bot = (
72+
get_ownerid_if_member(
73+
service=self.owner.service,
74+
owner_username=new_yaml_bot,
75+
owner_id=self.owner.ownerid,
76+
)
77+
or old_yaml_bot
78+
or None
79+
)
80+
self.owner.bot = new_bot
81+
self.owner.save()
82+
5383
@sync_to_async
5484
def execute(self, username: str, yaml_input: str) -> Owner:
5585
self.validate()
5686
self.owner = self.get_owner(username)
5787
self.authorize()
88+
old_yaml = self.owner.yaml
5889
self.owner.yaml = self.convert_yaml_to_dict(yaml_input)
5990
if self.owner.yaml:
6091
self.owner.yaml[OWNER_YAML_TO_STRING_KEY] = yaml_input
6192
self.owner.save()
93+
94+
# side effects
95+
self.yaml_side_effects(old_yaml=old_yaml, new_yaml=self.owner.yaml)
6296
return self.owner

codecov_auth/commands/owner/interactors/tests/test_set_yaml_on_owner.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import pytest
22
from django.test import TransactionTestCase
3-
from shared.django_apps.core.tests.factories import OwnerFactory
3+
from shared.django_apps.core.tests.factories import OwnerFactory, RepositoryFactory
44

55
from codecov.commands.exceptions import (
66
NotFound,
77
Unauthenticated,
88
Unauthorized,
99
ValidationError,
1010
)
11+
from codecov.db import sync_to_async
1112

1213
from ..set_yaml_on_owner import SetYamlOnOwnerInteractor
1314

@@ -21,6 +22,18 @@
2122
bot: 'codecov'
2223
"""
2324

25+
good_yaml_with_bot_and_branch = """
26+
codecov:
27+
branch: 'test-1'
28+
bot: 'codecov'
29+
"""
30+
31+
yaml_with_changed_branch_and_bot = """
32+
codecov:
33+
branch: 'test-2'
34+
bot: 'codecov-2'
35+
"""
36+
2437
bad_yaml_not_dict = """
2538
hey
2639
"""
@@ -143,3 +156,15 @@ async def test_yaml_has_comments(self):
143156
"# comment 3\n"
144157
" #comment 4\n",
145158
}
159+
160+
async def test_user_changes_yaml_bot_and_branch(self):
161+
await sync_to_async(RepositoryFactory)(author=self.org, branch="fake-branch")
162+
owner_updated = await self.execute(
163+
self.current_owner, self.org.username, yaml_with_changed_branch_and_bot
164+
)
165+
# check the interactor returns the right owner
166+
assert owner_updated.ownerid == self.org.ownerid
167+
assert owner_updated.yaml == {
168+
"codecov": {"branch": "test-2", "bot": "codecov-2"},
169+
"to_string": "\ncodecov:\n branch: 'test-2'\n bot: 'codecov-2'\n",
170+
}

graphql_api/dataloader/bundle_analysis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import Union
22

3+
from shared.api_archive.archive import ArchiveService
34
from shared.bundle_analysis import (
45
BundleAnalysisReportLoader,
56
MissingBaseReportError,
@@ -10,7 +11,6 @@
1011
from core.models import Commit
1112
from graphql_api.types.comparison.comparison import MissingBaseReport, MissingHeadReport
1213
from reports.models import CommitReport
13-
from services.archive import ArchiveService
1414
from services.bundle_analysis import BundleAnalysisComparison, BundleAnalysisReport
1515

1616

graphql_api/tests/test_bundle_analysis_measurements.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from unittest.mock import patch
22

33
from django.test import TransactionTestCase
4+
from shared.api_archive.archive import ArchiveService
45
from shared.bundle_analysis import StoragePaths
56
from shared.bundle_analysis.storage import get_bucket_name
67
from shared.django_apps.core.tests.factories import (
@@ -11,10 +12,7 @@
1112
from shared.storage.memory import MemoryStorageService
1213

1314
from reports.models import CommitReport
14-
from reports.tests.factories import (
15-
CommitReportFactory,
16-
)
17-
from services.archive import ArchiveService
15+
from reports.tests.factories import CommitReportFactory
1816
from timeseries.tests.factories import MeasurementFactory
1917

2018
from .helper import GraphQLTestHelper

graphql_api/tests/test_commit.py

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import yaml
88
from django.test import TransactionTestCase
9+
from shared.api_archive.archive import ArchiveService
910
from shared.bundle_analysis import StoragePaths
1011
from shared.bundle_analysis.storage import get_bucket_name
1112
from shared.django_apps.core.tests.factories import (
@@ -30,7 +31,6 @@
3031
UploadFactory,
3132
UploadFlagMembershipFactory,
3233
)
33-
from services.archive import ArchiveService
3434
from services.comparison import MissingComparisonReport
3535
from services.components import Component
3636
from services.profiling import CriticalFile
@@ -3323,3 +3323,70 @@ def test_bundle_analysis_asset_routes(self, get_storage_service):
33233323
"/login",
33243324
"/super/long/url/path",
33253325
]
3326+
3327+
@patch("graphql_api.dataloader.bundle_analysis.get_appropriate_storage_service")
3328+
def test_bundle_analysis_report_info(self, get_storage_service):
3329+
storage = MemoryStorageService({})
3330+
get_storage_service.return_value = storage
3331+
3332+
head_commit_report = CommitReportFactory(
3333+
commit=self.commit, report_type=CommitReport.ReportType.BUNDLE_ANALYSIS
3334+
)
3335+
3336+
with open(
3337+
"./services/tests/samples/bundle_with_assets_and_modules.sqlite", "rb"
3338+
) as f:
3339+
storage_path = StoragePaths.bundle_report.path(
3340+
repo_key=ArchiveService.get_archive_hash(self.repo),
3341+
report_key=head_commit_report.external_id,
3342+
)
3343+
storage.write_file(get_bucket_name(), storage_path, f)
3344+
3345+
query = """
3346+
query FetchCommit($org: String!, $repo: String!, $commit: String!) {
3347+
owner(username: $org) {
3348+
repository(name: $repo) {
3349+
... on Repository {
3350+
commit(id: $commit) {
3351+
bundleAnalysis {
3352+
bundleAnalysisReport {
3353+
__typename
3354+
... on BundleAnalysisReport {
3355+
bundle(name: "b5") {
3356+
info {
3357+
version
3358+
plugin_name
3359+
plugin_version
3360+
built_at
3361+
duration
3362+
bundler_name
3363+
bundler_version
3364+
}
3365+
}
3366+
}
3367+
}
3368+
}
3369+
}
3370+
}
3371+
}
3372+
}
3373+
}
3374+
"""
3375+
3376+
variables = {
3377+
"org": self.org.username,
3378+
"repo": self.repo.name,
3379+
"commit": self.commit.commitid,
3380+
}
3381+
data = self.gql_request(query, variables=variables)
3382+
commit = data["owner"]["repository"]["commit"]
3383+
3384+
bundle_info = commit["bundleAnalysis"]["bundleAnalysisReport"]["bundle"]["info"]
3385+
3386+
assert bundle_info["version"] == "1"
3387+
assert bundle_info["plugin_name"] == "codecov-vite-bundle-analysis-plugin"
3388+
assert bundle_info["plugin_version"] == "1.0.0"
3389+
assert bundle_info["built_at"] == "2023-12-01 17:17:28.604000"
3390+
assert bundle_info["duration"] == 331
3391+
assert bundle_info["bundler_name"] == "rollup"
3392+
assert bundle_info["bundler_version"] == "3.29.4"

graphql_api/tests/test_pull.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from django.test import TransactionTestCase
66
from freezegun import freeze_time
7+
from shared.api_archive.archive import ArchiveService
78
from shared.bundle_analysis import StoragePaths
89
from shared.bundle_analysis.storage import get_bucket_name
910
from shared.django_apps.core.tests.factories import (
@@ -18,7 +19,6 @@
1819
from core.models import Commit
1920
from reports.models import CommitReport
2021
from reports.tests.factories import CommitReportFactory, ReportLevelTotalsFactory
21-
from services.archive import ArchiveService
2222

2323
from .helper import GraphQLTestHelper, paginate_connection
2424

graphql_api/types/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
bundle_data_bindable,
1818
bundle_module_bindable,
1919
bundle_report_bindable,
20+
bundle_report_info_bindable,
2021
)
2122
from .commit import (
2223
commit,
@@ -149,6 +150,7 @@
149150
bundle_data_bindable,
150151
bundle_module_bindable,
151152
bundle_report_bindable,
153+
bundle_report_info_bindable,
152154
commit_bindable,
153155
commit_bundle_analysis_bindable,
154156
commit_coverage_analytics_bindable,

graphql_api/types/bundle_analysis/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
bundle_data_bindable,
66
bundle_module_bindable,
77
bundle_report_bindable,
8+
bundle_report_info_bindable,
89
)
910
from .comparison import (
1011
bundle_analysis_comparison_bindable,
@@ -26,6 +27,7 @@
2627
"bundle_data_bindable",
2728
"bundle_module_bindable",
2829
"bundle_report_bindable",
30+
"bundle_report_info_bindable",
2931
"bundle_analysis_comparison_bindable",
3032
"bundle_analysis_comparison_result_bindable",
3133
"bundle_comparison_bindable",

0 commit comments

Comments
 (0)