Browse Source

chore(github): cleanup unused code (#66971)

Cathy Teng 1 year ago
parent
commit
e4818e8b46

+ 2 - 15
src/sentry/conf/server.py

@@ -761,7 +761,6 @@ CELERY_IMPORTS = (
     "sentry.tasks.files",
     "sentry.tasks.groupowner",
     "sentry.tasks.integrations",
-    "sentry.tasks.invite_missing_org_members",
     "sentry.tasks.low_priority_symbolication",
     "sentry.tasks.merge",
     "sentry.tasks.options",
@@ -1104,15 +1103,6 @@ CELERYBEAT_SCHEDULE_REGION = {
         ),
         "options": {"expires": 60 * 60 * 3},
     },
-    # "schedule-monthly-invite-missing-org-members": {
-    #     "task": "sentry.tasks.invite_missing_org_members.schedule_organizations",
-    #     "schedule": crontab(
-    #         minute=0,
-    #         hour=7,
-    #         day_of_month="1",  # 00:00 PDT, 03:00 EDT, 7:00 UTC
-    #     ),
-    #     "options": {"expires": 60 * 25},
-    # },
     "schedule-hybrid-cloud-foreign-key-jobs": {
         "task": "sentry.tasks.deletion.hybrid_cloud.schedule_hybrid_cloud_foreign_key_jobs",
         # Run every 15 minutes
@@ -1436,7 +1426,6 @@ SENTRY_EARLY_FEATURES = {
     "organizations:grouping-stacktrace-ui": "Enable experimental new version of stacktrace component where additional data related to grouping is shown on each frame",
     "organizations:grouping-title-ui": "Enable tweaks to group title in relation to hierarchical grouping.",
     "organizations:grouping-tree-ui": "Enable experimental new version of Merged Issues where sub-hashes are shown",
-    "organizations:integrations-gh-invite": "Enables inviting new members based on GitHub commit activity",
     "organizations:issue-details-tag-improvements": "Enable tag improvements in the issue details page",
     "organizations:mobile-cpu-memory-in-transactions": "Display CPU and memory metrics in transactions with profiles",
     "organizations:performance-metrics-backed-transaction-summary": "Enable metrics-backed transaction summary view",
@@ -1588,6 +1577,8 @@ SENTRY_FEATURES: dict[str, bool | None] = {
     "organizations:integrations-chat-unfurl": True,
     # Enable the API to importing CODEOWNERS for a project
     "organizations:integrations-codeowners": True,
+    # Enable custom alert priorities for Pagerduty and Opsgenie
+    "organizations:integrations-custom-alert-priorities": False,
     # Enable integration functionality to work deployment integrations like Vercel
     "organizations:integrations-deployment": True,
     # Enable integration functionality to work with enterprise alert rules
@@ -1597,8 +1588,6 @@ SENTRY_FEATURES: dict[str, bool | None] = {
     "organizations:integrations-enterprise-incident-management": True,
     # Enable interface functionality to receive event hooks.
     "organizations:integrations-event-hooks": True,
-    # Enables inviting new members based on GitHub commit activity.
-    "organizations:integrations-gh-invite": False,
     # Enable integration functionality to work with alert rules (specifically incident
     # management integrations)
     "organizations:integrations-incident-management": True,
@@ -1892,8 +1881,6 @@ SENTRY_FEATURES: dict[str, bool | None] = {
     "organizations:sourcemaps-upload-release-as-artifact-bundle": False,
     # Enable Slack messages using Block Kit
     "organizations:slack-block-kit": False,
-    # Improvements to Slack messages using Block Kit
-    "organizations:slack-block-kit-improvements": False,
     # Send Slack notifications to threads for Metric Alerts
     "organizations:slack-thread": False,
     # Send Slack notifications to threads for Issue Alerts

+ 1 - 4
src/sentry/features/__init__.py

@@ -113,11 +113,9 @@ default_manager.add("organizations:grouping-title-ui", OrganizationFeature, Feat
 default_manager.add("organizations:grouping-tree-ui", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
 default_manager.add("organizations:higher-ownership-limit", OrganizationFeature, FeatureHandlerStrategy.INTERNAL)
 default_manager.add("organizations:increased-issue-owners-rate-limit", OrganizationFeature, FeatureHandlerStrategy.INTERNAL)
+default_manager.add("organizations:integrations-custom-alert-priorities", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
 default_manager.add("organizations:integrations-deployment", OrganizationFeature, FeatureHandlerStrategy.INTERNAL)
 default_manager.add("organizations:integrations-feature-flag-integration", OrganizationFeature, FeatureHandlerStrategy.INTERNAL)
-default_manager.add("organizations:integrations-gh-invite", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
-default_manager.add("organizations:integrations-open-pr-comment", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
-default_manager.add("organizations:integrations-open-pr-comment-js", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
 default_manager.add("organizations:integrations-open-pr-comment-beta-langs", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
 default_manager.add("organizations:investigation-bias", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
 default_manager.add("organizations:invite-members-rate-limits", OrganizationFeature, FeatureHandlerStrategy.INTERNAL)
@@ -261,7 +259,6 @@ default_manager.add("organizations:settings-legal-tos-ui", OrganizationFeature,
 default_manager.add("organizations:slack-block-kit", OrganizationFeature, FeatureHandlerStrategy.INTERNAL)
 default_manager.add("organizations:slack-thread", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
 default_manager.add("organizations:slack-thread-issue-alert", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
-default_manager.add("organizations:slack-block-kit-improvements", OrganizationFeature, FeatureHandlerStrategy.INTERNAL)
 default_manager.add("organizations:slack-overage-notifications", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
 default_manager.add("organizations:sourcemaps-bundle-flat-file-indexing", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
 default_manager.add("organizations:sourcemaps-upload-release-as-artifact-bundle", OrganizationFeature, FeatureHandlerStrategy.REMOTE)

+ 0 - 117
src/sentry/tasks/invite_missing_org_members.py

@@ -1,117 +0,0 @@
-import logging
-
-from sentry import features
-from sentry.api.endpoints.organization_missing_org_members import (
-    _format_external_id,
-    _get_missing_organization_members,
-    _get_shared_email_domain,
-)
-from sentry.constants import ObjectStatus
-from sentry.models.options import OrganizationOption
-from sentry.models.organization import Organization
-from sentry.notifications.notifications.missing_members_nudge import MissingMembersNudgeNotification
-from sentry.services.hybrid_cloud.integration import integration_service
-from sentry.silo.base import SiloMode
-from sentry.tasks.base import instrumented_task
-
-logger = logging.getLogger(__name__)
-
-
-@instrumented_task(
-    name="sentry.tasks.invite_missing_org_members.schedule_organizations",
-    max_retries=3,
-    silo_mode=SiloMode.REGION,
-)
-def schedule_organizations():
-    logger.info("invite_missing_org_members.schedule_organizations")
-
-    # NOTE: currently only for github
-    github_org_integrations = integration_service.get_organization_integrations(
-        providers=["github"], status=ObjectStatus.ACTIVE
-    )
-    orgs_with_github_integrations = {
-        org_integration.organization_id for org_integration in github_org_integrations
-    }
-
-    for org_id in orgs_with_github_integrations:
-        send_nudge_email.delay(org_id)
-
-
-@instrumented_task(
-    name="sentry.tasks.invite_missing_members.send_nudge_email",
-    silo_mode=SiloMode.REGION,
-    queue="nudge.invite_missing_org_members",
-)
-def send_nudge_email(org_id):
-    logger.info("invite_missing_org_members.send_nudge_email")
-
-    try:
-        organization = Organization.objects.get_from_cache(id=org_id)
-    except Organization.DoesNotExist:
-        logger.info(
-            "invite_missing_org_members.send_nudge_email.missing_org",
-            extra={"organization_id": org_id},
-        )
-        return
-
-    if not features.has("organizations:integrations-gh-invite", organization):
-        logger.info(
-            "invite_missing_org_members.send_nudge_email.missing_flag",
-            extra={"organization_id": org_id},
-        )
-        return
-
-    if not OrganizationOption.objects.get_value(
-        organization=organization, key="sentry:github_nudge_invite", default=True
-    ):
-        return
-
-    integrations = integration_service.get_integrations(
-        organization_id=org_id, providers=["github"], status=ObjectStatus.ACTIVE
-    )
-
-    if not integrations:
-        logger.info(
-            "invite_missing_org_members.send_nudge_email.missing_integrations",
-            extra={"organization_id": org_id},
-        )
-        return
-
-    shared_domain = _get_shared_email_domain(organization)
-
-    commit_author_query = _get_missing_organization_members(
-        organization,
-        provider="github",
-        integration_ids=[i.id for i in integrations],
-        shared_domain=shared_domain,
-    )
-
-    if not len(commit_author_query):  # don't email if no missing commit authors
-        logger.info(
-            "invite_missing_org_members.send_nudge_email.no_commit_authors",
-            extra={"organization_id": org_id},
-        )
-        return
-
-    commit_authors = []
-    for commit_author in commit_author_query[:3]:
-        formatted_external_id = _format_external_id(commit_author.external_id)
-
-        commit_authors.append(
-            {
-                "email": commit_author.email,
-                "external_id": formatted_external_id,
-                "commit_count": commit_author.commit__count,
-            }
-        )
-
-    notification = MissingMembersNudgeNotification(
-        organization=organization, commit_authors=commit_authors, provider="github"
-    )
-
-    logger.info(
-        "invite_missing_org_members.send_nudge_email.send_notification",
-        extra={"organization_id": org_id},
-    )
-
-    notification.send()

+ 0 - 1
tests/sentry/integrations/slack/test_message_builder.py

@@ -893,7 +893,6 @@ class BuildGroupAttachmentTest(TestCase, PerformanceIssueTestCase, OccurrenceTes
                 assert ":red_circle:" in section["text"]["text"]
 
     @with_feature("organizations:slack-block-kit")
-    @with_feature("organizations:slack-block-kit-improvements")
     def test_build_group_generic_issue_block_no_escaping(self):
         """Test that a generic issue type's Slack alert contains the expected values"""
         event = self.store_event(

+ 0 - 178
tests/sentry/tasks/test_invite_missing_org_members.py

@@ -1,178 +0,0 @@
-from unittest.mock import patch
-
-from sentry.constants import ObjectStatus
-from sentry.models.options.organization_option import OrganizationOption
-from sentry.tasks.invite_missing_org_members import schedule_organizations, send_nudge_email
-from sentry.testutils.cases import TestCase
-from sentry.testutils.helpers import with_feature
-from sentry.testutils.silo import region_silo_test
-
-
-@region_silo_test
-@patch(
-    "sentry.notifications.notifications.missing_members_nudge.MissingMembersNudgeNotification.send",
-)
-@patch(
-    "sentry.tasks.invite_missing_org_members.send_nudge_email",
-)
-class InviteMissingMembersTestCase(TestCase):
-    def setUp(self):
-        super().setUp()
-        self.user = self.create_user(email="owner@example.com")
-        self.organization = self.create_organization(owner=self.user)
-        self.create_member(
-            email="a@example.com",
-            organization=self.organization,
-        )
-        member = self.create_member(user=self.create_user(), organization=self.organization)
-        member.user_email = "b@example.com"
-        member.save()
-
-        self.member_commit_author = self.create_commit_author(
-            project=self.project, email="b@example.com"
-        )
-        self.nonmember_commit_author1 = self.create_commit_author(
-            project=self.project, email="c@example.com"
-        )
-        self.nonmember_commit_author1.external_id = "github:c"
-        self.nonmember_commit_author1.save()
-
-        self.nonmember_commit_author2 = self.create_commit_author(
-            project=self.project, email="d@example.com"
-        )
-        self.nonmember_commit_author2.external_id = "github:d"
-        self.nonmember_commit_author2.save()
-
-        nonmember_commit_author_invalid_char = self.create_commit_author(
-            project=self.project, email="hi+1@example.com"
-        )
-        nonmember_commit_author_invalid_char.external_id = "github:hi+1"
-        nonmember_commit_author_invalid_char.save()
-
-        nonmember_commit_author_invalid_domain = self.create_commit_author(
-            project=self.project, email="gmail@gmail.com"
-        )
-        nonmember_commit_author_invalid_domain.external_id = "github:gmail"
-        nonmember_commit_author_invalid_domain.save()
-
-        self.repo = self.create_repo(project=self.project, provider="integrations:github")
-        self.create_commit(repo=self.repo, author=self.member_commit_author)
-        self.create_commit(repo=self.repo, author=self.nonmember_commit_author1)
-        self.create_commit(repo=self.repo, author=self.nonmember_commit_author1)
-        self.create_commit(repo=self.repo, author=self.nonmember_commit_author2)
-        self.create_commit(repo=self.repo, author=nonmember_commit_author_invalid_char)
-        self.create_commit(repo=self.repo, author=nonmember_commit_author_invalid_domain)
-
-        not_shared_domain_author = self.create_commit_author(
-            project=self.project, email="a@exampletwo.com"
-        )
-        not_shared_domain_author.external_id = "github:not"
-        not_shared_domain_author.save()
-        self.create_commit(repo=self.repo, author=not_shared_domain_author)
-
-        self.login_as(self.user)
-
-    @with_feature("organizations:integrations-gh-invite")
-    def test_schedules_and_sends(self, mock_send_email, mock_send_notification):
-        integration = self.create_integration(
-            organization=self.organization, provider="github", name="Github", external_id="github:1"
-        )
-        self.repo.integration_id = integration.id
-        self.repo.save()
-
-        with self.tasks():
-            schedule_organizations()
-
-        mock_send_email.delay.assert_called_with(self.organization.id)
-
-        send_nudge_email(org_id=self.organization.id)
-
-        assert mock_send_notification.called
-
-    @with_feature("organizations:integrations-gh-invite")
-    @patch(
-        "sentry.notifications.notifications.missing_members_nudge.MissingMembersNudgeNotification.__init__",
-        return_value=None,
-    )
-    def test_excludes_filtered_emails(
-        self, mock_init_notification, mock_send_email, mock_send_notification
-    ):
-        integration = self.create_integration(
-            organization=self.organization, provider="github", name="Github", external_id="github:1"
-        )
-        self.repo.integration_id = integration.id
-        self.repo.save()
-
-        send_nudge_email(org_id=self.organization.id)
-
-        commit_authors = [
-            {"email": "c@example.com", "external_id": "c", "commit_count": 2},
-            {"email": "d@example.com", "external_id": "d", "commit_count": 1},
-        ]
-
-        mock_init_notification.assert_called_once_with(
-            organization=self.organization, commit_authors=commit_authors, provider="github"
-        )
-
-    def test_no_github_repos(self, mock_send_email, mock_send_notification):
-        self.repo.delete()
-
-        with self.tasks():
-            schedule_organizations()
-
-        assert not mock_send_email.delay.called
-
-    def test_no_active_github_repos(self, mock_send_email, mock_send_notification):
-        self.repo.status = ObjectStatus.DISABLED
-        self.repo.save()
-
-        with self.tasks():
-            schedule_organizations()
-
-        assert not mock_send_email.delay.called
-
-    def test_missing_org(self, mock_send_email, mock_send_notification):
-        send_nudge_email(org_id=0)
-
-        assert not mock_send_notification.called
-
-    def test_missing_feature_flag(self, mock_send_email, mock_send_notification):
-        send_nudge_email(org_id=self.organization.id)
-
-        assert not mock_send_notification.called
-
-    @with_feature("organizations:integrations-gh-invite")
-    def test_missing_integration(self, mock_send_email, mock_send_notification):
-        send_nudge_email(org_id=self.organization.id)
-
-        assert not mock_send_notification.called
-
-    @with_feature("organizations:integrations-gh-invite")
-    def test_missing_option(self, mock_send_email, mock_send_notification):
-        OrganizationOption.objects.set_value(
-            organization=self.organization, key="sentry:github_nudge_invite", value=False
-        )
-
-        integration = self.create_integration(
-            organization=self.organization, provider="github", name="Github", external_id="github:1"
-        )
-        self.repo.integration_id = integration.id
-        self.repo.save()
-
-        send_nudge_email(org_id=self.organization.id)
-
-        assert not mock_send_notification.called
-
-    @with_feature("organizations:integrations-gh-invite")
-    def test_missing_nonmember_commit_authors(self, mock_send_email, mock_send_notification):
-        org = self.create_organization()
-        project = self.create_project(organization=org)
-        self.create_repo(project=project, provider="github")
-
-        self.create_integration(
-            organization=org, provider="github", name="Github", external_id="github:1"
-        )
-
-        send_nudge_email(org_id=org.id)
-
-        assert not mock_send_notification.called