Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checkers: ability to replace timestamp #297

Merged
merged 2 commits into from
Apr 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/checkers/jsonchecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 4 additions & 0 deletions src/lib/checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import aiohttp
from yarl import URL
import jsonschema
import datetime

from . import (
utils,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
11 changes: 11 additions & 0 deletions tests/io.github.stedolan.jq.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion tests/test_jsonchecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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)
Expand Down