From 5aeb334f2514983b79cedf4e5df25d853347fb65 Mon Sep 17 00:00:00 2001 From: glaslos Date: Fri, 20 Nov 2015 12:39:01 +0100 Subject: [PATCH] pull on get, see: https://github.com/logsol/Github-Auto-Deploy/pull/14 --- README.md | 1 + git_deploy.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/README.md b/README.md index e5281bb..5114d73 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ To set it up, do the following: * Enter the matching for your project(s) in the git_deploy.conf.json file * Start the server by typing "python git_deploy.py" * To run it as a daemon add --daemon-mode +* To trigger the pull and deploy via get add --get-to-pull * On the Github page go to a repository, then "Admin", "Service Hooks", "Post-Receive URLs" and add the url of your machine + port (e.g. http://example.com:8001). You can even test the whole thing here, by clicking on the "Test Hook" button, whohoo! diff --git a/git_deploy.py b/git_deploy.py index 69df63c..272bc0d 100644 --- a/git_deploy.py +++ b/git_deploy.py @@ -14,6 +14,7 @@ class GitDeploy(BaseHTTPRequestHandler): quiet = False daemon = False branch = None + is_get_available = False @classmethod def get_config(cls): @@ -33,6 +34,22 @@ def get_config(cls): and not os.path.isdir(repository['path'] + '/objects'): sys.exit('Directory ' + repository['path'] + ' is not a Git repository') + def do_GET(self): + if GitDeploy.is_get_available: + paths = [repository['path'] for repository in self.getConfig()['repositories']] + for path in paths: + self.pull(path) + self.deploy(path) + self.send_response(200) + self.send_header("Content-type", "text/html") + self.end_headers() + self.wfile.write("") + self.wfile.write("Github Autodeploy") + self.wfile.write("

Ok, updated.

") + self.wfile.write("") + else: + self.send_response(500) + def do_POST(self): event = self.headers.getheader('X-Github-Event') if event == 'ping': @@ -109,6 +126,8 @@ def main(): GitDeploy.quiet = True if arg == '-q' or arg == '--quiet': GitDeploy.quiet = True + if arg == '-g' or arg == '--get-to-pull': + GitDeploy.is_get_available = True if GitDeploy.daemon: pid = os.fork()