Software update plugin: added check_type bitbucket_commit
This commit is contained in:
1 parent
30e962b447
commit
ee75ddce04
3 files changed
+63
-7
No files matched your search
@@ -113,7 +113,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
|
|||||||
# This used to be part of the settings migration (version 2) due to a bug - it can't
|
# This used to be part of the settings migration (version 2) due to a bug - it can't
|
||||||
# stay there though since it interferes with manual entries to the checks not
|
# stay there though since it interferes with manual entries to the checks not
|
||||||
# originating from within a plugin. Hence we do that step now here.
|
# originating from within a plugin. Hence we do that step now here.
|
||||||
if "type" not in effective_config or effective_config["type"] != "github_commit":
|
if "type" not in effective_config or effective_config["type"] not in ["github_commit", "bitbucket_commit"]:
|
||||||
deletables = ["current", "displayVersion"]
|
deletables = ["current", "displayVersion"]
|
||||||
else:
|
else:
|
||||||
deletables = []
|
deletables = []
|
||||||
@@ -378,7 +378,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
|
|||||||
configured_checks = self._settings.get(["checks"], incl_defaults=False)
|
configured_checks = self._settings.get(["checks"], incl_defaults=False)
|
||||||
if configured_checks is not None and "octoprint" in configured_checks:
|
if configured_checks is not None and "octoprint" in configured_checks:
|
||||||
octoprint_check = dict(configured_checks["octoprint"])
|
octoprint_check = dict(configured_checks["octoprint"])
|
||||||
if "type" not in octoprint_check or octoprint_check["type"] != "github_commit":
|
if "type" not in octoprint_check or octoprint_check["type"] not in ["github_commit", "bitbucket_commit"]:
|
||||||
deletables=["current", "displayName", "displayVersion"]
|
deletables=["current", "displayName", "displayVersion"]
|
||||||
else:
|
else:
|
||||||
deletables=[]
|
deletables=[]
|
||||||
@@ -827,7 +827,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
|
|||||||
self._settings.load()
|
self._settings.load()
|
||||||
|
|
||||||
# persist the new version if necessary for check type
|
# 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 = dict(plugins=dict())
|
||||||
dummy_default["plugins"][self._identifier] = dict(checks=dict())
|
dummy_default["plugins"][self._identifier] = dict(checks=dict())
|
||||||
dummy_default["plugins"][self._identifier]["checks"][target] = dict(current=None)
|
dummy_default["plugins"][self._identifier]["checks"][target] = dict(current=None)
|
||||||
@@ -884,7 +884,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
|
|||||||
release_branches += [x["branch"] for x in check["prerelease_branches"]]
|
release_branches += [x["branch"] for x in check["prerelease_branches"]]
|
||||||
result["released_version"] = not release_branches or BRANCH in release_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"
|
result["current"] = REVISION if REVISION else "unknown"
|
||||||
else:
|
else:
|
||||||
result["current"] = VERSION
|
result["current"] = VERSION
|
||||||
@@ -938,7 +938,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
|
|||||||
# displayVersion AND current missing or None
|
# displayVersion AND current missing or None
|
||||||
result["displayVersion"] = u"unknown"
|
result["displayVersion"] = u"unknown"
|
||||||
|
|
||||||
if check["type"] in ("github_commit",):
|
if check["type"] in ["github_commit", "bitbucket_commit"]:
|
||||||
result["current"] = check.get("current", None)
|
result["current"] = check.get("current", None)
|
||||||
else:
|
else:
|
||||||
result["current"] = check.get("current", check.get("displayVersion", None))
|
result["current"] = check.get("current", check.get("displayVersion", None))
|
||||||
@@ -974,6 +974,8 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
|
|||||||
return version_checks.github_release
|
return version_checks.github_release
|
||||||
elif check_type == "github_commit":
|
elif check_type == "github_commit":
|
||||||
return version_checks.github_commit
|
return version_checks.github_commit
|
||||||
|
elif check_type == "bitbucket_commit":
|
||||||
|
return version_checks.bitbucket_commit
|
||||||
elif check_type == "git_commit":
|
elif check_type == "git_commit":
|
||||||
return version_checks.git_commit
|
return version_checks.git_commit
|
||||||
elif check_type == "commandline":
|
elif check_type == "commandline":
|
||||||
|
|||||||
@@ -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'
|
__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"
|
__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):
|
def log_github_ratelimit(logger, r):
|
||||||
ratelimit = r.headers["X-RateLimit-Limit"] if "X-RateLimit-Limit" in r.headers else "?"
|
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:
|
except:
|
||||||
reset = "?"
|
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))
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
# 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}/commit/{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))
|
||||||
|
|
||||||
|
if not r.status_code == requests.codes.ok:
|
||||||
|
return None
|
||||||
|
|
||||||
|
reference = r.json()
|
||||||
|
if not "hash" in reference:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return reference["hash"]
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
Reference in new issue
Block a user