Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0cb9d29
Initial commit
rohitvinnakota-codecov Jan 15, 2025
85caf80
Merge branch 'main' of https://github.com/codecov/codecov-api into rv…
rohitvinnakota-codecov Feb 11, 2025
7c0bf38
update
rohitvinnakota-codecov Feb 11, 2025
91fd9cd
Update tests
rohitvinnakota-codecov Feb 18, 2025
d047c5b
Update
rohitvinnakota-codecov Feb 18, 2025
f8e566c
Merge branch 'main' into rvinnakota/update-ai-repo
rohitvinnakota-codecov Feb 18, 2025
7111b1b
Update
rohitvinnakota-codecov Feb 18, 2025
87c2414
Merge branch 'rvinnakota/update-ai-repo' of https://github.com/codeco…
rohitvinnakota-codecov Feb 18, 2025
4601365
Lint
rohitvinnakota-codecov Feb 18, 2025
333ff4c
Update return type
rohitvinnakota-codecov Feb 18, 2025
3763fb7
CI headaches
rohitvinnakota-codecov Feb 18, 2025
d987ef7
Try new approach
rohitvinnakota-codecov Feb 20, 2025
de1f3de
Tests
rohitvinnakota-codecov Feb 20, 2025
30dfe70
Merge branch 'main' of https://github.com/codecov/codecov-api into rv…
rohitvinnakota-codecov Feb 20, 2025
1ef6d08
Undo
rohitvinnakota-codecov Feb 20, 2025
4dd984d
Sort
rohitvinnakota-codecov Feb 20, 2025
c0fd454
Update params
rohitvinnakota-codecov Feb 20, 2025
a54ff4f
Merge branch 'main' into rvinnakota/update-ai-repo
rohitvinnakota-codecov Feb 20, 2025
662df84
Try fix flakes
rohitvinnakota-codecov Feb 21, 2025
2404b9d
Merge branch 'rvinnakota/update-ai-repo' of https://github.com/codeco…
rohitvinnakota-codecov Feb 21, 2025
0c82122
Update tests
rohitvinnakota-codecov Feb 21, 2025
82bbbc9
lint
rohitvinnakota-codecov Feb 21, 2025
a7be526
Merge branch 'main' into rvinnakota/update-ai-repo
rohitvinnakota-codecov Feb 24, 2025
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
40 changes: 34 additions & 6 deletions graphql_api/actions/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@

import sentry_sdk
from django.db.models import QuerySet
from shared.django_apps.codecov_auth.models import Owner
from shared.django_apps.codecov_auth.models import GithubAppInstallation, Owner
from shared.django_apps.core.models import Repository

from graphql_api.types.owner.owner import AI_FEATURES_GH_APP_ID

log = logging.getLogger(__name__)


def apply_filters_to_queryset(
queryset: QuerySet, filters: dict[str, Any] | None
queryset: QuerySet, filters: dict[str, Any] | None, owner: Owner
) -> QuerySet:
filters = filters or {}
term = filters.get("term")
active = filters.get("active")
activated = filters.get("activated")
repo_names = filters.get("repo_names")
is_public = filters.get("is_public")
ai_enabled = filters.get("ai_enabled")

if repo_names:
queryset = queryset.filter(name__in=repo_names)
Expand All @@ -29,6 +32,25 @@ def apply_filters_to_queryset(
queryset = queryset.filter(active=active)
if is_public is not None:
queryset = queryset.filter(private=not is_public)
if is_public is not None:
Comment thread
rohitvinnakota-codecov marked this conversation as resolved.
Outdated
queryset = queryset.filter(private=not is_public)
if ai_enabled is not None:
queryset = filter_queryset_by_ai_enabled_repos(queryset, owner)
return queryset


def filter_queryset_by_ai_enabled_repos(queryset: QuerySet, owner: Owner) -> QuerySet:
ai_features_app_install = GithubAppInstallation.objects.filter(
app_id=AI_FEATURES_GH_APP_ID, owner=owner
).first()

if not ai_features_app_install:
return Repository.objects.none()

if ai_features_app_install.repository_service_ids:
queryset = queryset.filter(
service_id__in=ai_features_app_install.repository_service_ids
)

return queryset

Expand All @@ -43,14 +65,20 @@ def list_repository_for_owner(
) -> QuerySet:
queryset = Repository.objects.viewable_repos(current_owner)

ai_enabled_filter = filters.get("ai_enabled")

if ai_enabled_filter:
return filter_queryset_by_ai_enabled_repos(queryset, owner)

if exclude_okta_enforced_repos:
queryset = queryset.exclude_accounts_enforced_okta(okta_account_auths)

queryset = (
queryset.with_recent_coverage().with_latest_commit_at().filter(author=owner)
)
if not ai_enabled_filter:
queryset = (
queryset.with_recent_coverage().with_latest_commit_at().filter(author=owner)
)

queryset = apply_filters_to_queryset(queryset, filters)
queryset = apply_filters_to_queryset(queryset, filters, owner)
return queryset


Expand Down
1 change: 1 addition & 0 deletions graphql_api/types/inputs/repository_set_filters.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ input RepositorySetFilters {
active: Boolean
activated: Boolean
isPublic: Boolean
aiEnabled: Boolean
}
5 changes: 3 additions & 2 deletions graphql_api/types/owner/owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from graphql_api.helpers.connection import (
Connection,
build_connection_graphql,
queryset_to_connection,
queryset_to_connection_sync,
)
from graphql_api.helpers.mutation import (
require_part_of_org,
Expand All @@ -54,6 +54,7 @@


@owner_bindable.field("repositories")
@sync_to_async
def resolve_repositories(
owner: Owner,
info: GraphQLResolveInfo,
Expand All @@ -76,7 +77,7 @@ def resolve_repositories(
current_owner, owner, filters, okta_account_auths, exclude_okta_enforced_repos
)

return queryset_to_connection(
return queryset_to_connection_sync(
queryset,
ordering=(ordering, RepositoryOrdering.ID),
ordering_direction=ordering_direction,
Expand Down
2 changes: 1 addition & 1 deletion utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ def setUp(self) -> None:
self.apps = executor.loader.project_state(self.migrate_to).apps

def setUpBeforeMigration(self, apps: Any) -> None:
pass
pass