Skip to content

Commit

Permalink
github: fix metadata validation issues
Browse files Browse the repository at this point in the history
  • Loading branch information
anikachurilova committed Jul 21, 2023
1 parent 28d9787 commit 6970c48
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
3 changes: 2 additions & 1 deletion invenio_rdm_records/services/github/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 29 additions & 22 deletions invenio_rdm_records/services/github/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand All @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit 6970c48

Please sign in to comment.