mirror of
https://github.com/lilydjwg/nvchecker.git
synced 2025-03-10 06:14:02 +00:00
23 lines
842 B
Python
23 lines
842 B
Python
import os
|
|
import json
|
|
from functools import partial
|
|
|
|
from tornado.httpclient import AsyncHTTPClient, HTTPRequest
|
|
|
|
GITHUB_URL = 'https://api.github.com/repos/%s/commits?sha=%s'
|
|
|
|
def get_version(name, conf, callback):
|
|
repo = conf.get('github')
|
|
br = conf.get('branch', 'master')
|
|
url = GITHUB_URL % (repo, br)
|
|
headers = {}
|
|
if 'NVCHECKER_GITHUB_TOKEN' in os.environ:
|
|
headers = {'Authorization': 'token %s' % os.environ['NVCHECKER_GITHUB_TOKEN']}
|
|
request = HTTPRequest(url, headers=headers)
|
|
AsyncHTTPClient().fetch(request, user_agent='lilydjwg/nvchecker',
|
|
callback=partial(_github_done, name, callback))
|
|
|
|
def _github_done(name, callback, res):
|
|
data = json.loads(res.body.decode('utf-8'))
|
|
version = data[0]['commit']['committer']['date'].split('T', 1)[0].replace('-', '')
|
|
callback(name, version)
|