mirror of
https://github.com/lilydjwg/nvchecker.git
synced 2025-03-10 06:14:02 +00:00
crates.io: skip pre-releases, list option
This adds a `use_pre_release` option and adds support for list option for crates.io, similar to PyPI.
This commit is contained in:
parent
3abe5ad394
commit
d5cc276000
3 changed files with 55 additions and 5 deletions
|
@ -661,6 +661,11 @@ Check `crates.io <https://crates.io/>`_ for updates.
|
||||||
cratesio
|
cratesio
|
||||||
The crate name on crates.io, e.g. ``tokio``.
|
The crate name on crates.io, e.g. ``tokio``.
|
||||||
|
|
||||||
|
use_pre_release
|
||||||
|
Whether to accept pre release. Default is false.
|
||||||
|
|
||||||
|
This source supports :ref:`list options`.
|
||||||
|
|
||||||
Check Local Pacman Database
|
Check Local Pacman Database
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
::
|
::
|
||||||
|
|
|
@ -1,15 +1,40 @@
|
||||||
# MIT licensed
|
# MIT licensed
|
||||||
# Copyright (c) 2013-2020 lilydjwg <lilydjwg@gmail.com>, et al.
|
# Copyright (c) 2013-2020 lilydjwg <lilydjwg@gmail.com>, et al.
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
import structlog
|
||||||
|
|
||||||
from nvchecker.api import RichResult
|
from nvchecker.api import RichResult
|
||||||
|
|
||||||
|
logger = structlog.get_logger(logger_name=__name__)
|
||||||
|
|
||||||
|
|
||||||
API_URL = 'https://crates.io/api/v1/crates/%s'
|
API_URL = 'https://crates.io/api/v1/crates/%s'
|
||||||
|
# https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
|
||||||
|
VERSION_PATTERN = r'^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$'
|
||||||
|
|
||||||
|
|
||||||
async def get_version(name, conf, *, cache, **kwargs):
|
async def get_version(name, conf, *, cache, **kwargs):
|
||||||
name = conf.get('cratesio') or name
|
name = conf.get('cratesio') or name
|
||||||
|
use_pre_release = conf.get('use_pre_release', False)
|
||||||
data = await cache.get_json(API_URL % name)
|
data = await cache.get_json(API_URL % name)
|
||||||
version = [v['num'] for v in data['versions'] if not v['yanked']][0]
|
results = []
|
||||||
return RichResult(
|
for v in data['versions']:
|
||||||
version = version,
|
if v['yanked']:
|
||||||
url = f'https://crates.io/crates/{name}/{version}',
|
continue
|
||||||
)
|
version = v['num']
|
||||||
|
match = re.fullmatch(VERSION_PATTERN, version)
|
||||||
|
if match is None:
|
||||||
|
logger.warning('ignoring invalid version', version=version)
|
||||||
|
continue
|
||||||
|
if not use_pre_release and match.group('prerelease'):
|
||||||
|
continue
|
||||||
|
results.append(
|
||||||
|
RichResult(
|
||||||
|
version=version,
|
||||||
|
url=f'https://crates.io/crates/{name}/{version}',
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
|
@ -8,3 +8,23 @@ async def test_cratesio(get_version):
|
||||||
assert await get_version("example", {
|
assert await get_version("example", {
|
||||||
"source": "cratesio",
|
"source": "cratesio",
|
||||||
}) == "1.1.0"
|
}) == "1.1.0"
|
||||||
|
|
||||||
|
async def test_cratesio_list(get_version):
|
||||||
|
assert await get_version("example", {
|
||||||
|
"source": "cratesio",
|
||||||
|
"include_regex": r"^1\.0.*",
|
||||||
|
}) == "1.0.2"
|
||||||
|
|
||||||
|
async def test_cratesio_skip_prerelease(get_version):
|
||||||
|
with pytest.raises(RuntimeError, match='include_regex matched no versions'):
|
||||||
|
await get_version("cargo-lock", {
|
||||||
|
"source": "cratesio",
|
||||||
|
"include_regex": r".*-.*",
|
||||||
|
})
|
||||||
|
|
||||||
|
async def test_cratesio_use_prerelease(get_version):
|
||||||
|
await get_version("cargo-lock", {
|
||||||
|
"source": "cratesio",
|
||||||
|
"use_pre_release": "true",
|
||||||
|
"include_regex": r".*-.*",
|
||||||
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue