diff --git a/swh/loader/package/deposit/loader.py b/swh/loader/package/deposit/loader.py --- a/swh/loader/package/deposit/loader.py +++ b/swh/loader/package/deposit/loader.py @@ -71,10 +71,7 @@ def build_revision( self, a_metadata: Dict, uncompressed_path: str, directory: Sha1Git ) -> Optional[Revision]: - # FIXME: the deposit read api should no longer need to build the revision entry - # as this would avoid unnecessary indirection. This would also align with what - # other package loaders do - revision_data = a_metadata.pop("revision") + depo = a_metadata.pop("deposit") # Note: # `date` and `committer_date` are always transmitted by the deposit read api @@ -82,18 +79,23 @@ # revision. # date: codemeta:dateCreated if any, deposit completed_date otherwise - date = TimestampWithTimezone.from_dict(revision_data["date"]) + date = TimestampWithTimezone.from_dict(depo["author_date"]) # commit_date: codemeta:datePublished if any, deposit completed_date otherwise - commit_date = TimestampWithTimezone.from_dict(revision_data["committer_date"]) + commit_date = TimestampWithTimezone.from_dict(depo["committer_date"]) + + name, id, collection = [depo[k] for k in ["fullname", "id", "collection"]] + message = f"{name}: Deposit {id} in collection {collection}".encode("utf-8") + + author = parse_author(depo["author"]) return Revision( type=RevisionType.TAR, - message=revision_data["message"].encode("utf-8"), - author=parse_author(revision_data["author"]), + message=message, + author=author, date=date, - committer=parse_author(revision_data["committer"]), + committer=author, committer_date=commit_date, - parents=[hash_to_bytes(p) for p in revision_data.get("parents", [])], + parents=[hash_to_bytes(p) for p in depo["revision_parents"]], directory=directory, synthetic=True, metadata={ diff --git a/swh/loader/package/deposit/tests/data/https_deposit.softwareheritage.org/hello_2.10.json b/swh/loader/package/deposit/tests/data/https_deposit.softwareheritage.org/hello_2.10.json --- a/swh/loader/package/deposit/tests/data/https_deposit.softwareheritage.org/hello_2.10.json +++ b/swh/loader/package/deposit/tests/data/https_deposit.softwareheritage.org/hello_2.10.json @@ -31,8 +31,7 @@ } } }, - "revision": { - "synthetic": true, + "deposit": { "committer_date": { "timestamp": { "seconds": 1507389428, @@ -41,18 +40,15 @@ "offset": 0, "negative_utc": false }, - "message": "hal: Deposit 666 in collection hal", + "fullname": "hal", + "id": "666", + "collection":"hal", "author": { "name": "Software Heritage", "fullname": "Software Heritage", "email": "robot@softwareheritage.org" }, - "committer": { - "name": "Software Heritage", - "fullname": "Software Heritage", - "email": "robot@softwareheritage.org" - }, - "date": { + "author_date": { "timestamp": { "seconds": 1507389428, "microseconds": 0 @@ -60,21 +56,7 @@ "offset": 0, "negative_utc": false }, - "metadata": { - "@xmlns": [ - "http://www.w3.org/2005/Atom" - ], - "author": [ - "some awesome author", - "another one", - "no one" - ], - "external_identifier": "some-external-id", - "codemeta:dateCreated": "2017-10-07T15:17:08Z", - "url": "https://hal-test.archives-ouvertes.fr/some-external-id" - }, - "type": "tar", - "parents": [] + "revision_parents": [] }, "branch_name": "master" } diff --git a/swh/loader/package/deposit/tests/data/https_deposit.softwareheritage.org/hello_2.11.json b/swh/loader/package/deposit/tests/data/https_deposit.softwareheritage.org/hello_2.11.json --- a/swh/loader/package/deposit/tests/data/https_deposit.softwareheritage.org/hello_2.11.json +++ b/swh/loader/package/deposit/tests/data/https_deposit.softwareheritage.org/hello_2.11.json @@ -32,8 +32,7 @@ } } }, - "revision": { - "synthetic": true, + "deposit": { "committer_date": { "timestamp": { "seconds": 1507474800, @@ -42,18 +41,15 @@ "offset": 0, "negative_utc": false }, - "message": "hal: Deposit 777 in collection hal", + "fullname": "hal", + "id": 777, + "collection": "hal", "author": { "name": "Software Heritage", "fullname": "Software Heritage", "email": "robot@softwareheritage.org" }, - "committer": { - "name": "Software Heritage", - "fullname": "Software Heritage", - "email": "robot@softwareheritage.org" - }, - "date": { + "author_date": { "timestamp": { "seconds": 1507389428, "microseconds": 0 @@ -61,22 +57,7 @@ "offset": 0, "negative_utc": false }, - "metadata": { - "@xmlns": [ - "http://www.w3.org/2005/Atom" - ], - "author": [ - "some awesome author", - "another one", - "no one" - ], - "external_identifier": "some-external-id", - "codemeta:dateCreated": "2017-10-07T15:17:08Z", - "codemeta:datePublished": "2017-10-08T15:00:00Z", - "url": "https://hal-test.archives-ouvertes.fr/some-external-id" - }, - "type": "tar", - "parents": [] + "revision_parents": [] }, "branch_name": "master" } diff --git a/swh/loader/package/deposit/tests/test_deposit.py b/swh/loader/package/deposit/tests/test_deposit.py --- a/swh/loader/package/deposit/tests/test_deposit.py +++ b/swh/loader/package/deposit/tests/test_deposit.py @@ -253,5 +253,5 @@ # Retrieve the revision revision = next(loader.storage.revision_get([hash_to_bytes(revision_id)])) assert revision - for field_date in ["committer_date", "date"]: - assert revision[field_date] == raw_meta["revision"][field_date] + assert revision["committer_date"] == raw_meta["deposit"]["committer_date"] + assert revision["date"] == raw_meta["deposit"]["author_date"]