testing bitbucket_commit

This commit is contained in:
Andy Werner 2017-04-28 16:40:20 +02:00
parent fa5260a9ff
commit 550c032e37
3 changed files with 69 additions and 5 deletions

View file

@ -825,7 +825,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
self._settings.load()
# persist the new version if necessary for check type
if check["type"] == "github_commit":
if check["type"] in ["github_commit", "bitbucket_commit"]:
dummy_default = dict(plugins=dict())
dummy_default["plugins"][self._identifier] = dict(checks=dict())
dummy_default["plugins"][self._identifier]["checks"][target] = dict(current=None)
@ -882,7 +882,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
release_branches += [x["branch"] for x in check["prerelease_branches"]]
result["released_version"] = not release_branches or BRANCH in release_branches
if check["type"] == "github_commit":
if check["type"] in ["github_commit", "bitbucket_commit"]:
result["current"] = REVISION if REVISION else "unknown"
else:
result["current"] = VERSION
@ -936,7 +936,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
# displayVersion AND current missing or None
result["displayVersion"] = u"unknown"
if check["type"] in ("github_commit",):
if check["type"] in ["github_commit", "bitbucket_commit"]:
result["current"] = check.get("current", None)
else:
result["current"] = check.get("current", check.get("displayVersion", None))
@ -972,6 +972,8 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
return version_checks.github_release
elif check_type == "github_commit":
return version_checks.github_commit
elif check_type == "bitbucket_commit":
return version_checks.bitbucket_commit
elif check_type == "git_commit":
return version_checks.git_commit
elif check_type == "commandline":

View file

@ -5,7 +5,7 @@ __author__ = "Gina Häußge <osd@foosel.net>"
__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
__copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms of the AGPLv3 License"
from . import commandline, git_commit, github_commit, github_release, python_checker
from . import commandline, git_commit, github_commit, github_release, bitbucket_commit, python_checker
def log_github_ratelimit(logger, r):
ratelimit = r.headers["X-RateLimit-Limit"] if "X-RateLimit-Limit" in r.headers else "?"
@ -17,4 +17,4 @@ def log_github_ratelimit(logger, r):
except:
reset = "?"
logger.debug("Github rate limit: %s/%s, reset at %s" % (remaining, ratelimit, reset))
logger.debug("Github rate limit: %s/%s, reset at %s" % (remaining, ratelimit, reset))

View file

@ -0,0 +1,62 @@
# coding=utf-8
from __future__ import absolute_import, division, print_function
__author__ = "Gina Häußge <osd@foosel.net>"
__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
__copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms of the AGPLv3 License"
import requests
import logging
from ..exceptions import ConfigurationInvalid
BRANCH_HEAD_URL = "https://api.bitbucket.org/2.0/repositories/{user}/{repo}/commits/{branch}?pagelen=1"
# BRANCH_HEAD_URL = "https://api.github.com/repos/{user}/{repo}/git/refs/heads/{branch}"
logger = logging.getLogger("octoprint.plugins.softwareupdate.version_checks.bitbucket_commit")
def _get_latest_commit(user, repo, branch):
result = None
r = requests.get(BRANCH_HEAD_URL.format(user=user, repo=repo, branch=branch))
# from . import log_github_ratelimit
# log_github_ratelimit(logger, r)
if not r.status_code == requests.codes.ok:
return None
reference = r.json()
if not "values" in reference \
or len(reference["values"]) < 1 \
or not 'hash' in reference["values"][0]:
return None
result = reference["values"][0]['hash']
logger.info("ANDYTEST bitbucket_commit: %s", result)
return result
def get_latest(target, check):
if "user" not in check or "repo" not in check:
raise ConfigurationInvalid("Update configuration for %s of type bitbucket_commit needs all of user and repo" % target)
branch = "master"
if "branch" in check:
branch = check["branch"]
current = None
if "current" in check:
current = check["current"]
remote_commit = _get_latest_commit(check["user"], check["repo"], branch)
information = dict(
local=dict(name="Commit {commit}".format(commit=current if current is not None else "unknown"), value=current),
remote=dict(name="Commit {commit}".format(commit=remote_commit if remote_commit is not None else "unknown"), value=remote_commit)
)
is_current = (current is not None and current == remote_commit) or remote_commit is None
logger.debug("Target: %s, local: %s, remote: %s" % (target, current, remote_commit))
return information, is_current