Skip to content

Commit 061dc64

Browse files
committed
add build handoff helper
1 parent 770c187 commit 061dc64

File tree

1 file changed

+22
-37
lines changed

1 file changed

+22
-37
lines changed

src/sentry/seer/autofix/utils.py

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22
from collections import defaultdict
3-
from collections.abc import Iterable, Mapping
3+
from collections.abc import Callable, Iterable, Mapping
44
from datetime import UTC, datetime
55
from enum import StrEnum
66
from typing import Any, NotRequired, TypedDict
@@ -702,6 +702,25 @@ def build_repo_definition_from_project_repo(
702702
)
703703

704704

705+
def _build_automation_handoff(
706+
get_option: Callable[[str], Any],
707+
) -> SeerAutomationHandoffConfiguration | None:
708+
"""Build a SeerAutomationHandoffConfiguration from option values, or None if incomplete."""
709+
handoff_point = get_option("sentry:seer_automation_handoff_point")
710+
handoff_target = get_option("sentry:seer_automation_handoff_target")
711+
handoff_integration_id = get_option("sentry:seer_automation_handoff_integration_id")
712+
713+
if handoff_point is None or handoff_target is None or handoff_integration_id is None:
714+
return None
715+
716+
return SeerAutomationHandoffConfiguration(
717+
handoff_point=handoff_point,
718+
target=handoff_target,
719+
integration_id=handoff_integration_id,
720+
auto_create_pr=get_option("sentry:seer_automation_handoff_auto_create_pr"),
721+
)
722+
723+
705724
def read_preference_from_sentry_db(project: Project) -> SeerProjectPreference | None:
706725
"""Read a single project's Seer preferences from Sentry DB."""
707726
seer_project_repo_qs = (
@@ -720,29 +739,12 @@ def read_preference_from_sentry_db(project: Project) -> SeerProjectPreference |
720739
if not repo_definitions and not has_configured_options:
721740
return None
722741

723-
handoff_point = project.get_option("sentry:seer_automation_handoff_point")
724-
handoff_target = project.get_option("sentry:seer_automation_handoff_target")
725-
handoff_integration_id = project.get_option("sentry:seer_automation_handoff_integration_id")
726-
727-
automation_handoff = None
728-
if (
729-
handoff_point is not None
730-
and handoff_target is not None
731-
and handoff_integration_id is not None
732-
):
733-
automation_handoff = SeerAutomationHandoffConfiguration(
734-
handoff_point=handoff_point,
735-
target=handoff_target,
736-
integration_id=handoff_integration_id,
737-
auto_create_pr=project.get_option("sentry:seer_automation_handoff_auto_create_pr"),
738-
)
739-
740742
return SeerProjectPreference(
741743
organization_id=project.organization_id,
742744
project_id=project.id,
743745
repositories=repo_definitions,
744746
automated_run_stopping_point=project.get_option("sentry:seer_automated_run_stopping_point"),
745-
automation_handoff=automation_handoff,
747+
automation_handoff=_build_automation_handoff(project.get_option),
746748
)
747749

748750

@@ -788,31 +790,14 @@ def get_project_option(key: str) -> Any:
788790
return projectoptions.lookup_well_known_key(key).default
789791
return value
790792

791-
handoff_point = get_project_option("sentry:seer_automation_handoff_point")
792-
handoff_target = get_project_option("sentry:seer_automation_handoff_target")
793-
handoff_integration_id = get_project_option("sentry:seer_automation_handoff_integration_id")
794-
795-
automation_handoff = None
796-
if (
797-
handoff_point is not None
798-
and handoff_target is not None
799-
and handoff_integration_id is not None
800-
):
801-
automation_handoff = SeerAutomationHandoffConfiguration(
802-
handoff_point=handoff_point,
803-
target=handoff_target,
804-
integration_id=handoff_integration_id,
805-
auto_create_pr=get_project_option("sentry:seer_automation_handoff_auto_create_pr"),
806-
)
807-
808793
result[project.id] = SeerProjectPreference(
809794
organization_id=project.organization_id,
810795
project_id=project.id,
811796
repositories=repo_definitions_by_project.get(project.id, []),
812797
automated_run_stopping_point=get_project_option(
813798
"sentry:seer_automated_run_stopping_point"
814799
),
815-
automation_handoff=automation_handoff,
800+
automation_handoff=_build_automation_handoff(get_project_option),
816801
)
817802

818803
return result

0 commit comments

Comments
 (0)