Browse Source

feat(migrations): Set Auto-Assignment settings True by default (#39472)

## Objective:
We want to enable the auto-assignment settings for new projects and
projects that currently do not have any Ownership Rules or Code Owners
setup.
NisanthanNanthakumar 2 years ago
parent
commit
563f709b05

+ 1 - 1
migrations_lockfile.txt

@@ -6,5 +6,5 @@ To resolve this, rebase against latest master and regenerate your migration. Thi
 will then be regenerated, and you should be able to merge without conflicts.
 
 nodestore: 0002_nodestore_no_dictfield
-sentry: 0323_backfill_ownership_for_projects_with_codeowners
+sentry: 0324_set_auto_assignments_true_by_default
 social_auth: 0001_initial

+ 41 - 0
src/sentry/migrations/0324_set_auto_assignments_true_by_default.py

@@ -0,0 +1,41 @@
+# Generated by Django 2.2.28 on 2022-09-29 17:57
+
+from django.db import migrations, models
+
+from sentry.new_migrations.migrations import CheckedMigration
+
+
+class Migration(CheckedMigration):
+    # This flag is used to mark that a migration shouldn't be automatically run in production. For
+    # the most part, this should only be used for operations where it's safe to run the migration
+    # after your code has deployed. So this should not be used for most operations that alter the
+    # schema of a table.
+    # Here are some things that make sense to mark as dangerous:
+    # - Large data migrations. Typically we want these to be run manually by ops so that they can
+    #   be monitored and not block the deploy for a long period of time while they run.
+    # - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to
+    #   have ops run this and not block the deploy. Note that while adding an index is a schema
+    #   change, it's completely safe to run the operation after the code has deployed.
+    is_dangerous = False
+
+    # This flag is used to decide whether to run this migration in a transaction or not. Generally
+    # we don't want to run in a transaction here, since for long running operations like data
+    # back-fills this results in us locking an increasing number of rows until we finally commit.
+    atomic = False
+
+    dependencies = [
+        ("sentry", "0323_backfill_ownership_for_projects_with_codeowners"),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name="projectownership",
+            name="auto_assignment",
+            field=models.BooleanField(default=True),
+        ),
+        migrations.AlterField(
+            model_name="projectownership",
+            name="suspect_committer_auto_assignment",
+            field=models.BooleanField(default=True),
+        ),
+    ]

+ 2 - 2
src/sentry/models/projectownership.py

@@ -23,12 +23,12 @@ class ProjectOwnership(Model):
     schema = JSONField(null=True)
     fallthrough = models.BooleanField(default=True)
     # Auto Assignment through Ownership Rules & Code Owners
-    auto_assignment = models.BooleanField(default=False)
+    auto_assignment = models.BooleanField(default=True)
     date_created = models.DateTimeField(default=timezone.now)
     last_updated = models.DateTimeField(default=timezone.now)
     is_active = models.BooleanField(default=True)
     codeowners_auto_sync = models.BooleanField(default=True, null=True)
-    suspect_committer_auto_assignment = models.BooleanField(default=False)
+    suspect_committer_auto_assignment = models.BooleanField(default=True)
 
     # An object to indicate ownership is implicitly everyone
     Everyone = object()

+ 4 - 4
tests/sentry/api/endpoints/test_project_ownership.py

@@ -35,7 +35,7 @@ class ProjectOwnershipEndpointTestCase(APITestCase):
         assert resp.data == {
             "raw": None,
             "fallthrough": True,
-            "autoAssignment": False,
+            "autoAssignment": True,
             "isActive": True,
             "dateCreated": None,
             "lastUpdated": None,
@@ -46,7 +46,7 @@ class ProjectOwnershipEndpointTestCase(APITestCase):
         resp = self.client.put(self.path, {"raw": "*.js admin@localhost #tiger-team"})
         assert resp.status_code == 200
         assert resp.data["fallthrough"] is True
-        assert resp.data["autoAssignment"] is False
+        assert resp.data["autoAssignment"] is True
         assert resp.data["raw"] == "*.js admin@localhost #tiger-team"
         assert resp.data["dateCreated"] is not None
         assert resp.data["lastUpdated"] is not None
@@ -55,7 +55,7 @@ class ProjectOwnershipEndpointTestCase(APITestCase):
         resp = self.client.put(self.path, {"fallthrough": False})
         assert resp.status_code == 200
         assert resp.data["fallthrough"] is False
-        assert resp.data["autoAssignment"] is False
+        assert resp.data["autoAssignment"] is True
         assert resp.data["raw"] == "*.js admin@localhost #tiger-team"
         assert resp.data["dateCreated"] is not None
         assert resp.data["lastUpdated"] is not None
@@ -64,7 +64,7 @@ class ProjectOwnershipEndpointTestCase(APITestCase):
         resp = self.client.get(self.path)
         assert resp.status_code == 200
         assert resp.data["fallthrough"] is False
-        assert resp.data["autoAssignment"] is False
+        assert resp.data["autoAssignment"] is True
         assert resp.data["raw"] == "*.js admin@localhost #tiger-team"
         assert resp.data["dateCreated"] is not None
         assert resp.data["lastUpdated"] is not None

+ 5 - 5
tests/sentry/models/test_projectownership.py

@@ -160,7 +160,7 @@ class ProjectOwnershipTestCase(TestCase):
 
         # No data matches
         assert ProjectOwnership.get_autoassign_owners(self.project.id, {}) == (
-            False,
+            True,
             [],
             False,
             None,
@@ -171,7 +171,7 @@ class ProjectOwnershipTestCase(TestCase):
         assert ProjectOwnership.get_autoassign_owners(
             self.project.id,
             {"stacktrace": {"frames": [{"filename": "foo.py"}]}},
-        ) == (False, [self.team], False, rule_a, [OwnerRuleType.OWNERSHIP_RULE.value])
+        ) == (True, [self.team], False, rule_a, [OwnerRuleType.OWNERSHIP_RULE.value])
 
         # autoassignment is True
         owner = ProjectOwnership.objects.get(project_id=self.project.id)
@@ -200,7 +200,7 @@ class ProjectOwnershipTestCase(TestCase):
         )
         # No data matches
         assert ProjectOwnership.get_autoassign_owners(self.project.id, {}) == (
-            False,
+            True,
             [],
             False,
             None,
@@ -210,7 +210,7 @@ class ProjectOwnershipTestCase(TestCase):
         # No autoassignment on match
         assert ProjectOwnership.get_autoassign_owners(
             self.project.id, {"stacktrace": {"frames": [{"filename": "foo.js"}]}}
-        ) == (False, [self.team], True, rule_a, [OwnerRuleType.CODEOWNERS.value])
+        ) == (True, [self.team], True, rule_a, [OwnerRuleType.CODEOWNERS.value])
 
     def test_get_autoassign_owners_when_codeowners_and_issueowners_exists(self):
         self.team = self.create_team(
@@ -240,7 +240,7 @@ class ProjectOwnershipTestCase(TestCase):
         assert ProjectOwnership.get_autoassign_owners(
             self.project.id, {"stacktrace": {"frames": [{"filename": "api/foo.py"}]}}
         ) == (
-            False,
+            True,
             [self.team, self.team2],
             False,
             rule_a,