Skip to content

Commit

Permalink
Add timestamp to jsonschema (#38)
Browse files Browse the repository at this point in the history
Summary of the issue
Add-on metadata may accept a timestamp, to sort add-ons or perform other queries.

Development approach
Update the json schema to accept an optional "submissionTime", corresponding to a timestamp. We use milliseconds instead of seconds, in case similar values are added in the future, for a better comparison.
When creating a json file, the current time will be assigned to submissionTime.
Updated tests, removing the submissionTime before comparing actual and expected json files.
  • Loading branch information
nvdaes authored Sep 17, 2024
1 parent d166e55 commit 888b38f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
3 changes: 2 additions & 1 deletion _tests/test_createJson.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

# Copyright (C) 2022 Noelia Ruiz Martínez, NV Access Limited
# Copyright (C) 2022-2024 Noelia Ruiz Martínez, NV Access Limited
# This file may be used under the terms of the GNU General Public License, version 2 or later.
# For more details see: https://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -79,6 +79,7 @@ def _assertJsonFilesEqual(self, actualJsonPath: str, expectedJsonPath: str):
del expectedJson["sha256-comment"] # remove explanatory comment
with open(actualJsonPath) as actualFile:
actualJson = json.load(actualFile)
del actualJson["submissionTime"] # remove submission time

self.assertDictEqual(actualJson, expectedJson)

Expand Down
14 changes: 12 additions & 2 deletions _validate/addonVersion_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
"description": "erleichtert das Durchführen von xyz"
}
],
"reviewUrl": "https://github.com/nvaccess/addon-datastore/discussions/1942#discussioncomment-7453248"
"reviewUrl": "https://github.com/nvaccess/addon-datastore/discussions/1942#discussioncomment-7453248",
"submissionTime": 1723523492363
}

],
"title": "Root",
"type": "object",
Expand Down Expand Up @@ -266,6 +266,16 @@
"title": "Discussion comment URL",
"type": "string"
},
"submissionTime": {
"$id": "#/properties/submissionTime",
"default": 0,
"description": "Timestamp in milliseconds, corresponding to the submission time of the add-on",
"examples": [
1723523492363
],
"title": "Submission time",
"type": "number"
},
"vtScanUrl": {
"$id": "#/properties/vtScanUrl",
"default": "",
Expand Down
9 changes: 8 additions & 1 deletion _validate/createJson.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env python

# Copyright (C) 2022-2023 Noelia Ruiz Martínez, NV Access Limited
# Copyright (C) 2022-2024 Noelia Ruiz Martínez, NV Access Limited
# This file may be used under the terms of the GNU General Public License, version 2 or later.
# For more details see: https://www.gnu.org/licenses/gpl-2.0.html

from time import gmtime, mktime
import dataclasses
import json
import argparse
Expand Down Expand Up @@ -31,6 +33,10 @@ def getSha256(addonPath: str) -> str:
return sha256Addon


def getCurrentTime() -> int:
return int(mktime(gmtime()) * 1000) # Milliseconds


def generateJsonFile(
manifest: AddonManifest,
addonPath: str,
Expand Down Expand Up @@ -121,6 +127,7 @@ def _createDictMatchingJsonSchema(
addonData["homepage"] = homepage
if licenseUrl:
addonData["licenseURL"] = licenseUrl
addonData["submissionTime"] = getCurrentTime()

addonData["translations"] = []
for langCode, manifest in getAddonManifestLocalizations(manifest):
Expand Down

0 comments on commit 888b38f

Please sign in to comment.