Skip to content

Commit cbf33d9

Browse files
authored
feat(emerge): Add new vcs fields to buildDetails API (#97456)
Add new vcs fields to buildDetails API Nullable fields
1 parent ae11c94 commit cbf33d9

File tree

3 files changed

+67
-24
lines changed

3 files changed

+67
-24
lines changed

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

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,46 @@ def get(self, request: Request, project, artifact_id) -> Response:
126126
)
127127

128128
vcs_info = BuildDetailsVcsInfo(
129-
commit_id=preprod_artifact.commit.key if preprod_artifact.commit else None,
130-
# TODO: Implement in the future when available
131-
# repo=None,
132-
# provider=None,
133-
# branch=None,
129+
head_sha=(
130+
preprod_artifact.commit_comparison.head_sha
131+
if preprod_artifact.commit_comparison
132+
else None
133+
),
134+
base_sha=(
135+
preprod_artifact.commit_comparison.base_sha
136+
if preprod_artifact.commit_comparison
137+
else None
138+
),
139+
provider=(
140+
preprod_artifact.commit_comparison.provider
141+
if preprod_artifact.commit_comparison
142+
else None
143+
),
144+
head_repo_name=(
145+
preprod_artifact.commit_comparison.head_repo_name
146+
if preprod_artifact.commit_comparison
147+
else None
148+
),
149+
base_repo_name=(
150+
preprod_artifact.commit_comparison.base_repo_name
151+
if preprod_artifact.commit_comparison
152+
else None
153+
),
154+
head_ref=(
155+
preprod_artifact.commit_comparison.head_ref
156+
if preprod_artifact.commit_comparison
157+
else None
158+
),
159+
base_ref=(
160+
preprod_artifact.commit_comparison.base_ref
161+
if preprod_artifact.commit_comparison
162+
else None
163+
),
164+
pr_number=(
165+
preprod_artifact.commit_comparison.pr_number
166+
if preprod_artifact.commit_comparison
167+
else None
168+
),
134169
)
135170

136171
api_response = BuildDetailsApiResponse(

src/sentry/preprod/api/models/project_preprod_build_details_models.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ class BuildDetailsAppInfo(BaseModel):
2626

2727

2828
class BuildDetailsVcsInfo(BaseModel):
29-
commit_id: str | None = None
30-
# repo: Optional[str] = None # Uncomment when available
31-
# provider: Optional[str] = None # Uncomment when available
32-
# branch: Optional[str] = None # Uncomment when available
29+
head_sha: str | None = None
30+
base_sha: str | None = None
31+
provider: str | None = None
32+
head_repo_name: str | None = None
33+
base_repo_name: str | None = None
34+
head_ref: str | None = None
35+
base_ref: str | None = None
36+
pr_number: int | None = None
3337

3438

3539
class BuildDetailsSizeInfo(BaseModel):

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

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from django.urls import reverse
22

3-
from sentry.models.commit import Commit
3+
from sentry.models.commitcomparison import CommitComparison
44
from sentry.preprod.models import PreprodArtifact
55
from sentry.testutils.cases import APITestCase
66

@@ -18,10 +18,16 @@ def setUp(self) -> None:
1818

1919
self.file = self.create_file(name="test_artifact.apk", type="application/octet-stream")
2020

21-
self.commit = Commit.objects.create(
21+
commit_comparison = CommitComparison.objects.create(
2222
organization_id=self.org.id,
23-
repository_id=1,
24-
key="abcdef1234567890",
23+
head_sha="1234567890098765432112345678900987654321",
24+
base_sha="9876543210012345678998765432100123456789",
25+
provider="github",
26+
head_repo_name="owner/repo",
27+
base_repo_name="owner/repo",
28+
head_ref="feature/xyz",
29+
base_ref="main",
30+
pr_number=123,
2531
)
2632

2733
self.preprod_artifact = PreprodArtifact.objects.create(
@@ -35,7 +41,7 @@ def setUp(self) -> None:
3541
build_number=42,
3642
build_configuration_id=None,
3743
installable_app_file_id=1234,
38-
commit=self.commit,
44+
commit_comparison=commit_comparison,
3945
)
4046

4147
# Enable the feature flag for all tests by default
@@ -68,9 +74,6 @@ def test_get_build_details_success(self) -> None:
6874
assert resp_data["app_info"]["version"] == self.preprod_artifact.build_version
6975
assert resp_data["app_info"]["build_number"] == self.preprod_artifact.build_number
7076
assert resp_data["app_info"]["artifact_type"] == self.preprod_artifact.artifact_type
71-
assert resp_data["vcs_info"]["commit_id"] == (
72-
self.preprod_artifact.commit.key if self.preprod_artifact.commit is not None else None
73-
)
7477

7578
def test_get_build_details_not_found(self) -> None:
7679
url = self._get_url(artifact_id=999999)
@@ -108,12 +111,6 @@ def test_get_build_details_dates_and_types(self) -> None:
108111
assert isinstance(resp_data["app_info"]["artifact_type"], int)
109112

110113
def test_get_build_details_vcs_info(self) -> None:
111-
new_commit = Commit.objects.create(
112-
organization_id=self.org.id,
113-
repository_id=1,
114-
key="deadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
115-
)
116-
self.preprod_artifact.commit = new_commit
117114
self.preprod_artifact.save()
118115

119116
url = self._get_url()
@@ -122,4 +119,11 @@ def test_get_build_details_vcs_info(self) -> None:
122119
)
123120
assert response.status_code == 200
124121
resp_data = response.json()
125-
assert resp_data["vcs_info"]["commit_id"] == "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
122+
assert resp_data["vcs_info"]["head_sha"] == "1234567890098765432112345678900987654321"
123+
assert resp_data["vcs_info"]["base_sha"] == "9876543210012345678998765432100123456789"
124+
assert resp_data["vcs_info"]["provider"] == "github"
125+
assert resp_data["vcs_info"]["head_repo_name"] == "owner/repo"
126+
assert resp_data["vcs_info"]["base_repo_name"] == "owner/repo"
127+
assert resp_data["vcs_info"]["head_ref"] == "feature/xyz"
128+
assert resp_data["vcs_info"]["base_ref"] == "main"
129+
assert resp_data["vcs_info"]["pr_number"] == 123

0 commit comments

Comments
 (0)