Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitvinnakota-codecov committed Sep 9, 2024
1 parent 2307921 commit 269eacf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
27 changes: 19 additions & 8 deletions graphql_api/tests/test_owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,28 @@ def setUp(self):
self.okta_settings = OktaSettingsFactory(account=self.account, enforced=True)
random_user = OwnerFactory(username="random-user", service="github")
RepositoryFactory(
author=self.owner, active=True, activated=True, private=True, name="a", service_id="repo-1"
author=self.owner,
active=True,
activated=True,
private=True,
name="a",
service_id="repo-1",
)
RepositoryFactory(
author=self.owner, active=False, activated=False, private=False, name="b", service_id="repo-2"
author=self.owner,
active=False,
activated=False,
private=False,
name="b",
service_id="repo-2",
)
RepositoryFactory(
author=random_user, active=True, activated=False, private=True, name="not", service_id="repo-3"
author=random_user,
active=True,
activated=False,
private=True,
name="not",
service_id="repo-3",
)

def test_fetching_repositories(self):
Expand Down Expand Up @@ -835,9 +850,7 @@ def test_fetch_is_github_rate_limited_not_on_gh_service(self):
assert data["owner"]["isGithubRateLimited"] == False

@patch("services.self_hosted.get_config")
def test_ai_features_enabled(
self, get_config_mock
):
def test_ai_features_enabled(self, get_config_mock):
current_org = OwnerFactory(
username="random-plan-user",
service="github",
Expand Down Expand Up @@ -878,7 +891,6 @@ def test_fetch_repos_ai_features_enabled(self, get_config_mock):
{"service": "github", "ai_features_app_id": 12345},
]


ai_app_installation = GithubAppInstallation(
name="ai-features",
owner=current_org,
Expand All @@ -888,7 +900,6 @@ def test_fetch_repos_ai_features_enabled(self, get_config_mock):

ai_app_installation.save()


query = query_repositories % (
self.owner.username,
"(filters: { isAiFeaturesEnabled: true })",
Expand Down
7 changes: 5 additions & 2 deletions graphql_api/types/owner/owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from services.redis_configuration import get_redis_connection
from timeseries.helpers import fill_sparse_measurements
from timeseries.models import Interval, MeasurementSummary
from utils.config import get_config

owner = ariadne_load_local_graphql(__file__, "owner.graphql")
owner = owner + build_connection_graphql("RepositoryConnection", "Repository")
Expand Down Expand Up @@ -338,5 +339,7 @@ def resolve_delinquent(owner: Owner, info) -> bool | None:
@owner_bindable.field("aiFeaturesEnabled")
@require_part_of_org
def resolve_ai_features_enabled(owner: Owner, info) -> bool | None:
# TODO: Update with proper app id once finalized
return GithubAppInstallation.objects.filter(app_id="TBD", owner=owner).exists()
ai_features_gh_app_id = get_config("github", "ai_features_app_id")
return GithubAppInstallation.objects.filter(
app_id=ai_features_gh_app_id, owner=owner
).exists()

0 comments on commit 269eacf

Please sign in to comment.