diff --git a/src/checkers/jsonchecker.py b/src/checkers/jsonchecker.py index 323dfe1c..7e54ac16 100644 --- a/src/checkers/jsonchecker.py +++ b/src/checkers/jsonchecker.py @@ -132,13 +132,20 @@ async def _check_data(self, json_data: bytes, external_data: ExternalData): checker_data = external_data.checker_data results = await self._query_sequence( json_data, - self._read_q_seq(checker_data, ["tag", "commit", "version", "url"]), + self._read_q_seq( + checker_data, ["tag", "commit", "version", "url", "timestamp"] + ), ) latest_version = results["version"] latest_url = results["url"] + latest_timestamp = parse_timestamp(results.get("timestamp")) await self._update_version( - external_data, latest_version, latest_url, follow_redirects=False + external_data, + latest_version, + latest_url, + follow_redirects=False, + timestamp=latest_timestamp, ) async def _check_git(self, json_data: bytes, external_data: ExternalGitRepo): diff --git a/src/lib/checkers.py b/src/lib/checkers.py index 2544f6ed..0ec66918 100644 --- a/src/lib/checkers.py +++ b/src/lib/checkers.py @@ -6,6 +6,7 @@ import aiohttp from yarl import URL import jsonschema +import datetime from . import ( utils, @@ -147,6 +148,7 @@ async def _update_version( latest_version: str, latest_url: str, follow_redirects: bool = False, + timestamp: t.Optional[datetime.datetime] = None, ): assert latest_version is not None assert latest_url is not None @@ -180,4 +182,6 @@ async def _update_version( new_version = new_version._replace( version=latest_version # pylint: disable=no-member ) + if timestamp is not None: + new_version = new_version._replace(timestamp=timestamp) external_data.set_new_version(new_version) diff --git a/tests/io.github.stedolan.jq.yml b/tests/io.github.stedolan.jq.yml index c146fb23..5981f8e6 100644 --- a/tests/io.github.stedolan.jq.yml +++ b/tests/io.github.stedolan.jq.yml @@ -10,6 +10,17 @@ modules: url: https://api.github.com/repos/stedolan/jq/releases/latest version-query: '.tag_name | sub("^jq-"; "")' url-query: '.assets[] | select(.name=="jq-" + $version + ".tar.gz") | .browser_download_url' + + - type: archive + dest-filename: jq-1.4.tarball.tar.gz + url: https://api.github.com/repos/stedolan/jq/tarball/jq-1.4 + sha256: "0000000000000000000000000000000000000000000000000000000000000000" + x-checker-data: + type: json + url: https://api.github.com/repos/stedolan/jq/releases/13660432 + version-query: '.tag_name | sub("^jq-"; "")' + url-query: '.tarball_url' + timestamp-query: '.published_at' modules: - name: oniguruma diff --git a/tests/test_jsonchecker.py b/tests/test_jsonchecker.py index 0a9f92d1..ec596008 100644 --- a/tests/test_jsonchecker.py +++ b/tests/test_jsonchecker.py @@ -18,7 +18,7 @@ async def test_check(self): checker = ManifestChecker(TEST_MANIFEST) ext_data = await checker.check() - self.assertEqual(len(ext_data), 7) + self.assertEqual(len(ext_data), 8) for data in ext_data: self.assertIsNotNone(data) if data.filename == "jq-1.4.tar.gz": @@ -38,6 +38,11 @@ async def test_check(self): sha256="0000000000000000000000000000000000000000000000000000000000000000" ), ) + elif data.filename == "jq-1.4.tarball.tar.gz": + self.assertEqual( + data.new_version.timestamp, + datetime.datetime.fromisoformat("2018-11-02T01:54:23+00:00"), + ) elif data.filename == "oniguruma.git": self.assertIsInstance(data.new_version, ExternalGitRef) self.assertEqual(data.current_version.url, data.new_version.url)