|
8 | 8 |
|
9 | 9 | from sentry import analytics, features |
10 | 10 | from sentry.analytics.events.autofix_automation_events import AiAutofixAutomationEvent |
11 | | -from sentry.constants import ObjectStatus |
| 11 | +from sentry.constants import ( |
| 12 | + ObjectStatus, |
| 13 | +) |
12 | 14 | from sentry.models.group import Group |
13 | 15 | from sentry.models.organization import Organization |
14 | 16 | from sentry.models.project import Project |
|
24 | 26 | deduplicate_repositories, |
25 | 27 | get_autofix_repos_from_project_code_mappings, |
26 | 28 | get_autofix_state, |
| 29 | + get_org_default_seer_automation_handoff, |
27 | 30 | get_seer_seat_based_tier_cache_key, |
28 | 31 | resolve_repository_ids, |
29 | 32 | ) |
@@ -238,34 +241,49 @@ def configure_seer_for_existing_org(organization_id: int) -> None: |
238 | 241 | "sentry:autofix_automation_tuning", AutofixAutomationTuningSettings.MEDIUM |
239 | 242 | ) |
240 | 243 |
|
| 244 | + default_stopping_point, default_handoff = get_org_default_seer_automation_handoff(organization) |
| 245 | + default_handoff_dict = default_handoff.dict() if default_handoff else None |
| 246 | + |
| 247 | + valid_stopping_points = {"open_pr", "code_changes"} |
| 248 | + |
241 | 249 | preferences_by_id = bulk_get_project_preferences(organization_id, project_ids) |
242 | 250 |
|
243 | 251 | # Determine which projects need updates |
244 | 252 | preferences_to_set = [] |
245 | 253 | projects_by_id = {p.id: p for p in projects} |
246 | 254 | for project_id in project_ids: |
| 255 | + stopping_point = default_stopping_point |
| 256 | + handoff = default_handoff_dict |
| 257 | + |
247 | 258 | existing_pref = preferences_by_id.get(str(project_id)) |
248 | 259 | if not existing_pref: |
249 | 260 | # No existing preferences, get repositories from code mappings |
250 | 261 | repositories = get_autofix_repos_from_project_code_mappings(projects_by_id[project_id]) |
251 | 262 | else: |
252 | | - # Skip projects that already have an acceptable stopping point configured |
253 | | - if existing_pref.get("automated_run_stopping_point") in ("open_pr", "code_changes"): |
254 | | - continue |
255 | 263 | repositories = existing_pref.get("repositories") or [] |
256 | 264 |
|
257 | | - repositories = deduplicate_repositories(repositories) |
| 265 | + existing_stopping_point = existing_pref.get("automated_run_stopping_point") |
| 266 | + existing_handoff = existing_pref.get("automation_handoff") |
| 267 | + |
| 268 | + # Skip projects that a) already have an acceptable stopping point configured |
| 269 | + # AND b) already have a handoff configured or no org default handoff. |
| 270 | + if existing_stopping_point in valid_stopping_points and ( |
| 271 | + existing_handoff or default_handoff_dict is None |
| 272 | + ): |
| 273 | + continue |
| 274 | + |
| 275 | + if existing_stopping_point in valid_stopping_points: |
| 276 | + stopping_point = existing_stopping_point |
| 277 | + if existing_handoff: |
| 278 | + handoff = existing_handoff |
258 | 279 |
|
259 | | - # Preserve existing repositories and automation_handoff, only update the stopping point |
260 | 280 | preferences_to_set.append( |
261 | 281 | { |
262 | 282 | "organization_id": organization_id, |
263 | 283 | "project_id": project_id, |
264 | | - "repositories": repositories or [], |
265 | | - "automated_run_stopping_point": "code_changes", |
266 | | - "automation_handoff": ( |
267 | | - existing_pref.get("automation_handoff") if existing_pref else None |
268 | | - ), |
| 284 | + "repositories": deduplicate_repositories(repositories) or [], |
| 285 | + "automated_run_stopping_point": stopping_point, |
| 286 | + "automation_handoff": handoff, |
269 | 287 | } |
270 | 288 | ) |
271 | 289 |
|
|
0 commit comments