diff options
author | Alexander Nestorov <alexandernst@gmail.com> | 2014-10-30 15:45:55 +0100 |
---|---|---|
committer | Alexander Nestorov <alexandernst@gmail.com> | 2014-10-30 15:45:55 +0100 |
commit | 2a1eaa0384ce9d6a8209bdde62bc357123db26dc (patch) | |
tree | eb89882b5ad03a0696534d722991b21695b439ee /GitAutoDeploy.py | |
parent | 6502d11238cb4c98d85f74aabe1920da037964b7 (diff) | |
parent | 2ab5c88c9e287a9e21153726dbcaa4556a78c399 (diff) | |
download | Git-Auto-Deploy-2a1eaa0384ce9d6a8209bdde62bc357123db26dc.zip Git-Auto-Deploy-2a1eaa0384ce9d6a8209bdde62bc357123db26dc.tar.gz Git-Auto-Deploy-2a1eaa0384ce9d6a8209bdde62bc357123db26dc.tar.bz2 |
Merge pull request #19 from BOFHers/master
WIP Start working on #17
Diffstat (limited to 'GitAutoDeploy.py')
-rwxr-xr-x | GitAutoDeploy.py | 50 |
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 |