Skip to content

Conversation

@suejung-sentry
Copy link
Member

@suejung-sentry suejung-sentry commented Dec 10, 2025

For seer launch, 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 #104645

@linear
Copy link

linear bot commented Dec 10, 2025

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Dec 10, 2025
@codecov
Copy link

codecov bot commented Dec 10, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff             @@
##           master   #104666      +/-   ##
===========================================
+ Coverage   79.21%    80.55%   +1.34%     
===========================================
  Files        9364      9335      -29     
  Lines      401865    400792    -1073     
  Branches    25834     25610     -224     
===========================================
+ Hits       318352    322876    +4524     
+ Misses      83071     77468    -5603     
- Partials      442       448       +6     

Comment on lines 203 to 212
if OrganizationOption.objects.get_value(
organization=instance.organization_id,
key="sentry:auto_enable_code_review",
default=False,
):
triggers = OrganizationOption.objects.get_value(
organization=instance.organization_id,
key="sentry:default_code_review_triggers",
default=[],
)
Copy link
Member

@ryan953 ryan953 Dec 10, 2025

Choose a reason for hiding this comment

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

Pointing out that we're only going to save triggers when the default is to enable code review. So we won't have extra rows representing repo's that might never have code-review enabled.

Therefore: If the default is Not to automatically enable code-review for a this repo, then we don't save a record into out RepositorySettings table.
Instead, later the user can still manually enable code-review for this repo, and at that time, in the UI, default trigger setting will be presented to the user. 💯

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup correct, that was my intent - good summary. I wanted to minimize the number of writes we're doing to this new table and err on the side of if there is no row, no user has ever actively chosen a setting.
I thought this paradigm would give us more flexibility in the future to change any programmatic default behavior

@suejung-sentry
Copy link
Member Author

Pinged integrations team for review, too - will merge after that!

@suejung-sentry suejung-sentry requested a review from a team December 11, 2025 02:28
Copy link
Contributor

@ajay-sentry ajay-sentry left a comment

Choose a reason for hiding this comment

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

lgtm! small stuff

handle_auto_enable_code_review(instance)


post_save.connect(on_repository_created, sender=Repository, weak=False)
Copy link
Member

Choose a reason for hiding this comment

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

After talking through this a bit more with @kcons, I think we should move this to override the Repository model's save method, ensuring both of these models are created within a transaction. It's a bit safer, and it's a pattern we follow for our outboxes, which have similar concerns.

Copy link
Member Author

Choose a reason for hiding this comment

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

That makes sense to me. Making the changes now!

@suejung-sentry suejung-sentry merged commit 557a28e into master Dec 12, 2025
66 checks passed
@suejung-sentry suejung-sentry deleted the sshin/auto-enable-code-review branch December 12, 2025 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants