summaryrefslogtreecommitdiffstats
path: root/GitAutoDeploy.py
diff options
context:
space:
mode:
authorAlexander Nestorov <alexandernst@gmail.com>2014-10-30 15:31:52 +0100
committerAlexander Nestorov <alexandernst@gmail.com>2014-10-30 15:31:52 +0100
commit96e921148eb73ebadb696c6f573d6eaabb0977c2 (patch)
treeeb89882b5ad03a0696534d722991b21695b439ee /GitAutoDeploy.py
parente05d5bf11fec49f2bc01bd6f501be271acae4137 (diff)
downloadGit-Auto-Deploy-96e921148eb73ebadb696c6f573d6eaabb0977c2.zip
Git-Auto-Deploy-96e921148eb73ebadb696c6f573d6eaabb0977c2.tar.gz
Git-Auto-Deploy-96e921148eb73ebadb696c6f573d6eaabb0977c2.tar.bz2
WIP Start working on #17
Diffstat (limited to 'GitAutoDeploy.py')
-rwxr-xr-xGitAutoDeploy.py50
1 files changed, 38 insertions, 12 deletions
diff --git a/GitAutoDeploy.py b/GitAutoDeploy.py
index 8d1f7da..334b8b6 100755
--- a/GitAutoDeploy.py
+++ b/GitAutoDeploy.py
@@ -51,21 +51,47 @@ class GitAutoDeploy(BaseHTTPRequestHandler):
self.deploy(path)
def parseRequest(self):
+ contenttype = self.headers.getheader('content-type')
length = int(self.headers.getheader('content-length'))
body = self.rfile.read(length)
- post = urlparse.parse_qs(body)
- items = []
-
- # If payload is missing, we assume gitlab syntax.
- if not 'payload' in post and 'repository' in body:
- response = json.loads(body)
- items.append(response['repository']['url'])
- # Otherwise, we assume github syntax.
- else:
- for itemString in post['payload']:
- item = json.loads(itemString)
- items.append(item['repository']['url'])
+ items = []
+
+ try:
+ if contenttype == "application/json" or contenttype == "application/x-www-form-urlencoded":
+ post = urlparse.parse_qs(body)
+
+ # If payload is missing, we assume gitlab syntax.
+ if contenttype == "application/json" and "payload" not in post:
+ mode = "github"
+ # If x-www-form-urlencoded, we assume bitbucket syntax.
+ elif contenttype == "application/x-www-form-urlencoded":
+ mode = "bitbucket"
+ # Oh Gitlab, dear Gitlab...
+ else:
+ mode = "gitlab"
+
+
+ if mode == "github":
+ response = json.loads(body)
+ items.append(response['repository']['url'])
+
+ elif mode == "bitbucket":
+ for itemString in post['payload']:
+ item = json.loads(itemString)
+ items.append("ssh://hg@bitbucket.org" + item['repository']['absolute_url'][0:-1]))
+
+ # Otherwise, we assume github/bitbucket syntax.
+ elif mode == "gitlab":
+ for itemString in post['payload']:
+ item = json.loads(itemString)
+ items.append(item['repository']['url'])
+
+ # WTF?!
+ else:
+ pass
+ except Exception:
+ pass
return items