Commit 89f90c48 authored by Christophe Benz's avatar Christophe Benz
Browse files

Follow opendataschema updates

parent fad1f9bb
...@@ -5,6 +5,7 @@ Generate assets from a catalog of schemas. ...@@ -5,6 +5,7 @@ Generate assets from a catalog of schemas.
""" """
import argparse import argparse
import itertools
import logging import logging
import subprocess import subprocess
import sys import sys
...@@ -14,7 +15,7 @@ from urllib.parse import urljoin ...@@ -14,7 +15,7 @@ from urllib.parse import urljoin
import requests import requests
from jinja2 import Template from jinja2 import Template
from opendataschema import GitSchemaReference, SchemaCatalog from opendataschema import GitSchemaReference, SchemaCatalog, by_commit_date
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -57,9 +58,14 @@ def main(): ...@@ -57,9 +58,14 @@ def main():
ref = None ref = None
if isinstance(reference, GitSchemaReference): if isinstance(reference, GitSchemaReference):
ref_names = [ref.name for ref in reference.iter_refs()] tags = sorted(reference.iter_tags(), key=by_commit_date, reverse=True)
latest_tag = tags[0] if tags else None
ref_names = itertools.chain(
(ref.name for ref in tags),
(ref.name for ref in reference.iter_branches()),
)
# Fallback to default branch name of repo if the refs specified by --ref option is not found. # Fallback to default branch name of repo if the refs specified by --ref option is not found.
ref = args.ref if args.ref in ref_names else reference.get_default_branch().name ref = args.ref if args.ref in ref_names else latest_tag
schema_url = reference.get_schema_url(ref=ref) schema_url = reference.get_schema_url(ref=ref)
log.info("{}: downloading schema file from {}".format(name, schema_url)) log.info("{}: downloading schema file from {}".format(name, schema_url))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment