Skip to content

Commit 888b38f

Browse files
authored
Add timestamp to jsonschema (#38)
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.
1 parent d166e55 commit 888b38f

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

_tests/test_createJson.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

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

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

8384
self.assertDictEqual(actualJson, expectedJson)
8485

_validate/addonVersion_schema.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
"description": "erleichtert das Durchführen von xyz"
3636
}
3737
],
38-
"reviewUrl": "https://github.com/nvaccess/addon-datastore/discussions/1942#discussioncomment-7453248"
38+
"reviewUrl": "https://github.com/nvaccess/addon-datastore/discussions/1942#discussioncomment-7453248",
39+
"submissionTime": 1723523492363
3940
}
40-
4141
],
4242
"title": "Root",
4343
"type": "object",
@@ -266,6 +266,16 @@
266266
"title": "Discussion comment URL",
267267
"type": "string"
268268
},
269+
"submissionTime": {
270+
"$id": "#/properties/submissionTime",
271+
"default": 0,
272+
"description": "Timestamp in milliseconds, corresponding to the submission time of the add-on",
273+
"examples": [
274+
1723523492363
275+
],
276+
"title": "Submission time",
277+
"type": "number"
278+
},
269279
"vtScanUrl": {
270280
"$id": "#/properties/vtScanUrl",
271281
"default": "",

_validate/createJson.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#!/usr/bin/env python
22

3-
# Copyright (C) 2022-2023 Noelia Ruiz Martínez, NV Access Limited
3+
# Copyright (C) 2022-2024 Noelia Ruiz Martínez, NV Access Limited
44
# This file may be used under the terms of the GNU General Public License, version 2 or later.
55
# For more details see: https://www.gnu.org/licenses/gpl-2.0.html
6+
7+
from time import gmtime, mktime
68
import dataclasses
79
import json
810
import argparse
@@ -31,6 +33,10 @@ def getSha256(addonPath: str) -> str:
3133
return sha256Addon
3234

3335

36+
def getCurrentTime() -> int:
37+
return int(mktime(gmtime()) * 1000) # Milliseconds
38+
39+
3440
def generateJsonFile(
3541
manifest: AddonManifest,
3642
addonPath: str,
@@ -121,6 +127,7 @@ def _createDictMatchingJsonSchema(
121127
addonData["homepage"] = homepage
122128
if licenseUrl:
123129
addonData["licenseURL"] = licenseUrl
130+
addonData["submissionTime"] = getCurrentTime()
124131

125132
addonData["translations"] = []
126133
for langCode, manifest in getAddonManifestLocalizations(manifest):

0 commit comments

Comments
 (0)