Browse Source

feat(insights): Record all instances of `SET_RESOLVED_IN_PULL_REQUEST` activity in `GroupHistory` (#29466)

We missed a spot here, just simplifying the code to make it easier to catch all cases.
Dan Fuller 3 years ago
parent
commit
2de94c3837
2 changed files with 28 additions and 29 deletions
  1. 15 21
      src/sentry/receivers/releases.py
  2. 13 8
      tests/sentry/models/test_pullrequest.py

+ 15 - 21
src/sentry/receivers/releases.py

@@ -189,30 +189,24 @@ def resolved_in_pull_request(instance, created, **kwargs):
                     user_list = list(instance.author.find_users())
                 else:
                     user_list = ()
+                acting_user = None
                 if user_list:
-                    Activity.objects.create(
-                        project_id=group.project_id,
-                        group=group,
-                        type=Activity.SET_RESOLVED_IN_PULL_REQUEST,
-                        ident=instance.id,
-                        user=user_list[0],
-                        data={"pull_request": instance.id},
-                    )
-                    record_group_history(
-                        group, GroupHistoryStatus.RESOLVED_IN_PULL_REQUEST, actor=user_list[0]
-                    )
-
+                    acting_user = user_list[0]
                     GroupAssignee.objects.assign(
-                        group=group, assigned_to=user_list[0], acting_user=user_list[0]
-                    )
-                else:
-                    Activity.objects.create(
-                        project_id=group.project_id,
-                        group=group,
-                        type=Activity.SET_RESOLVED_IN_PULL_REQUEST,
-                        ident=instance.id,
-                        data={"pull_request": instance.id},
+                        group=group, assigned_to=acting_user, acting_user=acting_user
                     )
+
+                Activity.objects.create(
+                    project_id=group.project_id,
+                    group=group,
+                    type=Activity.SET_RESOLVED_IN_PULL_REQUEST,
+                    ident=instance.id,
+                    user=acting_user,
+                    data={"pull_request": instance.id},
+                )
+                record_group_history(
+                    group, GroupHistoryStatus.SET_RESOLVED_IN_PULL_REQUEST, actor=acting_user
+                )
         except IntegrityError:
             pass
         else:

+ 13 - 8
tests/sentry/models/test_pullrequest.py

@@ -1,7 +1,7 @@
 from hashlib import sha1
 from uuid import uuid4
 
-from sentry.models import Commit, PullRequest, Repository
+from sentry.models import Commit, GroupHistory, GroupHistoryStatus, PullRequest, Repository
 from sentry.testutils import TestCase
 
 
@@ -23,14 +23,19 @@ class FindReferencedGroupsTest(TestCase):
         assert len(groups) == 1
         assert group in groups
 
-        pr = PullRequest.objects.create(
-            key="1",
-            repository_id=repo.id,
-            organization_id=group.organization.id,
-            title="very cool PR to fix the thing",
-            message=f"Foo Biz\n\nFixes {group2.qualified_short_id}",
-        )
+        with self.feature("organizations:group-history"):
+            pr = PullRequest.objects.create(
+                key="1",
+                repository_id=repo.id,
+                organization_id=group.organization.id,
+                title="very cool PR to fix the thing",
+                message=f"Foo Biz\n\nFixes {group2.qualified_short_id}",
+            )
 
         groups = pr.find_referenced_groups()
         assert len(groups) == 1
         assert group2 in groups
+        assert GroupHistory.objects.filter(
+            group=group2,
+            status=GroupHistoryStatus.SET_RESOLVED_IN_PULL_REQUEST,
+        )