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

only set citation value when valid citation presents #301

Merged
merged 1 commit into from
Oct 25, 2021
Merged
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
2 changes: 1 addition & 1 deletion backend/utils/_tests/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 6 additions & 4 deletions backend/utils/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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)
Expand All @@ -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]:
Expand Down