Skip to content

Conversation

@jasonyuezhang
Copy link
Owner

For seer launch Dec 15, there's a toggle where an org can turn on auto-enable code review on repos. As in sentry org turns this toggle on, they add a new repo in github that has sentry github app installed on it, that means we should consider this repo enabled for code review.
For new repos, they get written to sentry_repository table upon repositoryCreated gh webhook, or if the user manually adds the repo using sentry UI.
Instead of doing this by finding every existing repo.objects.create (and remembering to do it if any new cases arise), probably most durable to add as a signal. There are downsides to using signals but it seems like a common pattern across sentry codebase to use these.

Add that signal handler in this PR

Closes https://linear.app/getsentry/issue/ENG-6094/handle-auto-enable-code-review-org-setting

Depends on getsentry#104645


Copied from getsentry#104666
Original PR: getsentry#104666

@propel-test-bot
Copy link

Auto-enable code review when a new repository is created

Adds a post_save hook on Repository that automatically creates a RepositorySettings row with enabled_code_review=True for GitHub-backed repositories when the organization option sentry:auto_enable_code_review is turned on. Default review triggers are copied from sentry:default_code_review_triggers if present. Comprehensive tests cover opt-in/out cases, invalid trigger types, unsupported providers, and idempotency on repo updates.

Key Changes

• Added handle_auto_enable_code_review() and on_repository_created() in src/sentry/models/repository.py and connected them via post_save
• Created RepositorySettings row only for supported providers (integrations:github) and when org option is enabled
• Gracefully handles non-list trigger values by falling back to an empty list
• Prevents duplicate settings via get_or_create
• Extended tests/sentry/models/test_repository.py with 6 new test cases covering success, opt-out, triggers list, invalid trigger type, unsupported provider, and idempotent update

Affected Areas

src/sentry/models/repository.py signal wiring and business logic
RepositorySettings table write path
• Unit tests for repository model

This summary was automatically generated by @propel-code-bot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants