Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
github: fixed authors serialization.
Browse files Browse the repository at this point in the history
alejandromumo committed Oct 16, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 484ccc7 commit 08524ff
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions invenio_rdm_records/services/github/metadata.py
Original file line number Diff line number Diff line change
@@ -86,19 +86,30 @@ def contributors(self):
def serialize_author(gh_data):
"""Serializes github contributor data into RDM author."""
login = gh_data["login"]
name = gh_data.get("name", login)
company = gh_data.get("company", "")
# Default name to the user's login
name = gh_data.get("name") or login
company = gh_data.get("company") or ""

author = {}
if name.count(",") == 1:

total_commas = name.count(",")

# Case of "John Doe"
if total_commas == 0:
author["given_name"] = name
author["family_name"] = name
# Case of "Doe, John"
elif total_commas == 1:
family, given = name.split(",")
author["given_name"] = given.strip()
author["family_name"] = family.strip()
# autocompleted by RDM Metadata schema
author["name"] = name
# Case of "Mr, Doe, John, the Second"
else:
author["family_name"] = name
author["name"] = name
family, given = name.split(
",", 1
) # stop at the first occurrence, otherwise raises
author["given_name"] = given.strip()
author["family_name"] = family.strip()

rdm_contributor = {
"person_or_org": {
@@ -114,7 +125,8 @@ def serialize_author(gh_data):
# Get contributors from api
for c in self.rdm_release.contributors:
rdm_author = serialize_author(c)
contributors.append(rdm_author)
if rdm_author:
contributors.append(rdm_author)

return contributors

0 comments on commit 08524ff

Please sign in to comment.