mirror of
https://github.com/lilydjwg/nvchecker.git
synced 2025-03-10 06:14:02 +00:00
Add use_max_tag support for bitbucket source
This commit is contained in:
parent
4be2d6c09d
commit
d28d869add
3 changed files with 28 additions and 4 deletions
|
@ -142,6 +142,10 @@ bitbucket
|
||||||
branch
|
branch
|
||||||
Which branch to track? Default is the repository's default.
|
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
|
||||||
-------------
|
-------------
|
||||||
Check `GitCafe <https://gitcafe.com/>`_ for updates. The version returned is in date format ``%Y%m%d``, e.g. ``20130701``.
|
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
|
import json
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
|
from pkg_resources import parse_version
|
||||||
from tornado.httpclient import AsyncHTTPClient, HTTPRequest
|
from tornado.httpclient import AsyncHTTPClient, HTTPRequest
|
||||||
|
|
||||||
# doc: https://confluence.atlassian.com/display/BITBUCKET/commits+or+commit+Resource
|
# doc: https://confluence.atlassian.com/display/BITBUCKET/commits+or+commit+Resource
|
||||||
BITBUCKET_URL = 'https://bitbucket.org/api/2.0/repositories/%s/commits/%s'
|
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):
|
def get_version(name, conf, callback):
|
||||||
repo = conf.get('bitbucket')
|
repo = conf.get('bitbucket')
|
||||||
br = conf.get('branch', '')
|
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')
|
request = HTTPRequest(url, user_agent='lilydjwg/nvchecker')
|
||||||
AsyncHTTPClient().fetch(request,
|
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'))
|
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)
|
callback(name, version)
|
||||||
|
|
9
tests/test_bitbucket.py
Normal file
9
tests/test_bitbucket.py
Normal file
|
@ -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…
Add table
Reference in a new issue