Skip to content

Commit 3de8ad8

Browse files
fix check run billing gate
1 parent 1a69e22 commit 3de8ad8

File tree

4 files changed

+67
-57
lines changed

4 files changed

+67
-57
lines changed

fixtures/github.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3560,7 +3560,7 @@
35603560
"external_id": "4663713",
35613561
"html_url": "https://github.com/test/repo/runs/4"
35623562
},
3563-
"user": {
3563+
"sender": {
35643564
"id": 12345678,
35653565
"login": "test-user"
35663566
}
@@ -3574,7 +3574,7 @@
35743574
"full_name": "getsentry/sentry",
35753575
"html_url": "https://github.com/getsentry/sentry"
35763576
},
3577-
"user": {
3577+
"sender": {
35783578
"id": 12345678,
35793579
"login": "test-user"
35803580
}

src/sentry/seer/code_review/preflight.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
from sentry.models.repository import Repository
1010
from sentry.models.repositorysettings import CodeReviewSettings, RepositorySettings
1111

12-
from .billing import passes_code_review_billing_check
13-
1412
DenialReason = str | None
1513

1614

@@ -91,6 +89,8 @@ def _check_repo_feature_enablement(self) -> DenialReason:
9189
return "repo_code_review_disabled"
9290

9391
def _check_billing(self) -> DenialReason:
92+
# TODO: Once we're ready to actually gate billing (when it's time for GA), uncomment this
93+
"""
9494
if self.integration_id is None or self.pr_author_external_id is None:
9595
return "billing_missing_contributor_info"
9696
@@ -101,6 +101,7 @@ def _check_billing(self) -> DenialReason:
101101
)
102102
if not billing_ok:
103103
return "billing_quota_exceeded"
104+
"""
104105

105106
return None
106107

src/sentry/seer/code_review/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,8 @@ def get_pr_author_id(event: Mapping[str, Any]) -> str | None:
220220
if (user_id := event.get("user", {}).get("id")) is not None:
221221
return str(user_id)
222222

223+
# Check sender.id (for check_run events). Sender is the user who triggered the event
224+
if (user_id := event.get("sender", {}).get("id")) is not None:
225+
return str(user_id)
226+
223227
return None

tests/sentry/seer/code_review/test_preflight.py

Lines changed: 58 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,67 @@ def test_allowed_when_seat_based_org_has_repo_settings_enabled(
168168
assert result.settings is not None
169169
assert result.settings.enabled is True
170170

171+
# -------------------------------------------------------------------------
172+
# Settings retrieval tests
173+
# -------------------------------------------------------------------------
174+
175+
@patch("sentry.seer.code_review.billing.quotas.backend.check_seer_quota")
176+
@with_feature(["organizations:gen-ai-features", "organizations:seat-based-seer-enabled"])
177+
def test_returns_repo_settings_when_allowed(self, mock_check_quota: MagicMock) -> None:
178+
mock_check_quota.return_value = True
179+
180+
RepositorySettings.objects.create(
181+
repository=self.repo,
182+
enabled_code_review=True,
183+
code_review_triggers=[
184+
CodeReviewTrigger.ON_COMMAND_PHRASE.value,
185+
CodeReviewTrigger.ON_READY_FOR_REVIEW.value,
186+
],
187+
)
188+
189+
OrganizationContributors.objects.create(
190+
organization_id=self.organization.id,
191+
integration_id=self.integration.id,
192+
external_identifier=self.external_identifier,
193+
)
194+
195+
service = self._create_service()
196+
result = service.check()
197+
198+
assert result.allowed is True
199+
assert result.settings is not None
200+
assert result.settings.enabled is True
201+
assert CodeReviewTrigger.ON_COMMAND_PHRASE in result.settings.triggers
202+
assert CodeReviewTrigger.ON_READY_FOR_REVIEW in result.settings.triggers
203+
204+
@patch("sentry.seer.code_review.billing.quotas.backend.check_seer_quota")
205+
@with_feature(["organizations:gen-ai-features", "organizations:code-review-beta"])
206+
def test_returns_none_settings_for_beta_org_without_repo_settings(
207+
self, mock_check_quota: MagicMock
208+
) -> None:
209+
mock_check_quota.return_value = True
210+
211+
self.organization.update_option("sentry:enable_pr_review_test_generation", True)
212+
213+
OrganizationContributors.objects.create(
214+
organization_id=self.organization.id,
215+
integration_id=self.integration.id,
216+
external_identifier=self.external_identifier,
217+
)
218+
219+
service = self._create_service()
220+
result = service.check()
221+
222+
assert result.allowed is True
223+
assert result.settings is None
224+
171225
# -------------------------------------------------------------------------
172226
# Billing tests
173227
# -------------------------------------------------------------------------
174228

229+
230+
# TODO: Uncomment these billing tests once we're ready to actually gate billing (when it's time for GA)
231+
"""
175232
@with_feature(["organizations:gen-ai-features", "organizations:code-review-beta"])
176233
def test_denied_when_missing_integration_id(self) -> None:
177234
self.organization.update_option("sentry:enable_pr_review_test_generation", True)
@@ -231,56 +288,4 @@ def test_denied_when_quota_check_fails(self, mock_check_quota: MagicMock) -> Non
231288
assert result.allowed is False
232289
assert result.denial_reason == "billing_quota_exceeded"
233290
234-
# -------------------------------------------------------------------------
235-
# Settings retrieval tests
236-
# -------------------------------------------------------------------------
237-
238-
@patch("sentry.seer.code_review.billing.quotas.backend.check_seer_quota")
239-
@with_feature(["organizations:gen-ai-features", "organizations:seat-based-seer-enabled"])
240-
def test_returns_repo_settings_when_allowed(self, mock_check_quota: MagicMock) -> None:
241-
mock_check_quota.return_value = True
242-
243-
RepositorySettings.objects.create(
244-
repository=self.repo,
245-
enabled_code_review=True,
246-
code_review_triggers=[
247-
CodeReviewTrigger.ON_COMMAND_PHRASE.value,
248-
CodeReviewTrigger.ON_READY_FOR_REVIEW.value,
249-
],
250-
)
251-
252-
OrganizationContributors.objects.create(
253-
organization_id=self.organization.id,
254-
integration_id=self.integration.id,
255-
external_identifier=self.external_identifier,
256-
)
257-
258-
service = self._create_service()
259-
result = service.check()
260-
261-
assert result.allowed is True
262-
assert result.settings is not None
263-
assert result.settings.enabled is True
264-
assert CodeReviewTrigger.ON_COMMAND_PHRASE in result.settings.triggers
265-
assert CodeReviewTrigger.ON_READY_FOR_REVIEW in result.settings.triggers
266-
267-
@patch("sentry.seer.code_review.billing.quotas.backend.check_seer_quota")
268-
@with_feature(["organizations:gen-ai-features", "organizations:code-review-beta"])
269-
def test_returns_none_settings_for_beta_org_without_repo_settings(
270-
self, mock_check_quota: MagicMock
271-
) -> None:
272-
mock_check_quota.return_value = True
273-
274-
self.organization.update_option("sentry:enable_pr_review_test_generation", True)
275-
276-
OrganizationContributors.objects.create(
277-
organization_id=self.organization.id,
278-
integration_id=self.integration.id,
279-
external_identifier=self.external_identifier,
280-
)
281-
282-
service = self._create_service()
283-
result = service.check()
284-
285-
assert result.allowed is True
286-
assert result.settings is None
291+
"""

0 commit comments

Comments
 (0)