-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #277 from ilai-deutel/cratesio-prerelease
crates.io: skip pre-releases, list option
- Loading branch information
Showing
7 changed files
with
60 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,40 @@ | ||
# MIT licensed | ||
# Copyright (c) 2013-2020 lilydjwg <lilydjwg@gmail.com>, et al. | ||
|
||
import re | ||
|
||
import structlog | ||
|
||
from nvchecker.api import RichResult | ||
|
||
logger = structlog.get_logger(logger_name=__name__) | ||
|
||
|
||
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): | ||
name = conf.get('cratesio') or name | ||
use_pre_release = conf.get('use_pre_release', False) | ||
data = await cache.get_json(API_URL % name) | ||
version = [v['num'] for v in data['versions'] if not v['yanked']][0] | ||
return RichResult( | ||
version = version, | ||
url = f'https://crates.io/crates/{name}/{version}', | ||
) | ||
results = [] | ||
for v in data['versions']: | ||
if v['yanked']: | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,4 @@ async def test_launchpad(get_version): | |
} | ||
) | ||
|
||
assert version == '3.8.7' | ||
assert version == '3.8.8' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters