mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-12 06:29:54 -05:00
test
This commit is contained in:
parent
84b9ead52f
commit
403202b0e0
@ -7,6 +7,8 @@ This is the SpiceBot Update system.
|
|||||||
import sopel
|
import sopel
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
import json
|
||||||
|
from restkit import request
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
|
||||||
from .Config import config as botconfig
|
from .Config import config as botconfig
|
||||||
@ -25,6 +27,9 @@ class BotVersion():
|
|||||||
self.spicebot = {
|
self.spicebot = {
|
||||||
"version_local": None,
|
"version_local": None,
|
||||||
"version_local_num": None,
|
"version_local_num": None,
|
||||||
|
"version_url": 'https://api.github.com/users/SpiceBot/repos',
|
||||||
|
"version_online": None,
|
||||||
|
"version_online_num": None,
|
||||||
}
|
}
|
||||||
|
|
||||||
self.check_sopel()
|
self.check_sopel()
|
||||||
@ -45,7 +50,29 @@ class BotVersion():
|
|||||||
|
|
||||||
def check_spicebot(self):
|
def check_spicebot(self):
|
||||||
self.spicebot["version_local_num"] = pkg_resources.get_distribution("sopel-modules.SpiceBot").version
|
self.spicebot["version_local_num"] = pkg_resources.get_distribution("sopel-modules.SpiceBot").version
|
||||||
|
self.sopel["version_online_num"] = self.count_repo_commits()
|
||||||
# get actual version number, and commit count, and assemble a version
|
# get actual version number, and commit count, and assemble a version
|
||||||
|
|
||||||
|
def count_repo_commits(self, _acc=0):
|
||||||
|
r = request("https://api.github.com/repos/SpiceBot/SpiceBot/commits/master")
|
||||||
|
commits = json.loads(r.body_string())
|
||||||
|
n = len(commits)
|
||||||
|
if n == 0:
|
||||||
|
return _acc
|
||||||
|
link = r.headers.get('link')
|
||||||
|
if link is None:
|
||||||
|
return _acc + n
|
||||||
|
next_url = self.find_next(r.headers['link'])
|
||||||
|
if next_url is None:
|
||||||
|
return _acc + n
|
||||||
|
# try to be tail recursive, even when it doesn't matter in CPython
|
||||||
|
return self.count_repo_commits(next_url, _acc + n)
|
||||||
|
|
||||||
|
def find_next(self, link):
|
||||||
|
for l in link.split(','):
|
||||||
|
a, b = l.split(';')
|
||||||
|
if b.strip() == 'rel="next"':
|
||||||
|
return a.strip()[1:-1]
|
||||||
|
|
||||||
|
|
||||||
version = BotVersion()
|
version = BotVersion()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user