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

Commit 459bbbf

Browse files
Update
1 parent 64e5282 commit 459bbbf

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

webhook_handlers/tests/test_github.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ def mock_webhook_secret(self, mocker):
6161

6262
@pytest.fixture(autouse=True)
6363
def mock_ai_features_app_id(self, mocker):
64-
mock_config_helper(
65-
mocker, configs={"github.ai_features_app_id": AI_FEATURES_GH_APP_ID}
66-
)
64+
mock_config_helper(mocker, configs={"github.ai_features_app_id": 9999})
6765

6866
@pytest.fixture(autouse=True)
6967
def mock_default_app_id(self, mocker):
@@ -1456,7 +1454,7 @@ def test_check_codecov_ai_auto_enabled_reviews_enabled(self):
14561454
},
14571455
},
14581456
},
1459-
app_id=AI_FEATURES_GH_APP_ID,
1457+
app_id=9999,
14601458
)
14611459
assert response.data == {"auto_review_enabled": True}
14621460

@@ -1478,7 +1476,7 @@ def test_check_codecov_ai_auto_enabled_reviews_disabled(self):
14781476
"owner": {"id": org_with_ai_disabled.service_id},
14791477
},
14801478
},
1481-
app_id=AI_FEATURES_GH_APP_ID,
1479+
app_id=9999,
14821480
)
14831481
assert response.data == {"auto_review_enabled": False}
14841482

@@ -1498,7 +1496,7 @@ def test_check_codecov_ai_auto_enabled_reviews_no_config(self):
14981496
"owner": {"id": org_with_no_config.service_id},
14991497
},
15001498
},
1501-
app_id=AI_FEATURES_GH_APP_ID,
1499+
app_id=9999,
15021500
)
15031501
assert response.data == {"auto_review_enabled": False}
15041502

@@ -1520,6 +1518,6 @@ def test_check_codecov_ai_auto_enabled_reviews_partial_config(self):
15201518
"owner": {"id": org_with_partial_config.service_id},
15211519
},
15221520
},
1523-
app_id=AI_FEATURES_GH_APP_ID,
1521+
app_id=9999,
15241522
)
15251523
assert response.data == {"auto_review_enabled": False}

webhook_handlers/views/github.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838

3939
# This should probably go somewhere where it can be easily shared
4040
regexp_ci_skip = re.compile(r"\[(ci|skip| |-){3,}\]").search
41-
AI_FEATURES_GH_APP_ID = get_config("github", "ai_features_app_id")
4241

4342

4443
class GithubWebhookHandler(APIView):
@@ -53,6 +52,10 @@ class GithubWebhookHandler(APIView):
5352

5453
service_name = "github"
5554

55+
@property
56+
def ai_features_app_id(self):
57+
return get_config("github", "ai_features_app_id")
58+
5659
def _inc_recv(self):
5760
action = self.request.data.get("action", "")
5861
WEBHOOKS_RECEIVED.labels(
@@ -367,7 +370,7 @@ def status(self, request, *args, **kwargs):
367370

368371
def _is_ai_features_request(self, request):
369372
target_id = request.META.get(GitHubHTTPHeaders.HOOK_INSTALLATION_TARGET_ID, "")
370-
return str(target_id) == str(AI_FEATURES_GH_APP_ID)
373+
return str(target_id) == str(self.ai_features_app_id)
371374

372375
def pull_request(self, request, *args, **kwargs):
373376
if self._is_ai_features_request(request):
@@ -407,17 +410,10 @@ def pull_request(self, request, *args, **kwargs):
407410
return Response()
408411

409412
def check_codecov_ai_auto_enabled_reviews(self, request):
410-
try:
411-
org = Owner.objects.get(
412-
service=self.service_name,
413-
service_id=request.data["repository"]["owner"]["id"],
414-
)
415-
except Owner.DoesNotExist:
416-
return Response(
417-
data={
418-
"auto_review_enabled": False,
419-
}
420-
)
413+
org = Owner.objects.get(
414+
service=self.service_name,
415+
service_id=request.data["repository"]["owner"]["id"],
416+
)
421417

422418
auto_review_enabled = org.yaml.get("ai_pr_review", {}).get("auto_review", False)
423419
return Response(

0 commit comments

Comments
 (0)