Skip to content

[feat] Check if auto PR reviews are enabled for a given owner #1285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 23, 2025

Conversation

rohitvinnakota-codecov
Copy link
Contributor

Purpose/Motivation

What is the feature? Why is this being done?

This will be consumed in shelter. Forwarded pull request webhooks from codecov AI will check if the user has configured an auto-review setting for their org. If they have, the resulting response will be used upstream to kick off a review PR flow in seer.

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

Copy link
Contributor

sentry-autofix bot commented Apr 11, 2025

🚨 Sentry detected 1 potential issue in your recent changes 🚨

Lower risk findings

Did you find this useful? React with a 👍 or 👎

@codecov-notifications
Copy link

codecov-notifications bot commented Apr 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Copy link

codecov bot commented Apr 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.35%. Comparing base (d3f7e91) to head (459bbbf).
Report is 8 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1285   +/-   ##
=======================================
  Coverage   96.35%   96.35%           
=======================================
  Files         488      488           
  Lines       16919    16932   +13     
=======================================
+ Hits        16302    16315   +13     
  Misses        617      617           
Flag Coverage Δ
unit 96.35% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rohitvinnakota-codecov
Copy link
Contributor Author

@codecov-ai-reviewer test

Copy link
Contributor

codecov-ai bot commented Apr 11, 2025

On it! Codecov is generating unit tests for this PR.

@codecov-ai codecov-ai bot mentioned this pull request Apr 11, 2025
codecov-ai bot and others added 2 commits April 14, 2025 12:20
Co-authored-by: codecov-ai[bot] <156709835+codecov-ai[bot]@users.noreply.github.com>
Co-authored-by: Rohit <rohit.vinnakota@sentry.io>
@rohitvinnakota-codecov
Copy link
Contributor Author

@codecov-ai-reviewer review

Copy link
Contributor

codecov-ai bot commented Apr 14, 2025

On it! We are reviewing the PR and will provide feedback shortly.

Comment on lines 368 to 372
def pull_request(self, request, *args, **kwargs):
if (
request.META.get(GitHubHTTPHeaders.HOOK_INSTALLATION_TARGET_ID, "")
== AI_FEATURES_GH_APP_ID
):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string comparison with AI_FEATURES_GH_APP_ID could be unsafe if the types don't match. Consider adding type conversion to ensure robust comparison. Also, consider extracting this check into a helper method for better readability and reusability.

Suggested change
def pull_request(self, request, *args, **kwargs):
if (
request.META.get(GitHubHTTPHeaders.HOOK_INSTALLATION_TARGET_ID, "")
== AI_FEATURES_GH_APP_ID
):
def _is_ai_features_request(self, request):
target_id = request.META.get(GitHubHTTPHeaders.HOOK_INSTALLATION_TARGET_ID, '')
return str(target_id) == str(AI_FEATURES_GH_APP_ID)
def pull_request(self, request, *args, **kwargs):
if self._is_ai_features_request(request):
return self.check_codecov_ai_auto_enabled_reviews(request)

@rohitvinnakota-codecov
Copy link
Contributor Author

On it! We are reviewing the PR and will provide feedback shortly.

@rohitvinnakota-codecov
Copy link
Contributor Author

PR Description:

Here's a detailed analysis of this pull request:

Purpose

This PR implements a webhook-based mechanism to check if AI-powered code reviews should be automatically triggered for GitHub pull requests. It's part of a larger AI features integration system that appears to be controlled by a separate GitHub App installation.

Key Technical Changes

  1. Configuration and Infrastructure
  • Adds a new GitHub webhook header constant HOOK_INSTALLATION_TARGET_ID to identify requests from specific GitHub App installations
  • Introduces configuration for an AI features app ID, separate from the default app ID
  • Sets up the foundation for differentiating webhook requests between multiple GitHub Apps
  1. Feature Detection Logic
  • Implements a new endpoint handler that checks if automatic AI reviews are enabled for a repository
  • Uses organization-level YAML configuration to control the feature (ai_pr_review.auto_review setting)
  • Intercepts pull request webhooks to determine if they should trigger AI reviews
  1. Testing Infrastructure
  • Comprehensive test coverage for various configuration scenarios:
    • Explicitly enabled AI reviews
    • Explicitly disabled AI reviews
    • Missing configuration
    • Partial configuration
  • Uses factory patterns for test data generation
  • Mocks configuration values for consistent testing

Architecture Decisions

  1. Feature Toggle Design
  • Uses YAML-based configuration at the organization level, allowing granular control
  • Follows an opt-in model where the feature is disabled by default
  • Separates the feature check from the actual review implementation
  1. Multi-App Architecture
  • Implements a pattern for handling webhooks from multiple GitHub App installations
  • Uses the installation target ID to route requests to appropriate handlers
  • Maintains backward compatibility with existing webhook handling

Dependencies and Interactions

  1. System Dependencies
  • Relies on existing Owner model and YAML configuration system
  • Integrates with existing webhook validation and handling infrastructure
  • Uses the GitHub Apps installation system
  1. External Dependencies
  • Requires GitHub webhook delivery with installation target ID
  • Depends on proper GitHub App installation and configuration

Risk Considerations

  1. Operational Risks
  • New webhook handling path could affect existing webhook processing
  • Additional database queries for configuration checks
  • Potential for increased API latency due to additional checks
  1. Security Considerations
  • Maintains existing webhook signature validation
  • Properly validates GitHub App installation IDs
  • Uses existing security patterns for webhook handling

Notable Implementation Details

  • Clean separation of concerns between feature detection and implementation
  • Extensive test coverage for different configuration scenarios
  • Maintains existing error handling patterns
  • Uses property decorators for configuration access
  • Follows existing coding patterns for webhook handling

This PR appears to be laying the groundwork for a larger AI-powered code review feature while maintaining a clean separation of concerns and following existing architectural patterns. The implementation is well-tested and includes appropriate error handling and validation.

service_id=request.data["repository"]["owner"]["id"],
)

auto_review_enabled = org.yaml.get("ai_pr_review", {}).get("auto_review", False)
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Merged via the queue into main with commit d3b6462 Apr 23, 2025
23 of 24 checks passed
@rohitvinnakota-codecov rohitvinnakota-codecov deleted the rvinnakota/ai-yaml-updates branch April 23, 2025 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants