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

Commit 898c62b

Browse files
committed
Add BA and TA upload events
1 parent 46e642a commit 898c62b

File tree

6 files changed

+63
-4
lines changed

6 files changed

+63
-4
lines changed

upload/tests/views/test_bundle_analysis.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def test_upload_bundle_analysis_success(db, client, mocker, mock_redis):
2727
"shared.api_archive.archive.StorageService.create_presigned_put",
2828
return_value="test-presigned-put",
2929
)
30+
mock_amplitude = mocker.patch("shared.events.amplitude.AmplitudeEventPublisher")
3031

3132
repository = RepositoryFactory.create()
3233
commit_sha = "6fd5b89357fc8cdf34d6197549ac7c6d7e5977ef"
@@ -103,6 +104,19 @@ def test_upload_bundle_analysis_success(db, client, mocker, mock_redis):
103104
},
104105
)
105106

107+
# emits Amplitude event
108+
mock_amplitude.return_value.publish.assert_called_with(
109+
"Upload Sent",
110+
{
111+
"user_ownerid": commit.repository.author.ownerid,
112+
"ownerid": commit.repository.author.ownerid,
113+
"repoid": commit.repository.repoid,
114+
"commitid": commit.id,
115+
"pullid": commit.pullid,
116+
"upload_type": "Bundle",
117+
},
118+
)
119+
106120

107121
@pytest.mark.django_db(databases={"default", "timeseries"})
108122
@override_settings(SHELTER_SHARED_SECRET="shelter-shared-secret")

upload/tests/views/test_test_results.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def test_upload_test_results(db, client, mocker, mock_redis):
2525
"shared.api_archive.archive.StorageService.create_presigned_put",
2626
return_value="test-presigned-put",
2727
)
28+
mock_amplitude = mocker.patch("shared.events.amplitude.AmplitudeEventPublisher")
2829

2930
owner = OwnerFactory(service="github", username="codecov")
3031
repository = RepositoryFactory.create(author=owner)
@@ -115,6 +116,19 @@ def test_upload_test_results(db, client, mocker, mock_redis):
115116
},
116117
)
117118

119+
# emits Amplitude event
120+
mock_amplitude.return_value.publish.assert_called_with(
121+
"Upload Sent",
122+
{
123+
"user_ownerid": commit.repository.author.ownerid,
124+
"ownerid": commit.repository.author.ownerid,
125+
"repoid": commit.repository.repoid,
126+
"commitid": commit.id,
127+
"pullid": commit.pullid,
128+
"upload_type": "Test results",
129+
},
130+
)
131+
118132

119133
def test_test_results_org_token(db, client, mocker, mock_redis):
120134
mocker.patch.object(TaskService, "upload")

upload/tests/views/test_uploads.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ def test_uploads_post_tokenless(db, mocker, mock_redis, private, branch, branch_
435435
amplitude_mock.return_value.publish.assert_called_with(
436436
"Upload Sent",
437437
{
438-
"user_ownerid": commit.author.ownerid,
438+
"user_ownerid": commit.repository.author.ownerid,
439439
"ownerid": commit.repository.author.ownerid,
440440
"repoid": commit.repository.repoid,
441441
"commitid": commit.id,
@@ -599,7 +599,7 @@ def test_uploads_post_token_required_auth_check(
599599
amplitude_mock.return_value.publish.assert_called_with(
600600
"Upload Sent",
601601
{
602-
"user_ownerid": commit.author.ownerid,
602+
"user_ownerid": commit.repository.author.ownerid,
603603
"ownerid": commit.repository.author.ownerid,
604604
"repoid": commit.repository.repoid,
605605
"commitid": commit.id,
@@ -746,7 +746,7 @@ def test_uploads_post_github_oidc_auth(
746746
amplitude_mock.return_value.publish.assert_called_with(
747747
"Upload Sent",
748748
{
749-
"user_ownerid": commit.author.ownerid,
749+
"user_ownerid": commit.repository.author.ownerid,
750750
"ownerid": commit.repository.author.ownerid,
751751
"repoid": commit.repository.repoid,
752752
"commitid": commit.id,

upload/views/bundle_analysis.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from rest_framework.views import APIView
1212
from shared.api_archive.archive import ArchiveService
1313
from shared.bundle_analysis.storage import StoragePaths, get_bucket_name
14+
from shared.events.amplitude import AmplitudeEventPublisher
1415
from shared.metrics import Counter, inc_counter
1516

1617
from codecov_auth.authentication.repo_auth import (
@@ -220,4 +221,16 @@ def post(self, request: HttpRequest) -> Response:
220221
),
221222
)
222223

224+
AmplitudeEventPublisher().publish(
225+
"Upload Sent",
226+
{
227+
"user_ownerid": repo.author.ownerid,
228+
"ownerid": repo.author.ownerid,
229+
"repoid": repo.repoid,
230+
"commitid": commit.id, # Not commit.commitid, we do not want a commit SHA here!
231+
"pullid": commit.pullid,
232+
"upload_type": "Bundle",
233+
},
234+
)
235+
223236
return Response({"url": url}, status=201)

upload/views/test_results.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from rest_framework.response import Response
99
from rest_framework.views import APIView
1010
from shared.api_archive.archive import ArchiveService, MinioEndpoints
11+
from shared.events.amplitude import AmplitudeEventPublisher
1112
from shared.metrics import inc_counter
1213

1314
from codecov_auth.authentication.repo_auth import (
@@ -187,6 +188,18 @@ def post(self, request):
187188
report_type=CommitReport.ReportType.TEST_RESULTS,
188189
)
189190

191+
AmplitudeEventPublisher().publish(
192+
"Upload Sent",
193+
{
194+
"user_ownerid": repo.author.ownerid,
195+
"ownerid": repo.author.ownerid,
196+
"repoid": repo.repoid,
197+
"commitid": commit.id, # Not commit.commitid, we do not want a commit SHA here!
198+
"pullid": commit.pullid,
199+
"upload_type": "Test results",
200+
},
201+
)
202+
190203
if url is None:
191204
return Response(status=201)
192205
else:

upload/views/uploads.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,12 @@ def send_analytics_data(
171171
AmplitudeEventPublisher().publish(
172172
"Upload Sent",
173173
{
174-
"user_ownerid": commit.author.ownerid,
174+
# Attribute this event to the repo owner. For BA/TA uploads we
175+
# don't necessarily have the commit author at upload time, so to
176+
# align the upload events, we will always attribute uploads to the
177+
# repo owner. It's also not necessarily the case that the commit
178+
# author is the owner performing the 'Upload Sent' action.
179+
"user_ownerid": commit.repository.author.ownerid,
175180
"ownerid": commit.repository.author.ownerid,
176181
"repoid": commit.repository.repoid,
177182
"commitid": commit.id, # Not commit.commitid, we do not want a commit SHA here!

0 commit comments

Comments
 (0)