Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Enable pagination for AI enabled repos #1101

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions graphql_api/tests/test_owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,49 @@ 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

def test_fetch_owner_with_no_service(self):
current_org = OwnerFactory(
username="random-plan-user",
Expand Down
8 changes: 8 additions & 0 deletions graphql_api/types/owner/owner.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,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"])
rohitvinnakota-codecov marked this conversation as resolved.
Show resolved Hide resolved
uploadTokenRequired: Boolean
activatedUserCount: Int
}
rohitvinnakota-codecov marked this conversation as resolved.
Show resolved Hide resolved
30 changes: 30 additions & 0 deletions graphql_api/types/owner/owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,33 @@
@require_part_of_org
def resolve_billing(owner: Owner, info: GraphQLResolveInfo) -> dict | None:
return owner

@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 417 in graphql_api/types/owner/owner.py

View check run for this annotation

Codecov Notifications / codecov/patch

graphql_api/types/owner/owner.py#L417

Added line #L417 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 422 in graphql_api/types/owner/owner.py

View check run for this annotation

Codecov Notifications / codecov/patch

graphql_api/types/owner/owner.py#L421-L422

Added lines #L421 - L422 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 425 in graphql_api/types/owner/owner.py

View check run for this annotation

Codecov Notifications / codecov/patch

graphql_api/types/owner/owner.py#L424-L425

Added lines #L424 - L425 were not covered by tests

if ai_features_app_install.repository_service_ids:
queryset = queryset.filter(

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

View check run for this annotation

Codecov Notifications / codecov/patch

graphql_api/types/owner/owner.py#L427-L428

Added lines #L427 - L428 were not covered by tests
service_id__in=ai_features_app_install.repository_service_ids
)

return queryset_to_connection(

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

View check run for this annotation

Codecov Notifications / codecov/patch

graphql_api/types/owner/owner.py#L432

Added line #L432 was not covered by tests
queryset,
ordering=(ordering, RepositoryOrdering.ID),
ordering_direction=ordering_direction,
**kwargs,
)
rohitvinnakota-codecov marked this conversation as resolved.
Show resolved Hide resolved
rohitvinnakota-codecov marked this conversation as resolved.
Show resolved Hide resolved
rohitvinnakota-codecov marked this conversation as resolved.
Show resolved Hide resolved
Loading