Skip to content

Instantly share code, notes, and snippets.

@Denton-L
Last active August 15, 2017 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Denton-L/9e91de622d63063c779ea8ae380902b9 to your computer and use it in GitHub Desktop.
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.
#!/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