diff --git a/backend/utils/_tests/test_github.py b/backend/utils/_tests/test_github.py index 7cab458e3..4d068f43f 100644 --- a/backend/utils/_tests/test_github.py +++ b/backend/utils/_tests/test_github.py @@ -59,4 +59,4 @@ def test_valid_citation(self): def test_invalid_citation(self): citation_str = """Ha? What is this?""" citations = get_citations(citation_str) - assert citations['citation'] is None + assert citations is None diff --git a/backend/utils/github.py b/backend/utils/github.py index dea81d8a0..735c5b7fe 100644 --- a/backend/utils/github.py +++ b/backend/utils/github.py @@ -105,7 +105,9 @@ def get_github_metadata(repo_url: str) -> dict: citation_file = get_file(repo_url, "CITATION.cff") if citation_file is not None: - github_metadata['citations'] = get_citations(citation_file) + citation = get_citations(citation_file) + if citation: + github_metadata['citations'] = citation if 'visibility' not in github_metadata: github_metadata['visibility'] = 'public' @@ -127,11 +129,11 @@ def get_github_metadata(repo_url: str) -> dict: return github_metadata -def get_citations(citation_str: str) -> Dict[str, Union[str, None]]: +def get_citations(citation_str: str) -> Union[Dict[str, str], None]: """ Get citation information from the string. :param citation_str: citation string to parse - :return: citation dictionary with parsed citation of different formats + :return: citation dictionary with parsed citation of different formats, None if not valid citation """ try: citation = Citation(cffstr=citation_str) @@ -143,7 +145,7 @@ def get_citations(citation_str: str) -> Dict[str, Union[str, None]]: } except ValueError: # invalid CITATION.cff content - return dict.fromkeys(['citation', 'RIS', 'BibTex', 'APA'], None) + return None def get_artifact(url: str, token: str) -> Union[IO[bytes], None]: