From a5fa1fc007f17668b860edf59a750f6b0f56d989 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 2 Jun 2012 15:06:59 +0200 Subject: [PATCH] improve mercurial hook error handling --- .../resources/sonia/scm/python/scmhooks.py | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/scmhooks.py b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/scmhooks.py index c7266ccf23..e414aad9f7 100644 --- a/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/scmhooks.py +++ b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/scmhooks.py @@ -42,21 +42,32 @@ baseUrl = os.environ['SCM_URL'] challenge = os.environ['SCM_CHALLENGE'] credentials = os.environ['SCM_CREDENTIALS'] +def callHookUrl(ui, repo, hooktype, node): + abort = True + try: + url = baseUrl + hooktype + ui.debug( "send scm-hook to " + url + " and " + node + "\n" ) + data = urllib.urlencode({'node': node, 'challenge': challenge, 'credentials': credentials, 'repositoryPath': repo.root}) + conn = urllib2.urlopen(url, data); + if conn.code >= 200 and conn.code < 300: + ui.debug( "scm-hook " + hooktype + " success with status code " + str(conn.code) + "\n" ) + abort = False + else: + ui.warn( "ERROR: scm-hook failed with error code " + str(conn.code) + "\n" ) + except ValueError: + ui.warn( "scm-hook failed with an exception\n" ) + return abort + def callback(ui, repo, hooktype, node=None, source=None, pending=None, **kwargs): if pending != None: pending() - failure = True + abort = True if node != None: - try: - url = baseUrl + hooktype - ui.debug( "send scm-hook to " + url + " and " + node + "\n" ) - data = urllib.urlencode({'node': node, 'challenge': challenge, 'credentials': credentials, 'repositoryPath': repo.root}) - conn = urllib2.urlopen(url, data); - if conn.code >= 200 and conn.code < 300: - ui.debug( "scm-hook " + hooktype + " success with status code " + str(conn.code) + "\n" ) - failure = False - else: - ui.warn( "scm-hook failed with error code " + str(conn.code) + "\n" ) - except ValueError: - ui.warn( "scm-hook failed with an exception\n" ) - return failure + if len(baseUrl) > 0: + abort = callHookUrl(ui, repo, hooktype, node) + else: + ui.warn("ERROR: scm-manager hooks are disabled, please check your configuration and the scm-manager log for details\n") + abort = False + else: + ui.warn("changeset node is not available") + return abort