add bitbucket support
This commit is contained in:
parent
ddf9169074
commit
9de0eb289e
12
README.rst
12
README.rst
|
@ -120,8 +120,18 @@ branch
|
|||
|
||||
An environment variable ``NVCHECKER_GITHUB_TOKEN`` can be set to a GitHub OAuth token in order to request more frequently than anonymously.
|
||||
|
||||
Check BitBucket
|
||||
---------------
|
||||
Check `BitBucket <https://bitbucket.org/>`_ for updates. The version returned is in date format ``%Y%m%d``, e.g. ``20130701``.
|
||||
|
||||
bitbucket
|
||||
The bitbucket repository, with author, e.g. ``lilydjwg/dotvim``.
|
||||
|
||||
branch
|
||||
Which branch to track? Default is the repository's default.
|
||||
|
||||
Check GitCafe
|
||||
------------
|
||||
-------------
|
||||
Check `GitCafe <https://gitcafe.com/>`_ for updates. The version returned is in date format ``%Y%m%d``, e.g. ``20130701``.
|
||||
|
||||
gitcafe
|
||||
|
|
|
@ -4,7 +4,7 @@ from importlib import import_module
|
|||
logger = logging.getLogger(__name__)
|
||||
handler_precedence = (
|
||||
'github', 'gitcafe', 'aur', 'pypi', 'archpkg', 'gems', 'pacman',
|
||||
'cmd', 'gcode_hg', 'gcode_svn', 'regex', 'manual', 'vcs'
|
||||
'cmd', 'bitbucket', 'gcode_hg', 'gcode_svn', 'regex', 'manual', 'vcs',
|
||||
)
|
||||
|
||||
def get_version(name, conf, callback):
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
import os
|
||||
import json
|
||||
from functools import partial
|
||||
|
||||
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'
|
||||
|
||||
def get_version(name, conf, callback):
|
||||
repo = conf.get('bitbucket')
|
||||
br = conf.get('branch', '')
|
||||
url = BITBUCKET_URL % (repo, br)
|
||||
request = HTTPRequest(url, user_agent='lilydjwg/nvchecker')
|
||||
AsyncHTTPClient().fetch(request,
|
||||
callback=partial(_bitbucket_done, name, callback))
|
||||
|
||||
def _bitbucket_done(name, callback, res):
|
||||
data = json.loads(res.body.decode('utf-8'))
|
||||
version = data['values'][0]['date'].split('T', 1)[0].replace('-', '')
|
||||
callback(name, version)
|
Loading…
Reference in New Issue