Skip to content

Commit 3243fdb

Browse files
committed
use project_pref_repos and autofix repos as fallback
1 parent 1d53649 commit 3243fdb

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/sentry/tasks/seer/context_engine_index.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
from sentry.models.organization import Organization
1515
from sentry.models.project import Project
1616
from sentry.search.events.types import SnubaParams
17-
from sentry.seer.autofix.utils import get_autofix_repos_from_project_code_mappings
17+
from sentry.seer.autofix.utils import (
18+
bulk_get_project_preferences,
19+
get_autofix_repos_from_project_code_mappings,
20+
)
1821
from sentry.seer.explorer.context_engine_utils import (
1922
EVENT_COUNT_LOOKBACK_DAYS,
2023
ProjectEventCounts,
@@ -245,28 +248,40 @@ def index_repos(organization_id: int, *args, **kwargs) -> None:
245248
projects = list(
246249
Project.objects.filter(organization_id=organization_id, status=ObjectStatus.ACTIVE)
247250
)
251+
project_map = {p.id: p for p in projects}
248252

249-
if not projects:
253+
if not project_map:
250254
logger.info("No projects found for organization", extra={"org_id": organization_id})
251255
return
252256

253257
org_repo_definitions: dict[tuple[str, str, str], RepoDetails] = {}
254258

255-
for project in projects:
256-
repos = get_autofix_repos_from_project_code_mappings(project)
259+
preferences_by_id = bulk_get_project_preferences(organization_id, list(project_map.keys()))
260+
261+
for project_id, project in project_map.items():
262+
existing_pref = preferences_by_id.get(str(project_id))
263+
project_pref_repos = existing_pref.get("repositories") or []
264+
autofix_repos = get_autofix_repos_from_project_code_mappings(project_map[project_id])
265+
266+
language_map: dict[tuple[str, str, str], list[str]] = {}
267+
for autofix_repo in autofix_repos:
268+
key = (autofix_repo["provider"], autofix_repo["owner"], autofix_repo["name"])
269+
language_map[key] = autofix_repo["languages"]
270+
271+
repos = project_pref_repos if project_pref_repos else autofix_repos
257272
for repo in repos:
258273
key = (repo["provider"], repo["owner"], repo["name"])
259274
if key in org_repo_definitions:
260275
repo_definition = org_repo_definitions[key]
261-
repo_definition["project_ids"].append(project.id)
276+
repo_definition["project_ids"].append(project_id)
262277
else:
263278
org_repo_definitions[key] = {
264-
"project_ids": [project.id],
279+
"project_ids": [project_id],
265280
"provider": repo["provider"],
266281
"owner": repo["owner"],
267282
"name": repo["name"],
268283
"external_id": repo["external_id"],
269-
"languages": repo["languages"],
284+
"languages": language_map.get(key, []),
270285
"integration_id": repo["integration_id"],
271286
}
272287

0 commit comments

Comments
 (0)