|
9 | 9 | from tokenizers import Tokenizer |
10 | 10 |
|
11 | 11 | from sentry import features, options |
12 | | -from sentry.constants import DATA_ROOT |
| 12 | +from sentry.constants import ( |
| 13 | + AUTO_OPEN_PRS_DEFAULT, |
| 14 | + DATA_ROOT, |
| 15 | + SEER_DEFAULT_AUTOMATED_RUN_STOPPING_POINT_DEFAULT, |
| 16 | + SEER_DEFAULT_CODING_AGENT_DEFAULT, |
| 17 | +) |
13 | 18 | from sentry.grouping.api import get_contributing_variant_and_component |
14 | 19 | from sentry.grouping.grouping_info import get_grouping_info_from_variants_legacy |
15 | 20 | from sentry.grouping.variants import BaseVariant |
|
23 | 28 | set_project_seer_preference, |
24 | 29 | write_preference_to_sentry_db, |
25 | 30 | ) |
26 | | -from sentry.seer.models import SeerProjectPreference |
| 31 | +from sentry.seer.models import ( |
| 32 | + AutofixHandoffPoint, |
| 33 | + SeerAutomationHandoffConfiguration, |
| 34 | + SeerProjectPreference, |
| 35 | +) |
27 | 36 | from sentry.seer.similarity.types import GroupingVersion |
28 | 37 | from sentry.services.eventstore.models import Event, GroupEvent |
29 | 38 | from sentry.utils import metrics |
@@ -564,21 +573,51 @@ def set_default_project_seer_scanner_automation( |
564 | 573 |
|
565 | 574 |
|
566 | 575 | def set_default_project_auto_open_prs(organization: Organization, project: Project) -> None: |
567 | | - """Called once at project creation time to set the initial auto open PRs.""" |
| 576 | + """Called once at project creation time to set the initial automated run stopping |
| 577 | + point and automation handoff. |
| 578 | +
|
| 579 | + Reads org options (default_automated_run_stopping_point, auto_open_prs, default_coding_agent, |
| 580 | + default_coding_agent_integration_id) and writes the corresponding project-level |
| 581 | + options (stopping point, handoff config). |
| 582 | +
|
| 583 | + When auto_open_prs is True, stopping_point is forced to open_pr regardless of |
| 584 | + default_stopping_point. |
| 585 | + """ |
568 | 586 | if not is_seer_seat_based_tier_enabled(organization): |
569 | 587 | return |
570 | 588 |
|
571 | | - stopping_point = AutofixStoppingPoint.CODE_CHANGES |
572 | | - if organization.get_option("sentry:auto_open_prs"): |
| 589 | + auto_open_prs = bool(organization.get_option("sentry:auto_open_prs", AUTO_OPEN_PRS_DEFAULT)) |
| 590 | + if auto_open_prs: |
573 | 591 | stopping_point = AutofixStoppingPoint.OPEN_PR |
| 592 | + else: |
| 593 | + stopping_point = organization.get_option( |
| 594 | + "sentry:default_stopping_point", SEER_DEFAULT_AUTOMATED_RUN_STOPPING_POINT_DEFAULT |
| 595 | + ) |
| 596 | + |
| 597 | + coding_agent = organization.get_option( |
| 598 | + "sentry:seer_default_coding_agent", SEER_DEFAULT_CODING_AGENT_DEFAULT |
| 599 | + ) |
| 600 | + coding_agent_integration_id = organization.get_option( |
| 601 | + "sentry:seer_default_coding_agent_integration_id", None |
| 602 | + ) |
| 603 | + |
| 604 | + automation_handoff: SeerAutomationHandoffConfiguration | None = None |
| 605 | + if coding_agent and coding_agent != "seer" and coding_agent_integration_id is not None: |
| 606 | + automation_handoff = SeerAutomationHandoffConfiguration( |
| 607 | + handoff_point=AutofixHandoffPoint.ROOT_CAUSE, |
| 608 | + target=coding_agent, |
| 609 | + integration_id=coding_agent_integration_id, |
| 610 | + auto_create_pr=auto_open_prs, |
| 611 | + ) |
574 | 612 |
|
575 | | - # We need to make an API call to Seer to set this preference |
576 | 613 | preference = SeerProjectPreference( |
577 | 614 | organization_id=organization.id, |
578 | 615 | project_id=project.id, |
579 | 616 | repositories=[], |
580 | 617 | automated_run_stopping_point=stopping_point, |
| 618 | + automation_handoff=automation_handoff, |
581 | 619 | ) |
| 620 | + |
582 | 621 | try: |
583 | 622 | set_project_seer_preference(preference) |
584 | 623 | except Exception as e: |
|
0 commit comments