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

Commit abadaf4

Browse files
initial commit
1 parent e493767 commit abadaf4

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

webhook_handlers/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ class GitHubHTTPHeaders:
33
DELIVERY_TOKEN = "HTTP_X_GITHUB_DELIVERY"
44
SIGNATURE = "HTTP_X_HUB_SIGNATURE"
55
SIGNATURE_256 = "HTTP_X_HUB_SIGNATURE_256"
6+
HOOK_INSTALLATION_TARGET_ID = "HTTP_X_GITHUB_HOOK_INSTALLATION_TARGET_ID"
67

78

89
class GitHubWebhookEvents:

webhook_handlers/views/github.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,9 @@ def status(self, request, *args, **kwargs):
365365
return Response()
366366

367367
def pull_request(self, request, *args, **kwargs):
368+
if request.headers.get(GitHubHTTPHeaders.HOOK_INSTALLATION_TARGET_ID):
369+
return self.check_codecov_ai_auto_enabled_reviews(request)
370+
368371
repo = self._get_repo(request)
369372

370373
if not repo.active:
@@ -398,6 +401,18 @@ def pull_request(self, request, *args, **kwargs):
398401

399402
return Response()
400403

404+
def check_codecov_ai_auto_enabled_reviews(self, request):
405+
org = Owner.objects.get(
406+
service=self.service_name,
407+
service_id=request.data["organization"]["id"],
408+
)
409+
auto_review_enabled = org.yaml.get("ai_pr_review", {}).get("auto_review", False)
410+
return Response(
411+
data={
412+
"auto_review_enabled": auto_review_enabled,
413+
}
414+
)
415+
401416
def _decide_app_name(self, ghapp: GithubAppInstallation) -> str:
402417
"""Possibly updated the name of a GithubAppInstallation that has been fetched from DB or created.
403418
Only the real default installation maybe use the name `GITHUB_APP_INSTALLATION_DEFAULT_NAME`
@@ -520,9 +535,11 @@ def _handle_installation_events(
520535
AmplitudeEventPublisher().publish(
521536
"App Installed",
522537
{
523-
"user_ownerid": installer.ownerid
524-
if installer is not None
525-
else owner.ownerid,
538+
"user_ownerid": (
539+
installer.ownerid
540+
if installer is not None
541+
else owner.ownerid
542+
),
526543
"ownerid": owner.ownerid,
527544
},
528545
)

0 commit comments

Comments
 (0)