bitbucket: use 'fields' query to restrict returned fields

This commit is contained in:
Alexandru Fikl 2022-02-06 10:17:49 -06:00
parent a8228bb594
commit 4bf2755b0e
No known key found for this signature in database
GPG key ID: 32C1509CB6EE436B
2 changed files with 15 additions and 11 deletions

View file

@ -472,7 +472,7 @@ use_sorted_tags
``sort`` keys. Will return the tag name instead of the date. ``sort`` keys. Will return the tag name instead of the date.
query query
A query string use to filter tags when ``use_sorted_tags`` is set (see A query string use to filter tags when ``use_sorted_tags`` set (see
`here <https://developer.atlassian.com/cloud/bitbucket/rest/intro/#querying>`__ `here <https://developer.atlassian.com/cloud/bitbucket/rest/intro/#querying>`__
for examples). The string does not need to be escaped. for examples). The string does not need to be escaped.

View file

@ -21,29 +21,33 @@ async def get_version(
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) use_sorted_tags = conf.get('use_sorted_tags', False)
if use_sorted_tags: if use_sorted_tags or use_max_tag:
url = BITBUCKET_MAX_TAG % repo parameters = {'fields': 'values.name,next'}
parameters = {'sort': conf.get('sort', '-target.date')} if use_sorted_tags:
if 'query' in conf: parameters['sort'] = conf.get('sort', '-target.date')
if 'query' in conf:
parameters['q'] = conf['query'] parameters['q'] = conf['query']
if use_sorted_tags:
url = BITBUCKET_MAX_TAG % repo
url += '?' + urlencode(parameters) url += '?' + urlencode(parameters)
data = await _get_tags(url, max_page=1, cache=cache)
version = await _get_tags(url, max_page=1, cache=cache)
elif use_max_tag: elif use_max_tag:
url = BITBUCKET_MAX_TAG % repo url = BITBUCKET_MAX_TAG % repo
url += '?' + urlencode(parameters)
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) version = await _get_tags(url, max_page=max_page, cache=cache)
else: else:
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 or use_sorted_tags:
version = data
else:
version = data['values'][0]['date'].split('T', 1)[0].replace('-', '') version = data['values'][0]['date'].split('T', 1)[0].replace('-', '')
return version return version
async def _get_tags( async def _get_tags(
@ -51,7 +55,7 @@ async def _get_tags(
max_page: int, max_page: int,
cache: AsyncCache, cache: AsyncCache,
) -> List[str]: ) -> List[str]:
ret = [] ret: List[str] = []
for _ in range(max_page): for _ in range(max_page):
data = await cache.get_json(url) data = await cache.get_json(url)