summaryrefslogtreecommitdiffstats
path: root/gitautodeploy
diff options
context:
space:
mode:
Diffstat (limited to 'gitautodeploy')
-rw-r--r--gitautodeploy/gitautodeploy.py6
-rw-r--r--gitautodeploy/httpserver.py7
-rw-r--r--gitautodeploy/lock.py6
-rw-r--r--gitautodeploy/parsers/bitbucket.py2
-rw-r--r--gitautodeploy/parsers/generic.py2
-rw-r--r--gitautodeploy/parsers/github.py8
-rw-r--r--gitautodeploy/parsers/gitlab.py4
-rw-r--r--gitautodeploy/wrappers/git.py23
8 files changed, 34 insertions, 24 deletions
diff --git a/gitautodeploy/gitautodeploy.py b/gitautodeploy/gitautodeploy.py
index 1a04b5a..342ce9e 100644
--- a/gitautodeploy/gitautodeploy.py
+++ b/gitautodeploy/gitautodeploy.py
@@ -106,13 +106,15 @@ class GitAutoDeploy(object):
# Only clone repositories with a configured path
if 'path' not in repo_config:
- logger.info("Repository %s will not be cloned (no path configured)" % repo_config['url'])
+ logger.debug("Repository %s will not be cloned (no path configured)" % repo_config['url'])
continue
if os.path.isdir(repo_config['path']) and os.path.isdir(repo_config['path']+'/.git'):
- logger.info("Repository %s already present" % repo_config['url'])
+ logger.debug("Repository %s already present" % repo_config['url'])
continue
+ logger.info("Repository %s not present and needs to be cloned" % repo_config['url'])
+
# Clone repository
ret = GitWrapper.clone(url=repo_config['url'], branch=repo_config['branch'], path=repo_config['path'])
diff --git a/gitautodeploy/httpserver.py b/gitautodeploy/httpserver.py
index 23d660c..6a6608a 100644
--- a/gitautodeploy/httpserver.py
+++ b/gitautodeploy/httpserver.py
@@ -53,11 +53,11 @@ class WebhookRequestHandler(BaseHTTPRequestHandler):
self.send_header('Content-type', 'text/plain')
self.end_headers()
- logger.info('Using %s to handle the request.' % ServiceRequestParser.__name__)
+ logger.info('Handling the request with %s' % ServiceRequestParser.__name__)
# Could be GitHubParser, GitLabParser or other
repo_configs, ref, action, repo_urls = ServiceRequestParser(self._config).get_repo_params_from_request(request_headers, request_body)
- logger.info("Event details - ref: %s; action: %s" % (ref or "master", action))
+ logger.debug("Event details - ref: %s; action: %s" % (ref or "master", action))
if len(repo_configs) == 0:
self.send_error(400, 'Bad request')
@@ -109,8 +109,7 @@ class WebhookRequestHandler(BaseHTTPRequestHandler):
go through our custom logger instead."""
import logging
logger = logging.getLogger()
- logger.info("%s - - [%s] %s" % (self.client_address[0],
- self.log_date_time_string(),
+ logger.info("%s - %s" % (self.client_address[0],
format%args))
def figure_out_service_from_request(self, request_headers, request_body):
diff --git a/gitautodeploy/lock.py b/gitautodeploy/lock.py
index 8bd8b32..b0b408b 100644
--- a/gitautodeploy/lock.py
+++ b/gitautodeploy/lock.py
@@ -16,7 +16,7 @@ class Lock():
try:
os.open(self.path, os.O_CREAT | os.O_EXCL | os.O_WRONLY)
self._has_lock = True
- logger.info("Successfully obtained lock: %s" % self.path)
+ logger.debug("Successfully obtained lock: %s" % self.path)
except OSError:
return False
else:
@@ -31,7 +31,7 @@ class Lock():
raise Exception("Unable to release lock that is owned by another process")
try:
os.remove(self.path)
- logger.info("Successfully released lock: %s" % self.path)
+ logger.debug("Successfully released lock: %s" % self.path)
finally:
self._has_lock = False
@@ -48,5 +48,5 @@ class Lock():
except OSError:
pass
finally:
- logger.info("Successfully cleared lock: %s" % self.path)
+ logger.debug("Successfully cleared lock: %s" % self.path)
self._has_lock = False \ No newline at end of file
diff --git a/gitautodeploy/parsers/bitbucket.py b/gitautodeploy/parsers/bitbucket.py
index d1dc095..353435c 100644
--- a/gitautodeploy/parsers/bitbucket.py
+++ b/gitautodeploy/parsers/bitbucket.py
@@ -13,7 +13,7 @@ class BitBucketRequestParser(WebhookRequestParser):
ref = ""
action = ""
- logger.info("Received event from BitBucket")
+ logger.debug("Received event from BitBucket")
if 'repository' not in data:
logger.error("Unable to recognize data format")
diff --git a/gitautodeploy/parsers/generic.py b/gitautodeploy/parsers/generic.py
index 6dede03..3247662 100644
--- a/gitautodeploy/parsers/generic.py
+++ b/gitautodeploy/parsers/generic.py
@@ -13,7 +13,7 @@ class GenericRequestParser(WebhookRequestParser):
ref = ""
action = ""
- logger.info("Received event from unknown origin. Assume generic data format.")
+ logger.debug("Received event from unknown origin. Assume generic data format.")
if 'repository' not in data:
logger.error("Unable to recognize data format")
diff --git a/gitautodeploy/parsers/github.py b/gitautodeploy/parsers/github.py
index 82785c3..7077def 100644
--- a/gitautodeploy/parsers/github.py
+++ b/gitautodeploy/parsers/github.py
@@ -15,7 +15,7 @@ class GitHubRequestParser(WebhookRequestParser):
github_event = 'x-github-event' in request_headers and request_headers['x-github-event']
- logger.info("Received '%s' event from GitHub" % github_event)
+ logger.debug("Received '%s' event from GitHub" % github_event)
if 'repository' not in data:
logger.error("Unable to recognize data format")
@@ -30,14 +30,14 @@ class GitHubRequestParser(WebhookRequestParser):
if 'base' in data['pull_request']:
if 'ref' in data['pull_request']['base']:
ref = data['pull_request']['base']['ref']
- logger.info("Pull request to branch '%s' was fired" % ref)
+ logger.debug("Pull request to branch '%s' was fired" % ref)
elif 'ref' in data:
ref = data['ref']
- logger.info("Push to branch '%s' was fired" % ref)
+ logger.debug("Push to branch '%s' was fired" % ref)
if 'action' in data:
action = data['action']
- logger.info("Action '%s' was fired" % action)
+ logger.debug("Action '%s' was fired" % action)
# Get a list of configured repositories that matches the incoming web hook reqeust
items = self.get_matching_repo_configs(repo_urls)
diff --git a/gitautodeploy/parsers/gitlab.py b/gitautodeploy/parsers/gitlab.py
index 6c9a8d4..3551dc6 100644
--- a/gitautodeploy/parsers/gitlab.py
+++ b/gitautodeploy/parsers/gitlab.py
@@ -15,7 +15,7 @@ class GitLabRequestParser(WebhookRequestParser):
gitlab_event = 'x-gitlab-event' in request_headers and request_headers['x-gitlab-event']
- logger.info("Received '%s' event from GitLab" % gitlab_event)
+ logger.debug("Received '%s' event from GitLab" % gitlab_event)
if 'repository' not in data:
logger.error("Unable to recognize data format")
@@ -53,7 +53,7 @@ class GitLabCIRequestParser(WebhookRequestParser):
ref = ""
action = ""
- logger.info('Received event from Gitlab CI')
+ logger.debug('Received event from Gitlab CI')
if 'push_data' not in data:
logger.error("Unable to recognize data format")
diff --git a/gitautodeploy/wrappers/git.py b/gitautodeploy/wrappers/git.py
index 63a94fc..7d18550 100644
--- a/gitautodeploy/wrappers/git.py
+++ b/gitautodeploy/wrappers/git.py
@@ -10,16 +10,15 @@ class GitWrapper():
"""Pulls the latest version of the repo from the git server"""
import logging
from process import ProcessWrapper
-
+ import os
+
logger = logging.getLogger()
- logger.info("Post push request received")
+ logger.info("Updating repository %s" % repo_config['path'])
# Only pull if there is actually a local copy of the repository
if 'path' not in repo_config:
logger.info('No local repository path configured, no pull will occure')
return 0
-
- logger.info('Updating ' + repo_config['path'])
cmd = 'unset GIT_DIR ' + \
'&& git fetch ' + repo_config['remote'] + \
@@ -29,7 +28,11 @@ class GitWrapper():
# '&& git update-index --refresh ' +\
res = ProcessWrapper().call([cmd], cwd=repo_config['path'], shell=True)
- logger.info('Pull result: ' + str(res))
+
+ if res == 0 and os.path.isdir(repo_config['path']):
+ logger.info("Repository %s successfully updated" % repo_config['path'])
+ else:
+ logger.error("Unable to update repository %s" % repo_config['path'])
return int(res)
@@ -49,8 +52,12 @@ class GitWrapper():
if 'path' in repo_config:
path = repo_config['path']
- logger.info('Executing deploy command(s)')
-
+ if not 'deploy_commands' in repo_config or len(repo_config['deploy_commands']) == 0:
+ logger.info('No deploy commands configured')
+ return []
+
+ logger.info('Executing %s deploy commands' % str(len(repo_config['deploy_commands'])))
+
# Use repository path as default cwd when executing deploy commands
cwd = (repo_config['path'] if 'path' in repo_config else None)
@@ -58,4 +65,6 @@ class GitWrapper():
for cmd in repo_config['deploy_commands']:
res.append(ProcessWrapper().call([cmd], cwd=cwd, shell=True))
+ logger.info('%s commands executed with status; %s' % (str(len(res)), str(res)))
+
return res \ No newline at end of file