Skip to content

Commit cdf4bd2

Browse files
authored
chore(slack): suspect commit small refactor (#70914)
1 parent be135cd commit cdf4bd2

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/sentry/integrations/slack/message_builder/issues.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,16 +324,16 @@ def get_suspect_commit_text(group: Group) -> str | None:
324324
return None
325325

326326
suspect_commit_text = "Suspect Commit: "
327-
pull_request = PullRequest.objects.filter(
328-
merge_commit_sha=commit.key, organization_id=group.project.organization_id
329-
).first()
330327

331328
author = commit.author
332329
commit_id = commit.key
333330
if not (author and commit_id): # we need both the author and commit id to continue
334331
return None
335332

336333
author_display = author.name if author.name else author.email
334+
pull_request = PullRequest.objects.filter(
335+
merge_commit_sha=commit.key, organization_id=group.project.organization_id
336+
).first()
337337
if pull_request:
338338
repo = Repository.objects.get(id=pull_request.repository_id)
339339
repo_base = repo.url

src/sentry/models/group.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -807,13 +807,20 @@ def get_recommended_event_for_environments(
807807
def get_suspect_commit(self) -> Commit | None:
808808
from sentry.models.groupowner import GroupOwner, GroupOwnerType
809809

810-
suspect_commit_owner = GroupOwner.objects.filter(
811-
group_id=self.id, project_id=self.project_id, type=GroupOwnerType.SUSPECT_COMMIT.value
810+
suspect_commit_owner = (
811+
GroupOwner.objects.filter(
812+
group_id=self.id,
813+
project_id=self.project_id,
814+
type=GroupOwnerType.SUSPECT_COMMIT.value,
815+
context__isnull=False,
816+
)
817+
.order_by("-date_added")
818+
.first()
812819
)
813-
if not suspect_commit_owner.exists():
820+
821+
if not suspect_commit_owner:
814822
return None
815823

816-
suspect_commit_owner = suspect_commit_owner.first()
817824
commit_id = suspect_commit_owner.context.get("commitId")
818825
if not commit_id:
819826
return None

0 commit comments

Comments
 (0)