diff --git a/invenio_rdm_records/services/github/metadata.py b/invenio_rdm_records/services/github/metadata.py index c8d16392e3..31be714d3a 100644 --- a/invenio_rdm_records/services/github/metadata.py +++ b/invenio_rdm_records/services/github/metadata.py @@ -68,13 +68,14 @@ def default_metadata(self): return dict( description=self.description, - rights={"id": default_right}, + rights=[{"id": default_right}], publication_date=self.rdm_release.release_payload["published_at"][:10], related_identifiers=[self.related_identifiers], version=version, title=self.title, resource_type={"id": "software"}, creators=self.contributors, + publisher=current_app.config.get("APP_RDM_DEPOSIT_FORM_DEFAULTS").get("publisher", "CERN"), ) @property diff --git a/invenio_rdm_records/services/github/release.py b/invenio_rdm_records/services/github/release.py index 808f90158d..ea3bd538c0 100644 --- a/invenio_rdm_records/services/github/release.py +++ b/invenio_rdm_records/services/github/release.py @@ -37,6 +37,27 @@ def resolve_record(self): recid = retrieve_recid_by_uuid(self.release_object.record_id) return current_rdm_records_service.read(system_identity, recid.pid_value) + def _upload_files_to_draft(self, draft, draft_file_service, uow): + """Upload files to draft.""" + # Validate the release files are fetchable + self.test_zipball() + + draft_file_service.init_files( + self.user_identity, + draft.id, + data=[{"key": self.release_file_name}], + uow=uow, + ) + + with self.fetch_zipball_file() as file_stream: + draft_file_service.set_file_content( + self.user_identity, + draft.id, + self.release_file_name, + file_stream, + uow=uow, + ) + def publish(self): """Publish GitHub release as record. @@ -57,6 +78,8 @@ def publish(self): # Commit state change, in case the publishing is stuck db.session.commit() + draft_file_service = current_rdm_records_service.draft_files + with UnitOfWork(db.session) as uow: data = { "metadata": self.metadata, @@ -68,6 +91,7 @@ def publish(self): draft = current_rdm_records_service.create( self.user_identity, data, uow=uow ) + self._upload_files_to_draft(draft, draft_file_service, uow) else: # Retrieve latest record id and its recid latest_record_uuid = self.repository_object.latest_release( @@ -80,30 +104,13 @@ def publish(self): new_version_draft = current_rdm_records_service.new_version( self.user_identity, recid.pid_value, uow=uow ) - draft = current_rdm_records_service.update_draft( - self.user_identity, new_version_draft.id, data, uow=uow - ) - # Validate the release files are fetchable - self.test_zipball() - - # Upload files to draft - draft_file_service = current_rdm_records_service.draft_files - - draft_file_service.init_files( - self.user_identity, - draft.id, - data=[{"key": self.release_file_name}], - uow=uow, - ) + self._upload_files_to_draft( + new_version_draft, draft_file_service, uow + ) - with self.fetch_zipball_file() as file_stream: - draft_file_service.set_file_content( - self.user_identity, - draft.id, - self.release_file_name, - file_stream, - uow=uow, + draft = current_rdm_records_service.update_draft( + self.user_identity, new_version_draft.id, data, uow=uow ) draft_file_service.commit_file(