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

Commit 0cb9d29

Browse files
Initial commit
1 parent ddb4755 commit 0cb9d29

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

graphql_api/tests/test_owner.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,3 +1202,46 @@ def test_fetch_available_plans_is_enterprise_plan(self):
12021202
]
12031203
}
12041204
}
1205+
1206+
@patch("services.self_hosted.get_config")
1207+
def test_ai_enabled_repositories(self, get_config_mock):
1208+
current_org = OwnerFactory(
1209+
username="random-plan-user",
1210+
service="github",
1211+
)
1212+
1213+
get_config_mock.return_value = [
1214+
{"service": "github", "ai_features_app_id": 12345},
1215+
]
1216+
1217+
query = """{
1218+
owner(username: "%s") {
1219+
aiEnabledRepos
1220+
}
1221+
}
1222+
1223+
""" % (current_org.username)
1224+
data = self.gql_request(query, owner=current_org)
1225+
assert data["owner"]["aiEnabledRepos"] is None
1226+
1227+
1228+
@patch("services.self_hosted.get_config")
1229+
def test_ai_enabled_repositories_app_not_configured(self, get_config_mock):
1230+
current_org = OwnerFactory(
1231+
username="random-plan-user",
1232+
service="github",
1233+
)
1234+
1235+
get_config_mock.return_value = [
1236+
{"service": "github", "ai_features_app_id": 12345},
1237+
]
1238+
1239+
query = """{
1240+
owner(username: "%s") {
1241+
aiEnabledRepos
1242+
}
1243+
}
1244+
1245+
""" % (current_org.username)
1246+
data = self.gql_request(query, owner=current_org)
1247+
assert data["owner"]["aiEnabledRepos"] is None

graphql_api/types/owner/owner.graphql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ type Owner {
3939
yaml: String
4040
aiFeaturesEnabled: Boolean!
4141
aiEnabledRepos: [String]
42+
aiEnabledRepositories(
43+
ordering: RepositoryOrdering
44+
orderingDirection: OrderingDirection
45+
first: Int
46+
after: String
47+
last: Int
48+
before: String
49+
): RepositoryConnection! @cost(complexity: 25, multipliers: ["first", "last"])
4250
uploadTokenRequired: Boolean
4351
activatedUserCount: Int
4452
}

graphql_api/types/owner/owner.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,33 @@ def resolve_upload_token_required(
396396
@require_shared_account_or_part_of_org
397397
def resolve_activated_user_count(owner: Owner, info: GraphQLResolveInfo) -> int:
398398
return owner.activated_user_count
399+
400+
@owner_bindable.field("aiEnabledRepositories")
401+
def resolve_ai_enabled_repositories(
402+
owner: Owner,
403+
info: GraphQLResolveInfo,
404+
ordering: Optional[RepositoryOrdering] = RepositoryOrdering.ID,
405+
ordering_direction: Optional[OrderingDirection] = OrderingDirection.ASC,
406+
**kwargs: Any,
407+
) -> Coroutine[Any, Any, Connection]:
408+
ai_features_app_install = GithubAppInstallation.objects.filter(
409+
app_id=AI_FEATURES_GH_APP_ID, owner=owner
410+
).first()
411+
412+
if not ai_features_app_install:
413+
return None
414+
415+
current_owner = info.context["request"].current_owner
416+
queryset = Repository.objects.filter(author=owner).viewable_repos(current_owner)
417+
418+
if ai_features_app_install.repository_service_ids:
419+
queryset = queryset.filter(
420+
service_id__in=ai_features_app_install.repository_service_ids
421+
)
422+
423+
return queryset_to_connection(
424+
queryset,
425+
ordering=(ordering, RepositoryOrdering.ID),
426+
ordering_direction=ordering_direction,
427+
**kwargs,
428+
)

0 commit comments

Comments
 (0)