Skip to content

Commit ff4c52b

Browse files
NicoHinderlingandrewshie-sentry
authored andcommitted
chore(launchpad): Return artifact URL upon creation (#97558)
Instead of just returning the artifact id, lets return the full URL
1 parent 977c138 commit ff4c52b

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

src/sentry/preprod/api/endpoints/organization_preprod_artifact_assemble.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from sentry.models.orgauthtoken import is_org_auth_token_auth, update_org_auth_token_last_used
1515
from sentry.preprod.analytics import PreprodArtifactApiAssembleEvent
1616
from sentry.preprod.tasks import assemble_preprod_artifact, create_preprod_artifact
17+
from sentry.preprod.url_utils import get_preprod_artifact_url
1718
from sentry.tasks.assemble import ChunkFileState
1819
from sentry.types.ratelimit import RateLimit, RateLimitCategory
1920

@@ -183,6 +184,12 @@ def post(self, request: Request, project) -> Response:
183184
if is_org_auth_token_auth(request.auth):
184185
update_org_auth_token_last_used(request.auth, [project.id])
185186

187+
artifact_url = get_preprod_artifact_url(project.organization_id, artifact_id)
188+
186189
return Response(
187-
{"state": ChunkFileState.OK, "missingChunks": [], "artifactId": artifact_id}
190+
{
191+
"state": ChunkFileState.CREATED,
192+
"missingChunks": [],
193+
"artifactUrl": artifact_url,
194+
}
188195
)

src/sentry/preprod/url_utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from __future__ import annotations
2+
3+
from sentry.models.organization import Organization
4+
5+
6+
def get_preprod_artifact_url(organization_id: int, artifact_id: str) -> str:
7+
"""
8+
Build a region/customer-domain aware absolute URL for the preprod artifact UI.
9+
"""
10+
organization: Organization = Organization.objects.get_from_cache(id=organization_id)
11+
12+
path = f"/organizations/{organization.slug}/preprod/internal/{artifact_id}"
13+
return organization.absolute_url(path)

tests/sentry/preprod/api/endpoints/test_organization_preprod_artifact_assemble.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,10 @@ def test_assemble_basic(
374374
HTTP_AUTHORIZATION=f"Bearer {self.token.token}",
375375
)
376376
assert response.status_code == 200, response.content
377-
assert response.data["state"] == ChunkFileState.OK
377+
assert response.data["state"] == ChunkFileState.CREATED
378378
assert set(response.data["missingChunks"]) == set()
379-
assert response.data["artifactId"] == artifact_id
379+
expected_url = f"/organizations/{self.organization.slug}/preprod/internal/{artifact_id}"
380+
assert expected_url in response.data["artifactUrl"]
380381

381382
mock_create_preprod_artifact.assert_called_once_with(
382383
org_id=self.organization.id,
@@ -440,9 +441,10 @@ def test_assemble_with_metadata(
440441
HTTP_AUTHORIZATION=f"Bearer {self.token.token}",
441442
)
442443
assert response.status_code == 200, response.content
443-
assert response.data["state"] == ChunkFileState.OK
444+
assert response.data["state"] == ChunkFileState.CREATED
444445
assert set(response.data["missingChunks"]) == set()
445-
assert response.data["artifactId"] == artifact_id
446+
expected_url = f"/organizations/{self.organization.slug}/preprod/internal/{artifact_id}"
447+
assert expected_url in response.data["artifactUrl"]
446448

447449
mock_create_preprod_artifact.assert_called_once_with(
448450
org_id=self.organization.id,
@@ -500,7 +502,7 @@ def test_assemble_with_missing_chunks(self) -> None:
500502
)
501503

502504
assert response.status_code == 200, response.content
503-
assert response.data["state"] == ChunkFileState.OK
505+
assert response.data["state"] == ChunkFileState.CREATED
504506

505507
def test_assemble_response(self) -> None:
506508
content = b"test response content"
@@ -518,7 +520,7 @@ def test_assemble_response(self) -> None:
518520
)
519521

520522
assert response.status_code == 200, response.content
521-
assert response.data["state"] == ChunkFileState.OK
523+
assert response.data["state"] == ChunkFileState.CREATED
522524

523525
def test_assemble_with_pending_deletion_project(self) -> None:
524526
self.project.status = ObjectStatus.PENDING_DELETION
@@ -637,7 +639,7 @@ def test_check_existing_assembly_status(self) -> None:
637639

638640
# Even if assembly status exists, endpoint doesn't check it
639641
set_assemble_status(
640-
AssembleTask.PREPROD_ARTIFACT, self.project.id, checksum, ChunkFileState.OK
642+
AssembleTask.PREPROD_ARTIFACT, self.project.id, checksum, ChunkFileState.CREATED
641643
)
642644

643645
response = self.client.post(
@@ -671,7 +673,7 @@ def test_integration_task_sets_status_api_can_read_it(self) -> None:
671673

672674
# Even if task sets status, this endpoint doesn't read it
673675
set_assemble_status(
674-
AssembleTask.PREPROD_ARTIFACT, self.project.id, total_checksum, ChunkFileState.OK
676+
AssembleTask.PREPROD_ARTIFACT, self.project.id, total_checksum, ChunkFileState.CREATED
675677
)
676678

677679
response = self.client.post(

0 commit comments

Comments
 (0)