Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit de9135a

Browse files
Try new approach
1 parent 3763fb7 commit de9135a

File tree

3 files changed

+27
-34
lines changed

3 files changed

+27
-34
lines changed

graphql_api/actions/repository.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33

44
import sentry_sdk
55
from django.db.models import QuerySet
6-
from shared.django_apps.codecov_auth.models import Owner
6+
from shared.django_apps.codecov_auth.models import GithubAppInstallation, Owner
77
from shared.django_apps.core.models import Repository
88

9+
from graphql_api.types.owner.owner import AI_FEATURES_GH_APP_ID
10+
911
log = logging.getLogger(__name__)
1012

1113

@@ -33,6 +35,22 @@ def apply_filters_to_queryset(
3335
return queryset
3436

3537

38+
def filter_queryset_by_ai_enabled_repos(queryset: QuerySet, owner: Owner) -> QuerySet:
39+
ai_features_app_install = GithubAppInstallation.objects.filter(
40+
app_id=AI_FEATURES_GH_APP_ID, owner=owner
41+
).first()
42+
43+
if not ai_features_app_install:
44+
return None
45+
46+
if ai_features_app_install.repository_service_ids:
47+
queryset = queryset.filter(
48+
service_id__in=ai_features_app_install.repository_service_ids
49+
)
50+
51+
return queryset
52+
53+
3654
@sentry_sdk.trace
3755
def list_repository_for_owner(
3856
current_owner: Owner,
@@ -43,6 +61,11 @@ def list_repository_for_owner(
4361
) -> QuerySet:
4462
queryset = Repository.objects.viewable_repos(current_owner)
4563

64+
ai_enabled_filter = filters.get("ai_enabled")
65+
66+
if ai_enabled_filter:
67+
return filter_queryset_by_ai_enabled_repos(queryset, owner)
68+
4669
if exclude_okta_enforced_repos:
4770
queryset = queryset.exclude_accounts_enforced_okta(okta_account_auths)
4871

graphql_api/types/inputs/repository_set_filters.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ input RepositorySetFilters {
44
active: Boolean
55
activated: Boolean
66
isPublic: Boolean
7+
aiEnabled: Boolean
78
}

graphql_api/types/owner/owner.py

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
from graphql_api.helpers.connection import (
3232
Connection,
3333
build_connection_graphql,
34-
queryset_to_connection,
3534
queryset_to_connection_sync,
3635
)
3736
from graphql_api.helpers.mutation import (
@@ -55,6 +54,7 @@
5554

5655

5756
@owner_bindable.field("repositories")
57+
@sync_to_async
5858
def resolve_repositories(
5959
owner: Owner,
6060
info: GraphQLResolveInfo,
@@ -77,7 +77,7 @@ def resolve_repositories(
7777
current_owner, owner, filters, okta_account_auths, exclude_okta_enforced_repos
7878
)
7979

80-
return queryset_to_connection(
80+
return queryset_to_connection_sync(
8181
queryset,
8282
ordering=(ordering, RepositoryOrdering.ID),
8383
ordering_direction=ordering_direction,
@@ -406,34 +406,3 @@ def resolve_activated_user_count(owner: Owner, info: GraphQLResolveInfo) -> int:
406406
@require_part_of_org
407407
def resolve_billing(owner: Owner, info: GraphQLResolveInfo) -> dict | None:
408408
return owner
409-
410-
411-
@owner_bindable.field("aiEnabledRepositories")
412-
@sync_to_async
413-
def resolve_ai_enabled_repositories(
414-
owner: Owner,
415-
info: GraphQLResolveInfo,
416-
ordering: Optional[RepositoryOrdering] = RepositoryOrdering.ID,
417-
ordering_direction: Optional[OrderingDirection] = OrderingDirection.ASC,
418-
**kwargs: Any,
419-
) -> Coroutine[Any, Any, Connection] | None:
420-
ai_features_app_install = GithubAppInstallation.objects.filter(
421-
app_id=AI_FEATURES_GH_APP_ID, owner=owner
422-
).first()
423-
424-
if not ai_features_app_install:
425-
return None
426-
427-
current_owner = info.context["request"].current_owner
428-
queryset = Repository.objects.filter(author=owner).viewable_repos(current_owner)
429-
if ai_features_app_install.repository_service_ids:
430-
queryset = queryset.filter(
431-
service_id__in=ai_features_app_install.repository_service_ids
432-
)
433-
434-
return queryset_to_connection_sync(
435-
queryset,
436-
ordering=(ordering, RepositoryOrdering.ID),
437-
ordering_direction=ordering_direction,
438-
**kwargs,
439-
)

0 commit comments

Comments
 (0)