2017-02-28 07:24:53 +00:00
|
|
|
# MIT licensed
|
2020-08-14 10:25:48 +00:00
|
|
|
# Copyright (c) 2013-2020 lilydjwg <lilydjwg@gmail.com>, et al.
|
2017-02-28 07:24:53 +00:00
|
|
|
|
2020-08-14 12:04:05 +00:00
|
|
|
from nvchecker.api import sort_version_keys
|
2016-04-02 14:13:41 +00:00
|
|
|
|
2015-08-04 08:12:46 +00:00
|
|
|
# doc: https://confluence.atlassian.com/display/BITBUCKET/commits+or+commit+Resource
|
|
|
|
BITBUCKET_URL = 'https://bitbucket.org/api/2.0/repositories/%s/commits/%s'
|
2019-07-04 08:39:49 +00:00
|
|
|
BITBUCKET_MAX_TAG = 'https://bitbucket.org/api/2.0/repositories/%s/refs/tags'
|
2015-08-04 08:12:46 +00:00
|
|
|
|
2020-08-14 10:25:48 +00:00
|
|
|
async def get_version(name, conf, *, cache, **kwargs):
|
2020-08-20 07:39:21 +00:00
|
|
|
repo = conf['bitbucket']
|
2015-08-04 08:12:46 +00:00
|
|
|
br = conf.get('branch', '')
|
2020-08-17 08:31:59 +00:00
|
|
|
use_max_tag = conf.get('use_max_tag', False)
|
2019-07-04 08:39:49 +00:00
|
|
|
|
2015-11-05 04:12:03 +00:00
|
|
|
if use_max_tag:
|
|
|
|
url = BITBUCKET_MAX_TAG % repo
|
2020-08-17 08:31:59 +00:00
|
|
|
max_page = conf.get('max_page', 3)
|
2020-08-14 10:25:48 +00:00
|
|
|
data = await _get_tags(url, max_page=max_page, cache=cache)
|
2019-07-04 08:39:49 +00:00
|
|
|
|
2015-11-05 04:12:03 +00:00
|
|
|
else:
|
|
|
|
url = BITBUCKET_URL % (repo, br)
|
2020-08-14 10:25:48 +00:00
|
|
|
data = await cache.get_json(url)
|
2017-07-08 07:52:30 +00:00
|
|
|
|
2015-11-05 04:12:03 +00:00
|
|
|
if use_max_tag:
|
2019-10-12 07:40:08 +00:00
|
|
|
version = data
|
2015-11-05 04:12:03 +00:00
|
|
|
else:
|
|
|
|
version = data['values'][0]['date'].split('T', 1)[0].replace('-', '')
|
2017-07-08 07:59:54 +00:00
|
|
|
return version
|
2019-07-04 08:39:49 +00:00
|
|
|
|
2020-08-14 10:25:48 +00:00
|
|
|
async def _get_tags(url, *, max_page, cache):
|
2019-07-04 08:39:49 +00:00
|
|
|
ret = []
|
|
|
|
|
2019-07-04 09:59:19 +00:00
|
|
|
for _ in range(max_page):
|
2020-08-14 10:25:48 +00:00
|
|
|
data = await cache.get_json(url)
|
2019-07-04 08:39:49 +00:00
|
|
|
ret.extend(x['name'] for x in data['values'])
|
|
|
|
if 'next' in data:
|
|
|
|
url = data['next']
|
|
|
|
else:
|
|
|
|
break
|
|
|
|
|
|
|
|
return ret
|
|
|
|
|