Add a script to fetch schemas from mozilla-central

This commit is contained in:
Barret Rennie 2022-05-06 21:51:02 -04:00
Родитель afada3f499
Коммит 855e9b11fd
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4D71D86C09132D72
3 изменённых файлов: 49 добавлений и 1 удалений

Просмотреть файл

@ -2,3 +2,4 @@ jsonschema==3.2.0
PyYAML==5.4
yamllint==1.21.0
pyjexl==0.3.0
requests>=2.27.1,<2.28.0

48
scripts/fetch-schemas.py Executable file
Просмотреть файл

@ -0,0 +1,48 @@
#!/usr/bin/env python3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from pathlib import Path
import requests
URL_BASE = "https://hg.mozilla.org/mozilla-central/raw-file/tip/"
SCHEMAS = {
# The combined FxMS Mega schema
"MessagingExperiment.schema.json": (
"browser/components/newtab/content-src/asrouter/schemas/"
"MessagingExperiment.schema.json"
),
# The Nimbus recipe schema
"NimbusExperiment.schema.json": (
"toolkit/components/nimbus/schemas/NimbusExperiment.schema.json"
),
# Non-message schemas
"SpecialMessageActionSchemas.json": (
"toolkit/components/messaging-system/schemas/"
"SpecialMessageActionSchemas/SpecialMessageActionSchemas.json"
),
"message-groups.schema.json": (
"browser/components/newtab/content-src/asrouter/schemas/"
"message-group.schema.json"
),
}
def main():
session = requests.session()
for schema, fragment in SCHEMAS.items():
path = Path("schema") / schema
url = URL_BASE + fragment
print(f"Fetching {schema} ...")
with path.open("w") as f, session.get(url) as req:
f.write(req.text)
if __name__ == "__main__":
main()

Просмотреть файл

@ -4,7 +4,6 @@ import json
import sys
import jsonschema
from jsonschema.exceptions import best_match, ValidationError
from pyjexl.jexl import JEXL