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

Commit 0449c02

Browse files
committed
Capture uploads for upload-only endpoint also
1 parent b1440be commit 0449c02

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

upload/tests/views/test_uploads.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ def test_uploads_post(db, mocker, mock_redis):
206206
mocker.patch.object(
207207
CanDoCoverageUploadsPermission, "has_permission", return_value=True
208208
)
209+
amplitude_mock = mocker.patch(
210+
"shared.events.amplitude.AmplitudeEventPublisher.publish"
211+
)
209212
presigned_put_mock = mocker.patch(
210213
"shared.storage.MinioStorageService.create_presigned_put",
211214
return_value="presigned put",
@@ -262,6 +265,17 @@ def test_uploads_post(db, mocker, mock_redis):
262265
== f"{settings.CODECOV_DASHBOARD_URL}/{repository.author.service}/{repository.author.username}/{repository.name}/commit/{commit.commitid}"
263266
)
264267

268+
amplitude_mock.assert_called_with(
269+
"Upload Received",
270+
{
271+
"user_ownerid": commit.author.ownerid,
272+
"ownerid": commit.repository.author.ownerid,
273+
"repoid": commit.repository.repoid,
274+
"commitid": commit.id,
275+
"pullid": commit.pullid,
276+
"upload_type": "Coverage report",
277+
},
278+
)
265279
assert ReportSession.objects.filter(
266280
report_id=commit_report.id,
267281
upload_extras={"format_version": "v1"},

upload/views/upload_coverage.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from rest_framework.response import Response
77
from rest_framework.views import APIView
88
from shared.api_archive.archive import ArchiveService
9-
from shared.events.amplitude import UNKNOWN_USER_OWNERID, AmplitudeEventPublisher
109
from shared.metrics import inc_counter
1110

1211
from codecov_auth.authentication.repo_auth import (
@@ -93,20 +92,6 @@ def post(self, request: HttpRequest, *args, **kwargs) -> Response:
9392
),
9493
)
9594

96-
AmplitudeEventPublisher().publish(
97-
"Upload Received",
98-
{
99-
"user_ownerid": commit.author.ownerid
100-
if commit.author
101-
else UNKNOWN_USER_OWNERID,
102-
"ownerid": commit.repository.author.ownerid,
103-
"repoid": commit.repository.repoid,
104-
"commitid": commit.id, # Not commit.commitid, we do not want a commit SHA here.
105-
"pullid": commit.pullid,
106-
"upload_type": "Coverage report",
107-
},
108-
)
109-
11095
# Create report
11196
commit_report_data = dict(
11297
code=request.data.get("code"),

upload/views/uploads.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from rest_framework.response import Response
1111
from rest_framework.views import APIView
1212
from shared.api_archive.archive import ArchiveService, MinioEndpoints
13+
from shared.events.amplitude import UNKNOWN_USER_OWNERID, AmplitudeEventPublisher
1314
from shared.metrics import inc_counter
1415
from shared.upload.utils import UploaderType, insert_coverage_measurement
1516

@@ -51,6 +52,20 @@ def create_upload(
5152
is_shelter_request: bool,
5253
analytics_token: str,
5354
) -> ReportSession:
55+
AmplitudeEventPublisher().publish(
56+
"Upload Received",
57+
{
58+
"user_ownerid": commit.author.ownerid
59+
if commit.author
60+
else UNKNOWN_USER_OWNERID,
61+
"ownerid": commit.repository.author.ownerid,
62+
"repoid": commit.repository.repoid,
63+
"commitid": commit.id, # Not commit.commitid, we do not want a commit SHA here.
64+
"pullid": commit.pullid,
65+
"upload_type": "Coverage report",
66+
},
67+
)
68+
5469
version = (
5570
serializer.validated_data["version"]
5671
if "version" in serializer.validated_data

0 commit comments

Comments
 (0)