diff --git a/graphql_api/tests/test_repository.py b/graphql_api/tests/test_repository.py index e7978d1ccd..ea5c53e3da 100644 --- a/graphql_api/tests/test_repository.py +++ b/graphql_api/tests/test_repository.py @@ -5,6 +5,7 @@ from freezegun import freeze_time from codecov_auth.tests.factories import OwnerFactory +from core import models from core.tests.factories import ( CommitFactory, PullFactory, @@ -69,6 +70,7 @@ graphToken yaml isATSConfigured + primaryLanguage bot { username } """ @@ -97,7 +99,12 @@ def setUp(self): @freeze_time("2021-01-01") def test_when_repository_has_no_coverage(self): repo = RepositoryFactory( - author=self.owner, active=True, private=True, name="a", yaml=self.yaml + author=self.owner, + active=True, + private=True, + name="a", + yaml=self.yaml, + language="rust", ) profiling_token = RepositoryTokenFactory( repository_id=repo.repoid, token_type="profiling" @@ -124,6 +131,7 @@ def test_when_repository_has_no_coverage(self): "graphToken": graphToken, "yaml": "test: test\n", "isATSConfigured": False, + "primaryLanguage": "rust", "bot": None, } @@ -135,6 +143,7 @@ def test_when_repository_has_coverage(self): private=True, name="b", yaml=self.yaml, + language="erlang", ) hour_ago = datetime.datetime.now() - datetime.timedelta(hours=1) @@ -175,6 +184,7 @@ def test_when_repository_has_coverage(self): "graphToken": graphToken, "yaml": "test: test\n", "isATSConfigured": False, + "primaryLanguage": "erlang", "bot": None, } @@ -439,3 +449,11 @@ def test_repository_has_ats_configured(self): res = self.fetch_repository(repo.name) assert res["isATSConfigured"] == True + + def test_repository_get_language(self): + repo = RepositoryFactory( + author=self.owner, active=True, private=True, language="python" + ) + + res = self.fetch_repository(repo.name) + assert res["primaryLanguage"] == "python" diff --git a/graphql_api/types/repository/repository.graphql b/graphql_api/types/repository/repository.graphql index cdae8032ca..0a92a627e6 100644 --- a/graphql_api/types/repository/repository.graphql +++ b/graphql_api/types/repository/repository.graphql @@ -64,6 +64,7 @@ type Repository { repositoryConfig: RepositoryConfig staticAnalysisToken: String isATSConfigured: Boolean + primaryLanguage: String } type PullConnection { diff --git a/graphql_api/types/repository/repository.py b/graphql_api/types/repository/repository.py index c37f0a6e9c..a9466b743a 100644 --- a/graphql_api/types/repository/repository.py +++ b/graphql_api/types/repository/repository.py @@ -323,6 +323,11 @@ def resolve_repository_config(repository: Repository, info): return repository +@repository_bindable.field("primaryLanguage") +def resolve_languate(repository: Repository, info): + return repository.language + + repository_result_bindable = UnionType("RepositoryResult")