Add use_max_tag support for bitbucket source
This commit is contained in:
parent
4be2d6c09d
commit
d28d869add
|
@ -142,6 +142,10 @@ bitbucket
|
|||
branch
|
||||
Which branch to track? Default is the repository's default.
|
||||
|
||||
use_max_tag
|
||||
Set this to ``true`` to check for the max tag on BitBucket. Will return the biggest one
|
||||
sorted by ``pkg_resources.parse_version``.
|
||||
|
||||
Check GitCafe
|
||||
-------------
|
||||
Check `GitCafe <https://gitcafe.com/>`_ for updates. The version returned is in date format ``%Y%m%d``, e.g. ``20130701``.
|
||||
|
|
|
@ -2,20 +2,31 @@ import os
|
|||
import json
|
||||
from functools import partial
|
||||
|
||||
from pkg_resources import parse_version
|
||||
from tornado.httpclient import AsyncHTTPClient, HTTPRequest
|
||||
|
||||
# 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/1.0/repositories/%s/tags'
|
||||
|
||||
def get_version(name, conf, callback):
|
||||
repo = conf.get('bitbucket')
|
||||
br = conf.get('branch', '')
|
||||
url = BITBUCKET_URL % (repo, br)
|
||||
use_max_tag = conf.getboolean('use_max_tag', False)
|
||||
if use_max_tag:
|
||||
url = BITBUCKET_MAX_TAG % repo
|
||||
else:
|
||||
url = BITBUCKET_URL % (repo, br)
|
||||
request = HTTPRequest(url, user_agent='lilydjwg/nvchecker')
|
||||
AsyncHTTPClient().fetch(request,
|
||||
callback=partial(_bitbucket_done, name, callback))
|
||||
callback=partial(_bitbucket_done, name, use_max_tag, callback))
|
||||
|
||||
def _bitbucket_done(name, callback, res):
|
||||
def _bitbucket_done(name, use_max_tag, callback, res):
|
||||
data = json.loads(res.body.decode('utf-8'))
|
||||
version = data['values'][0]['date'].split('T', 1)[0].replace('-', '')
|
||||
if use_max_tag:
|
||||
data = list(data)
|
||||
data.sort(key=parse_version)
|
||||
version = data[-1]
|
||||
else:
|
||||
version = data['values'][0]['date'].split('T', 1)[0].replace('-', '')
|
||||
callback(name, version)
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
from tests.helper import ExternalVersionTestCase
|
||||
|
||||
|
||||
class BitBucketTest(ExternalVersionTestCase):
|
||||
def test_bitbucket(self):
|
||||
self.assertEqual(self.sync_get_version("example", {"bitbucket": "prawee/git-tag"}), "20150303")
|
||||
|
||||
def test_bitbucket_max_tag(self):
|
||||
self.assertEqual(self.sync_get_version("example", {"bitbucket": "prawee/git-tag", "use_max_tag": 1}), "1.7.0")
|
Loading…
Reference in New Issue