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

Commit 02c7a11

Browse files
committed
Change Upload Sent to Upload Received and move to beginning of endpoint logic
1 parent 1589140 commit 02c7a11

File tree

7 files changed

+48
-47
lines changed

7 files changed

+48
-47
lines changed

upload/tests/views/test_bundle_analysis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def test_upload_bundle_analysis_success(db, client, mocker, mock_redis):
109109

110110
# emits Amplitude event
111111
mock_amplitude.assert_called_with(
112-
"Upload Sent",
112+
"Upload Received",
113113
{
114114
"user_ownerid": UNKNOWN_USER_OWNERID,
115115
"ownerid": commit.repository.author.ownerid,

upload/tests/views/test_test_results.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def test_upload_test_results(db, client, mocker, mock_redis):
121121

122122
# emits Amplitude event
123123
mock_amplitude.assert_called_with(
124-
"Upload Sent",
124+
"Upload Received",
125125
{
126126
"user_ownerid": UNKNOWN_USER_OWNERID,
127127
"ownerid": commit.repository.author.ownerid,

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
},
436436
)
437437
amplitude_mock.assert_called_with(
438-
"Upload Sent",
438+
"Upload Received",
439439
{
440440
"user_ownerid": commit.author.ownerid,
441441
"ownerid": commit.repository.author.ownerid,
@@ -601,7 +601,7 @@ def test_uploads_post_token_required_auth_check(
601601
},
602602
)
603603
amplitude_mock.assert_called_with(
604-
"Upload Sent",
604+
"Upload Received",
605605
{
606606
"user_ownerid": commit.author.ownerid,
607607
"ownerid": commit.repository.author.ownerid,
@@ -748,7 +748,7 @@ def test_uploads_post_github_oidc_auth(
748748
},
749749
)
750750
amplitude_mock.assert_called_with(
751-
"Upload Sent",
751+
"Upload Received",
752752
{
753753
"user_ownerid": commit.author.ownerid,
754754
"ownerid": commit.repository.author.ownerid,

upload/views/bundle_analysis.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,20 @@ def post(self, request: HttpRequest) -> Response:
141141
},
142142
)
143143

144+
AmplitudeEventPublisher().publish(
145+
"Upload Received",
146+
{
147+
"user_ownerid": commit.author.ownerid
148+
if commit.author
149+
else UNKNOWN_USER_OWNERID,
150+
"ownerid": repo.author.ownerid,
151+
"repoid": repo.repoid,
152+
"commitid": commit.id, # Not commit.commitid, we do not want a commit SHA here!
153+
"pullid": commit.pullid,
154+
"upload_type": "Bundle",
155+
},
156+
)
157+
144158
storage_path = data.get("storage_path", None)
145159
upload_external_id = data.get("upload_external_id", None)
146160
url = None
@@ -221,18 +235,4 @@ def post(self, request: HttpRequest) -> Response:
221235
),
222236
)
223237

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

upload/views/test_results.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,20 @@ def post(self, request):
136136
},
137137
)
138138

139+
AmplitudeEventPublisher().publish(
140+
"Upload Received",
141+
{
142+
"user_ownerid": commit.author.ownerid
143+
if commit.author
144+
else UNKNOWN_USER_OWNERID,
145+
"ownerid": repo.author.ownerid,
146+
"repoid": repo.repoid,
147+
"commitid": commit.id, # Not commit.commitid, we do not want a commit SHA here!
148+
"pullid": commit.pullid,
149+
"upload_type": "Test results",
150+
},
151+
)
152+
139153
upload_external_id = str(uuid.uuid4())
140154

141155
url = None
@@ -188,20 +202,6 @@ def post(self, request):
188202
report_type=CommitReport.ReportType.TEST_RESULTS,
189203
)
190204

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

upload/views/upload_coverage.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
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
910
from shared.metrics import inc_counter
1011

1112
from codecov_auth.authentication.repo_auth import (
@@ -92,6 +93,20 @@ def post(self, request: HttpRequest, *args, **kwargs) -> Response:
9293
),
9394
)
9495

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+
95110
# Create report
96111
commit_report_data = dict(
97112
code=request.data.get("code"),

upload/views/uploads.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
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
1413
from shared.metrics import inc_counter
1514
from shared.upload.utils import UploaderType, insert_coverage_measurement
1615

@@ -168,19 +167,6 @@ def send_analytics_data(
168167
AnalyticsService().account_uploaded_coverage_report(
169168
commit.repository.author.ownerid, analytics_upload_data
170169
)
171-
AmplitudeEventPublisher().publish(
172-
"Upload Sent",
173-
{
174-
"user_ownerid": commit.author.ownerid
175-
if commit.author
176-
else UNKNOWN_USER_OWNERID,
177-
"ownerid": commit.repository.author.ownerid,
178-
"repoid": commit.repository.repoid,
179-
"commitid": commit.id, # Not commit.commitid, we do not want a commit SHA here.
180-
"pullid": commit.pullid,
181-
"upload_type": "Coverage report",
182-
},
183-
)
184170

185171

186172
def get_token_for_analytics(commit: Commit, request: HttpRequest) -> str:

0 commit comments

Comments
 (0)