Last active
August 15, 2017 12:26
-
-
Save Denton-L/9e91de622d63063c779ea8ae380902b9 to your computer and use it in GitHub Desktop.
A quick and dirty server. You can set up a webhook to point to it and, whenever the endpoint is hit, it will automatically git pull.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import http.server | |
import socketserver | |
import subprocess | |
GIT_DIRECTORY='<directory>' | |
ENDPOINT='/<endpoint>' | |
PORT=0 | |
class GitHandler(http.server.BaseHTTPRequestHandler): | |
def __init__(self, request, client_address, server): | |
http.server.BaseHTTPRequestHandler.__init__(self, request, client_address, server) | |
def do_POST(self): | |
if self.path == ENDPOINT: | |
subprocess.Popen(['git', 'pull'], cwd = GIT_DIRECTORY).wait() | |
self.send_response(200) | |
else: | |
self.send_response(404) | |
self.end_headers() | |
if __name__ == '__main__': | |
with socketserver.TCPServer(('', PORT), GitHandler) as httpd: | |
print('Now running on port', PORT) | |
httpd.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment