improve mercurial hook error handling

This commit is contained in:
Sebastian Sdorra
2012-06-02 15:06:59 +02:00
parent 3ba0766281
commit a5fa1fc007

View File

@@ -42,11 +42,8 @@ baseUrl = os.environ['SCM_URL']
challenge = os.environ['SCM_CHALLENGE'] challenge = os.environ['SCM_CHALLENGE']
credentials = os.environ['SCM_CREDENTIALS'] credentials = os.environ['SCM_CREDENTIALS']
def callback(ui, repo, hooktype, node=None, source=None, pending=None, **kwargs): def callHookUrl(ui, repo, hooktype, node):
if pending != None: abort = True
pending()
failure = True
if node != None:
try: try:
url = baseUrl + hooktype url = baseUrl + hooktype
ui.debug( "send scm-hook to " + url + " and " + node + "\n" ) ui.debug( "send scm-hook to " + url + " and " + node + "\n" )
@@ -54,9 +51,23 @@ def callback(ui, repo, hooktype, node=None, source=None, pending=None, **kwargs)
conn = urllib2.urlopen(url, data); conn = urllib2.urlopen(url, data);
if conn.code >= 200 and conn.code < 300: if conn.code >= 200 and conn.code < 300:
ui.debug( "scm-hook " + hooktype + " success with status code " + str(conn.code) + "\n" ) ui.debug( "scm-hook " + hooktype + " success with status code " + str(conn.code) + "\n" )
failure = False abort = False
else: else:
ui.warn( "scm-hook failed with error code " + str(conn.code) + "\n" ) ui.warn( "ERROR: scm-hook failed with error code " + str(conn.code) + "\n" )
except ValueError: except ValueError:
ui.warn( "scm-hook failed with an exception\n" ) ui.warn( "scm-hook failed with an exception\n" )
return failure return abort
def callback(ui, repo, hooktype, node=None, source=None, pending=None, **kwargs):
if pending != None:
pending()
abort = True
if node != None:
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