nvchecker/nvchecker_source/bitbucket.py

43 lines
1.1 KiB
Python
Raw Normal View History

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
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'
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)
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)
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
if use_max_tag:
version = data
else:
version = data['values'][0]['date'].split('T', 1)[0].replace('-', '')
return version
2020-08-14 10:25:48 +00:00
async def _get_tags(url, *, max_page, cache):
ret = []
for _ in range(max_page):
2020-08-14 10:25:48 +00:00
data = await cache.get_json(url)
ret.extend(x['name'] for x in data['values'])
if 'next' in data:
url = data['next']
else:
break
return ret