Skip to content

Commit

Permalink
metadata: fix empty affiliations.
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandromumo authored and zzacharo committed Oct 17, 2023
1 parent 30ab064 commit 7b08f35
Showing 1 changed file with 6 additions and 26 deletions.
32 changes: 6 additions & 26 deletions invenio_rdm_records/services/github/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,39 +91,19 @@ def contributors(self):

def serialize_author(gh_data):
"""Serializes github contributor data into RDM author."""
login = gh_data["login"]
gh_username = gh_data["login"]
# Default name to the user's login
name = gh_data.get("name") or login
company = gh_data.get("company") or ""

author = {}

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()
# Case of "Mr, Doe, John, the Second"
else:
family, given = name.split(
",", 1
) # stop at the first occurrence, otherwise raises
author["given_name"] = given.strip()
author["family_name"] = family.strip()
name = gh_data.get("name") or gh_username
company = gh_data.get("company")

rdm_contributor = {
"person_or_org": {
"type": "personal",
**author,
"family_name": name
},
"affiliations": [{"name": company}],
}
if company:
rdm_contributor.update({"affiliations": [{"name": company}]})
return rdm_contributor

contributors = []
Expand Down

0 comments on commit 7b08f35

Please sign in to comment.