From 403202b0e033cb509b3d81017e79f9c0b87e1237 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 16 Jul 2019 12:16:42 -0400 Subject: [PATCH] test --- sopel_modules/SpiceBot/Version.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/sopel_modules/SpiceBot/Version.py b/sopel_modules/SpiceBot/Version.py index c756b7b..e17b25d 100644 --- a/sopel_modules/SpiceBot/Version.py +++ b/sopel_modules/SpiceBot/Version.py @@ -7,6 +7,8 @@ This is the SpiceBot Update system. import sopel import requests +import json +from restkit import request import pkg_resources from .Config import config as botconfig @@ -25,6 +27,9 @@ class BotVersion(): self.spicebot = { "version_local": None, "version_local_num": None, + "version_url": 'https://api.github.com/users/SpiceBot/repos', + "version_online": None, + "version_online_num": None, } self.check_sopel() @@ -45,7 +50,29 @@ class BotVersion(): def check_spicebot(self): 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 + 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()