Skip to content

Commit

Permalink
feat(insights): Record all instances of `SET_RESOLVED_IN_PULL_REQUEST…
Browse files Browse the repository at this point in the history
…` activity in `GroupHistory` (#29466)

We missed a spot here, just simplifying the code to make it easier to catch all cases.
  • Loading branch information
wedamija authored Oct 21, 2021
1 parent 370466a commit 2de94c3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
36 changes: 15 additions & 21 deletions src/sentry/receivers/releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
21 changes: 13 additions & 8 deletions tests/sentry/models/test_pullrequest.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -23,14 +23,19 @@ def test_multiple_matches_basic(self):
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,
)

0 comments on commit 2de94c3

Please sign in to comment.