mirror of
https://github.com/lilydjwg/nvchecker
synced 2024-12-25 16:12:39 +00:00
bitbucket: use querying and sorting for improved tag search
This commit is contained in:
parent
4f06ce7862
commit
a8228bb594
@ -467,11 +467,27 @@ use_max_tag
|
|||||||
Set this to ``true`` to check for the max tag on BitBucket. Will return the biggest one
|
Set this to ``true`` to check for the max tag on BitBucket. Will return the biggest one
|
||||||
sorted by old ``pkg_resources.parse_version``. Will return the tag name instead of date.
|
sorted by old ``pkg_resources.parse_version``. Will return the tag name instead of date.
|
||||||
|
|
||||||
|
use_sorted_tags
|
||||||
|
If ``true``, tags are queried and sorted according to the ``query`` and
|
||||||
|
``sort`` keys. Will return the tag name instead of the date.
|
||||||
|
|
||||||
|
query
|
||||||
|
A query string use to filter tags when ``use_sorted_tags`` is set (see
|
||||||
|
`here <https://developer.atlassian.com/cloud/bitbucket/rest/intro/#querying>`__
|
||||||
|
for examples). The string does not need to be escaped.
|
||||||
|
|
||||||
|
sort
|
||||||
|
A field used to sort the tags when ``use_sorted_tags`` is set (see
|
||||||
|
`here <https://developer.atlassian.com/cloud/bitbucket/rest/intro/#filtering>`__
|
||||||
|
for examples). Defaults to ``-target.date`` (sorts tags in descending order
|
||||||
|
by date).
|
||||||
|
|
||||||
max_page
|
max_page
|
||||||
How many pages do we search for the max tag? Default is 3. This works when
|
How many pages do we search for the max tag? Default is 3. This works when
|
||||||
``use_max_tag`` is set.
|
``use_max_tag`` is set.
|
||||||
|
|
||||||
This source supports :ref:`list options` when ``use_max_tag`` is set.
|
This source supports :ref:`list options` when ``use_max_tag`` or
|
||||||
|
``use_sorted_tags`` is set.
|
||||||
|
|
||||||
Check GitLab
|
Check GitLab
|
||||||
~~~~~~~~~~~~
|
~~~~~~~~~~~~
|
||||||
|
@ -2,12 +2,14 @@
|
|||||||
# Copyright (c) 2013-2020 lilydjwg <lilydjwg@gmail.com>, et al.
|
# Copyright (c) 2013-2020 lilydjwg <lilydjwg@gmail.com>, et al.
|
||||||
|
|
||||||
from typing import Any, List
|
from typing import Any, List
|
||||||
|
from urllib.parse import urlencode
|
||||||
|
|
||||||
from nvchecker.api import VersionResult, Entry, AsyncCache
|
from nvchecker.api import VersionResult, Entry, AsyncCache
|
||||||
|
|
||||||
# doc: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commits-get
|
# doc: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commits-get
|
||||||
BITBUCKET_URL = 'https://bitbucket.org/api/2.0/repositories/%s/commits/%s'
|
BITBUCKET_URL = 'https://bitbucket.org/api/2.0/repositories/%s/commits/%s'
|
||||||
# doc: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-refs/#api-repositories-workspace-repo-slug-refs-tags-get
|
# doc: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-refs/#api-repositories-workspace-repo-slug-refs-tags-get
|
||||||
BITBUCKET_MAX_TAG = 'https://bitbucket.org/api/2.0/repositories/%s/refs/tags?sort=-target.date'
|
BITBUCKET_MAX_TAG = 'https://bitbucket.org/api/2.0/repositories/%s/refs/tags'
|
||||||
|
|
||||||
async def get_version(
|
async def get_version(
|
||||||
name: str, conf: Entry, *,
|
name: str, conf: Entry, *,
|
||||||
@ -17,8 +19,19 @@ async def get_version(
|
|||||||
repo = conf['bitbucket']
|
repo = conf['bitbucket']
|
||||||
br = conf.get('branch', '')
|
br = conf.get('branch', '')
|
||||||
use_max_tag = conf.get('use_max_tag', False)
|
use_max_tag = conf.get('use_max_tag', False)
|
||||||
|
use_sorted_tags = conf.get('use_sorted_tags', False)
|
||||||
|
|
||||||
if use_max_tag:
|
if use_sorted_tags:
|
||||||
|
url = BITBUCKET_MAX_TAG % repo
|
||||||
|
|
||||||
|
parameters = {'sort': conf.get('sort', '-target.date')}
|
||||||
|
if 'query' in conf:
|
||||||
|
parameters['q'] = conf['query']
|
||||||
|
|
||||||
|
url += '?' + urlencode(parameters)
|
||||||
|
data = await _get_tags(url, max_page=1, cache=cache)
|
||||||
|
|
||||||
|
elif use_max_tag:
|
||||||
url = BITBUCKET_MAX_TAG % repo
|
url = BITBUCKET_MAX_TAG % repo
|
||||||
max_page = conf.get('max_page', 3)
|
max_page = conf.get('max_page', 3)
|
||||||
data = await _get_tags(url, max_page=max_page, cache=cache)
|
data = await _get_tags(url, max_page=max_page, cache=cache)
|
||||||
@ -27,7 +40,7 @@ async def get_version(
|
|||||||
url = BITBUCKET_URL % (repo, br)
|
url = BITBUCKET_URL % (repo, br)
|
||||||
data = await cache.get_json(url)
|
data = await cache.get_json(url)
|
||||||
|
|
||||||
if use_max_tag:
|
if use_max_tag or use_sorted_tags:
|
||||||
version = data
|
version = data
|
||||||
else:
|
else:
|
||||||
version = data['values'][0]['date'].split('T', 1)[0].replace('-', '')
|
version = data['values'][0]['date'].split('T', 1)[0].replace('-', '')
|
||||||
|
@ -24,3 +24,25 @@ async def test_bitbucket_max_tag_with_ignored(get_version):
|
|||||||
"use_max_tag": True,
|
"use_max_tag": True,
|
||||||
"ignored": "1.6.0 1.7.0",
|
"ignored": "1.6.0 1.7.0",
|
||||||
}) == "v1.5"
|
}) == "v1.5"
|
||||||
|
|
||||||
|
async def test_bitbucket_sorted_tags(get_version):
|
||||||
|
assert await get_version("example", {
|
||||||
|
"source": "bitbucket",
|
||||||
|
"bitbucket": "prawee/git-tag",
|
||||||
|
"use_sorted_tags": True,
|
||||||
|
}) == "1.7.0"
|
||||||
|
|
||||||
|
assert await get_version("example", {
|
||||||
|
"source": "bitbucket",
|
||||||
|
"bitbucket": "prawee/git-tag",
|
||||||
|
"use_sorted_tags": True,
|
||||||
|
"query": 'name~"v"',
|
||||||
|
}) == "v1.5"
|
||||||
|
|
||||||
|
assert await get_version("example", {
|
||||||
|
"source": "bitbucket",
|
||||||
|
"bitbucket": "berkeleylab/gasnet",
|
||||||
|
"use_sorted_tags": True,
|
||||||
|
"query": 'name~"CVS/BERKELEY_UPC" AND name!~"rc"',
|
||||||
|
"prefix": "CVS/BERKELEY_UPC_",
|
||||||
|
}) == "2_18_0"
|
||||||
|
Loading…
Reference in New Issue
Block a user