Browse Source

ref(open-pr-comments): get unresolved issues (#60716)

Cathy Teng 1 year ago
parent
commit
5740541f6e

+ 2 - 1
src/sentry/tasks/integrations/github/open_pr_comment.py

@@ -11,7 +11,7 @@ from snuba_sdk import Column, Condition, Direction, Entity, Function, Op, OrderB
 from snuba_sdk import Request as SnubaRequest
 
 from sentry.integrations.github.client import GitHubAppsClient
-from sentry.models.group import Group
+from sentry.models.group import Group, GroupStatus
 from sentry.models.integrations.repository_project_path_config import RepositoryProjectPathConfig
 from sentry.models.options.organization_option import OrganizationOption
 from sentry.models.organization import Organization
@@ -217,6 +217,7 @@ def get_top_5_issues_by_count_for_file(
     group_ids = list(
         Group.objects.filter(
             last_seen__gte=datetime.now() - timedelta(days=14),
+            status=GroupStatus.UNRESOLVED,
             project__in=projects,
         ).values_list("id", flat=True)
     )

+ 10 - 1
tests/sentry/tasks/integrations/github/test_open_pr_comment.py

@@ -4,7 +4,7 @@ import pytest
 import responses
 from django.utils import timezone
 
-from sentry.models.group import Group
+from sentry.models.group import Group, GroupStatus
 from sentry.models.options.organization_option import OrganizationOption
 from sentry.models.pullrequest import CommentType, PullRequest, PullRequestComment
 from sentry.shared_integrations.exceptions.base import ApiError
@@ -287,6 +287,15 @@ class TestGetCommentIssues(TestCase):
         assert top_5_issue_ids == [self.group_id]
         assert top_5_issues[0]["affected_users"] == 6
 
+    def test_filters_resolved_issue(self):
+        group = Group.objects.all()[0]
+        group.resolved_at = timezone.now()
+        group.status = GroupStatus.RESOLVED
+        group.save()
+
+        top_5_issues = get_top_5_issues_by_count_for_file([self.project], ["baz.py"])
+        assert len(top_5_issues) == 0
+
     def test_project_group_id_mismatch(self):
         # we fetch all group_ids that belong to the projects passed into the function
         self._create_event(project_id=self.another_org_project.id)