From d93d514e2b67837ff7df460a7401ae96c6c9e572 Mon Sep 17 00:00:00 2001 From: alejandromumo Date: Tue, 26 Nov 2024 16:53:54 +0100 Subject: [PATCH] github: add default license from Github API --- site/zenodo_rdm/github/release.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/site/zenodo_rdm/github/release.py b/site/zenodo_rdm/github/release.py index b1dff64a..1a2a4e63 100644 --- a/site/zenodo_rdm/github/release.py +++ b/site/zenodo_rdm/github/release.py @@ -12,7 +12,6 @@ from invenio_github.errors import CustomGitHubMetadataError from invenio_rdm_records.services.github.metadata import RDMReleaseMetadata from invenio_rdm_records.services.github.release import RDMGithubRelease - from zenodo_rdm.github.schemas import CitationMetadataSchema from zenodo_rdm.legacy.deserializers.schemas import LegacySchema @@ -28,7 +27,10 @@ def load_extra_metadata(self): if not content: # File does not exists return {} - legacy_data = {"metadata": json.loads(content.decoded.decode("utf-8"))} + file_data = json.loads(content.decoded.decode("utf-8")) + if not file_data.get("license") and self.repo_license: + file_data.update({"license": self.repo_license}) + legacy_data = {"metadata": file_data} rdm_data = LegacySchema().load(legacy_data) return rdm_data["metadata"] except Exception as exc: @@ -51,6 +53,8 @@ def load_citation_metadata(self, data): ) try: + if not data.get("license") and self.repo_license: + data.update({"license": self.repo_license}) legacy_data = {"metadata": CitationMetadataSchema().load(data)} rdm_data = LegacySchema().load(legacy_data) return rdm_data["metadata"] @@ -105,4 +109,7 @@ def metadata(self): ] } ) + # Add default license if not yet added + if not output.get("rights"): + output.update({"rights": [{"id": metadata.repo_license or "cc-by-4.0"}]}) return output