From 81b77168f15490e127f9b931ca318bc730e72be7 Mon Sep 17 00:00:00 2001 From: "jenn.muengtaweepongsa" Date: Thu, 14 Nov 2024 13:41:33 -0800 Subject: [PATCH 1/3] feat(org-options): Add autofix_enabled org option --- .../api/endpoints/group_autofix_setup_check.py | 3 +++ src/sentry/api/endpoints/organization_details.py | 12 ++++++++++++ src/sentry/api/serializers/models/organization.py | 5 +++++ src/sentry/apidocs/examples/organization_examples.py | 1 + src/sentry/constants.py | 1 + 5 files changed, 22 insertions(+) diff --git a/src/sentry/api/endpoints/group_autofix_setup_check.py b/src/sentry/api/endpoints/group_autofix_setup_check.py index ff856bf4609bc6..07be1dd61f65a3 100644 --- a/src/sentry/api/endpoints/group_autofix_setup_check.py +++ b/src/sentry/api/endpoints/group_autofix_setup_check.py @@ -153,5 +153,8 @@ def get(self, request: Request, group: Group) -> Response: "codebaseIndexing": { "ok": codebase_indexing_ok, }, + "autofixEnabled": { + "ok": org.get_option("sentry:autofix_enabled", False), + }, } ) diff --git a/src/sentry/api/endpoints/organization_details.py b/src/sentry/api/endpoints/organization_details.py index 22c97e291220b2..660328114470bd 100644 --- a/src/sentry/api/endpoints/organization_details.py +++ b/src/sentry/api/endpoints/organization_details.py @@ -45,6 +45,7 @@ AI_SUGGESTED_SOLUTION, ALERTS_MEMBER_WRITE_DEFAULT, ATTACHMENTS_ROLE_DEFAULT, + AUTOFIX_ENABLED_DEFAULT, DEBUG_FILES_ROLE_DEFAULT, EVENTS_MEMBER_ADMIN_DEFAULT, GITHUB_COMMENT_BOT_DEFAULT, @@ -192,6 +193,12 @@ bool, HIDE_AI_FEATURES_DEFAULT, ), + ( + "autofixEnabled", + "sentry:autofix_enabled", + bool, + AUTOFIX_ENABLED_DEFAULT, + ), ( "githubPRBot", "sentry:github_pr_bot", @@ -284,6 +291,7 @@ class OrganizationSerializer(BaseOrganizationSerializer): isEarlyAdopter = serializers.BooleanField(required=False) aiSuggestedSolution = serializers.BooleanField(required=False) hideAiFeatures = serializers.BooleanField(required=False) + autofixEnabled = serializers.BooleanField(required=False) codecovAccess = serializers.BooleanField(required=False) githubOpenPRBot = serializers.BooleanField(required=False) githubNudgeInvite = serializers.BooleanField(required=False) @@ -673,6 +681,10 @@ class OrganizationDetailsPutSerializer(serializers.Serializer): help_text="Specify `true` to hide AI features from the organization.", required=False, ) + autofixEnabled = serializers.BooleanField( + help_text="Specify `true` to enable Autofix for the organization.", + required=False, + ) codecovAccess = serializers.BooleanField( help_text="Specify `true` to enable Code Coverage Insights. This feature is only available for organizations on the Team plan and above. Learn more about Codecov [here](/product/codecov/).", required=False, diff --git a/src/sentry/api/serializers/models/organization.py b/src/sentry/api/serializers/models/organization.py index d104484153a859..3d40f1fbcdde1a 100644 --- a/src/sentry/api/serializers/models/organization.py +++ b/src/sentry/api/serializers/models/organization.py @@ -33,6 +33,7 @@ AI_SUGGESTED_SOLUTION, ALERTS_MEMBER_WRITE_DEFAULT, ATTACHMENTS_ROLE_DEFAULT, + AUTOFIX_ENABLED_DEFAULT, DATA_CONSENT_DEFAULT, DEBUG_FILES_ROLE_DEFAULT, EVENTS_MEMBER_ADMIN_DEFAULT, @@ -496,6 +497,7 @@ class DetailedOrganizationSerializerResponse(_DetailedOrganizationSerializerResp metricsActivateLastForGauges: bool requiresSso: bool rollbackEnabled: bool + autofixEnabled: bool class DetailedOrganizationSerializer(OrganizationSerializer): @@ -605,6 +607,9 @@ def serialize( # type: ignore[explicit-override, override] "hideAiFeatures": bool( obj.get_option("sentry:hide_ai_features", HIDE_AI_FEATURES_DEFAULT) ), + "autofixEnabled": bool( + obj.get_option("sentry:autofix_enabled", AUTOFIX_ENABLED_DEFAULT) + ), "githubPRBot": bool( obj.get_option("sentry:github_pr_bot", GITHUB_COMMENT_BOT_DEFAULT) ), diff --git a/src/sentry/apidocs/examples/organization_examples.py b/src/sentry/apidocs/examples/organization_examples.py index 09f90d6ba36b71..90736c727a4ed5 100644 --- a/src/sentry/apidocs/examples/organization_examples.py +++ b/src/sentry/apidocs/examples/organization_examples.py @@ -312,6 +312,7 @@ class OrganizationExamples: "codecovAccess": False, "aiSuggestedSolution": True, "hideAiFeatures": False, + "autofixEnabled": False, "githubPRBot": True, "githubOpenPRBot": True, "githubNudgeInvite": True, diff --git a/src/sentry/constants.py b/src/sentry/constants.py index b6d53e557f2f4d..652a06d6b9b765 100644 --- a/src/sentry/constants.py +++ b/src/sentry/constants.py @@ -708,6 +708,7 @@ class InsightModules(Enum): JOIN_REQUESTS_DEFAULT = True AI_SUGGESTED_SOLUTION = True HIDE_AI_FEATURES_DEFAULT = False +AUTOFIX_ENABLED_DEFAULT = False GITHUB_COMMENT_BOT_DEFAULT = True ISSUE_ALERTS_THREAD_DEFAULT = True METRIC_ALERTS_THREAD_DEFAULT = True From d8e32c1bcbe80d610a1902ca6b3e6faa394864d6 Mon Sep 17 00:00:00 2001 From: "jenn.muengtaweepongsa" Date: Thu, 14 Nov 2024 13:49:42 -0800 Subject: [PATCH 2/3] tests --- tests/sentry/api/endpoints/test_organization_details.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/sentry/api/endpoints/test_organization_details.py b/tests/sentry/api/endpoints/test_organization_details.py index b2554bc31ca418..9fc5ea39bda568 100644 --- a/tests/sentry/api/endpoints/test_organization_details.py +++ b/tests/sentry/api/endpoints/test_organization_details.py @@ -705,6 +705,7 @@ def test_various_options(self, mock_get_repositories): "allowMemberInvite": False, "aiSuggestedSolution": False, "hideAiFeatures": True, + "autofixEnabled": True, "githubOpenPRBot": False, "githubNudgeInvite": False, "githubPRBot": False, @@ -772,6 +773,7 @@ def test_various_options(self, mock_get_repositories): assert options.get("sentry:sampling_mode") == "organization" assert options.get("sentry:rollback_enabled") is True assert options.get("sentry:hide_ai_features") is True + assert options.get("sentry:autofix_enabled") is True # log created with assume_test_silo_mode_of(AuditLogEntry): @@ -802,6 +804,7 @@ def test_various_options(self, mock_get_repositories): assert "to {}".format(data["alertsMemberWrite"]) in log.data["alertsMemberWrite"] assert "to {}".format(data["aiSuggestedSolution"]) in log.data["aiSuggestedSolution"] assert "to {}".format(data["hideAiFeatures"]) in log.data["hideAiFeatures"] + assert "to {}".format(data["autofixEnabled"]) in log.data["autofixEnabled"] assert "to {}".format(data["githubPRBot"]) in log.data["githubPRBot"] assert "to {}".format(data["githubOpenPRBot"]) in log.data["githubOpenPRBot"] assert "to {}".format(data["githubNudgeInvite"]) in log.data["githubNudgeInvite"] From 3e9bf8c772dc2ef3a7caa23b2eb42c7ec861f1cb Mon Sep 17 00:00:00 2001 From: "jenn.muengtaweepongsa" Date: Thu, 14 Nov 2024 14:37:34 -0800 Subject: [PATCH 3/3] fix test --- .../sentry/api/endpoints/test_group_autofix_setup_check.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/sentry/api/endpoints/test_group_autofix_setup_check.py b/tests/sentry/api/endpoints/test_group_autofix_setup_check.py index 6a7e5188d53050..e070ce037c80e3 100644 --- a/tests/sentry/api/endpoints/test_group_autofix_setup_check.py +++ b/tests/sentry/api/endpoints/test_group_autofix_setup_check.py @@ -31,6 +31,7 @@ def setUp(self): source_root="sentry/", ) self.organization.update_option("sentry:gen_ai_consent_v2024_11_14", True) + self.organization.update_option("sentry:autofix_enabled", True) @patch( "sentry.api.endpoints.group_autofix_setup_check.get_repos_and_access", @@ -82,6 +83,9 @@ def test_successful_setup(self, mock_update_codebase_index, mock_get_repos_and_a "codebaseIndexing": { "ok": True, }, + "autofixEnabled": { + "ok": True, + }, } @with_feature("organizations:autofix-disable-codebase-indexing") @@ -137,6 +141,9 @@ def test_successful_with_codebase_indexing_disabled_flag( "codebaseIndexing": { "ok": True, }, + "autofixEnabled": { + "ok": True, + }, }