This repository was archived by the owner on Jun 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
[feat] Check if auto PR reviews are enabled for a given owner #1285
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
abadaf4
initial commit
rohitvinnakota-codecov a388eec
Add Tests for PR#1285 (#1286)
codecov-ai[bot] 736052b
Merge branch 'main' into rvinnakota/ai-yaml-updates
rohitvinnakota-codecov 64e5282
Add try catch
rohitvinnakota-codecov 459bbbf
Update
rohitvinnakota-codecov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,10 @@ class GithubWebhookHandler(APIView): | |
|
||
service_name = "github" | ||
|
||
@property | ||
def ai_features_app_id(self): | ||
return get_config("github", "ai_features_app_id") | ||
|
||
def _inc_recv(self): | ||
action = self.request.data.get("action", "") | ||
WEBHOOKS_RECEIVED.labels( | ||
|
@@ -364,7 +368,14 @@ def status(self, request, *args, **kwargs): | |
|
||
return Response() | ||
|
||
def _is_ai_features_request(self, request): | ||
target_id = request.META.get(GitHubHTTPHeaders.HOOK_INSTALLATION_TARGET_ID, "") | ||
return str(target_id) == str(self.ai_features_app_id) | ||
rohitvinnakota-codecov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def pull_request(self, request, *args, **kwargs): | ||
if self._is_ai_features_request(request): | ||
return self.check_codecov_ai_auto_enabled_reviews(request) | ||
|
||
repo = self._get_repo(request) | ||
|
||
if not repo.active: | ||
|
@@ -398,6 +409,19 @@ def pull_request(self, request, *args, **kwargs): | |
|
||
return Response() | ||
|
||
def check_codecov_ai_auto_enabled_reviews(self, request): | ||
org = Owner.objects.get( | ||
service=self.service_name, | ||
service_id=request.data["repository"]["owner"]["id"], | ||
) | ||
|
||
auto_review_enabled = org.yaml.get("ai_pr_review", {}).get("auto_review", False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note for later: think whether you want to use the full yaml vs the org yaml or any variant |
||
return Response( | ||
data={ | ||
"auto_review_enabled": auto_review_enabled, | ||
} | ||
rohitvinnakota-codecov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
rohitvinnakota-codecov marked this conversation as resolved.
Show resolved
Hide resolved
rohitvinnakota-codecov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def _decide_app_name(self, ghapp: GithubAppInstallation) -> str: | ||
"""Possibly updated the name of a GithubAppInstallation that has been fetched from DB or created. | ||
Only the real default installation maybe use the name `GITHUB_APP_INSTALLATION_DEFAULT_NAME` | ||
|
@@ -520,9 +544,11 @@ def _handle_installation_events( | |
AmplitudeEventPublisher().publish( | ||
"App Installed", | ||
{ | ||
"user_ownerid": installer.ownerid | ||
if installer is not None | ||
else owner.ownerid, | ||
"user_ownerid": ( | ||
installer.ownerid | ||
if installer is not None | ||
else owner.ownerid | ||
), | ||
"ownerid": owner.ownerid, | ||
}, | ||
) | ||
|
@@ -751,7 +777,6 @@ def post(self, request, *args, **kwargs): | |
delivery=self.request.META.get(GitHubHTTPHeaders.DELIVERY_TOKEN), | ||
), | ||
) | ||
|
||
self.validate_signature(request) | ||
|
||
if handler := getattr(self, self.event, None): | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.