Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitvinnakota-codecov committed Jan 15, 2025
1 parent ddb4755 commit 0cb9d29
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
43 changes: 43 additions & 0 deletions graphql_api/tests/test_owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -1202,3 +1202,46 @@ def test_fetch_available_plans_is_enterprise_plan(self):
]
}
}

@patch("services.self_hosted.get_config")
def test_ai_enabled_repositories(self, get_config_mock):
current_org = OwnerFactory(
username="random-plan-user",
service="github",
)

get_config_mock.return_value = [
{"service": "github", "ai_features_app_id": 12345},
]

query = """{
owner(username: "%s") {
aiEnabledRepos
}
}
""" % (current_org.username)
data = self.gql_request(query, owner=current_org)
assert data["owner"]["aiEnabledRepos"] is None


@patch("services.self_hosted.get_config")
def test_ai_enabled_repositories_app_not_configured(self, get_config_mock):
current_org = OwnerFactory(
username="random-plan-user",
service="github",
)

get_config_mock.return_value = [
{"service": "github", "ai_features_app_id": 12345},
]

query = """{
owner(username: "%s") {
aiEnabledRepos
}
}
""" % (current_org.username)
data = self.gql_request(query, owner=current_org)
assert data["owner"]["aiEnabledRepos"] is None
8 changes: 8 additions & 0 deletions graphql_api/types/owner/owner.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ type Owner {
yaml: String
aiFeaturesEnabled: Boolean!
aiEnabledRepos: [String]
aiEnabledRepositories(
ordering: RepositoryOrdering
orderingDirection: OrderingDirection
first: Int
after: String
last: Int
before: String
): RepositoryConnection! @cost(complexity: 25, multipliers: ["first", "last"])
uploadTokenRequired: Boolean
activatedUserCount: Int
}
30 changes: 30 additions & 0 deletions graphql_api/types/owner/owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,33 @@ def resolve_upload_token_required(
@require_shared_account_or_part_of_org
def resolve_activated_user_count(owner: Owner, info: GraphQLResolveInfo) -> int:
return owner.activated_user_count

@owner_bindable.field("aiEnabledRepositories")
def resolve_ai_enabled_repositories(
owner: Owner,
info: GraphQLResolveInfo,
ordering: Optional[RepositoryOrdering] = RepositoryOrdering.ID,
ordering_direction: Optional[OrderingDirection] = OrderingDirection.ASC,
**kwargs: Any,
) -> Coroutine[Any, Any, Connection]:
ai_features_app_install = GithubAppInstallation.objects.filter(

Check warning on line 408 in graphql_api/types/owner/owner.py

View check run for this annotation

Codecov Notifications / codecov/patch

graphql_api/types/owner/owner.py#L408

Added line #L408 was not covered by tests
app_id=AI_FEATURES_GH_APP_ID, owner=owner
).first()

if not ai_features_app_install:
return None

Check warning on line 413 in graphql_api/types/owner/owner.py

View check run for this annotation

Codecov Notifications / codecov/patch

graphql_api/types/owner/owner.py#L412-L413

Added lines #L412 - L413 were not covered by tests

current_owner = info.context["request"].current_owner
queryset = Repository.objects.filter(author=owner).viewable_repos(current_owner)

Check warning on line 416 in graphql_api/types/owner/owner.py

View check run for this annotation

Codecov Notifications / codecov/patch

graphql_api/types/owner/owner.py#L415-L416

Added lines #L415 - L416 were not covered by tests

if ai_features_app_install.repository_service_ids:
queryset = queryset.filter(

Check warning on line 419 in graphql_api/types/owner/owner.py

View check run for this annotation

Codecov Notifications / codecov/patch

graphql_api/types/owner/owner.py#L418-L419

Added lines #L418 - L419 were not covered by tests
service_id__in=ai_features_app_install.repository_service_ids
)

return queryset_to_connection(

Check warning on line 423 in graphql_api/types/owner/owner.py

View check run for this annotation

Codecov Notifications / codecov/patch

graphql_api/types/owner/owner.py#L423

Added line #L423 was not covered by tests
queryset,
ordering=(ordering, RepositoryOrdering.ID),
ordering_direction=ordering_direction,
**kwargs,
)

0 comments on commit 0cb9d29

Please sign in to comment.