summaryrefslogtreecommitdiffstats
path: root/gitautodeploy/parsers/bitbucket.py
diff options
context:
space:
mode:
Diffstat (limited to 'gitautodeploy/parsers/bitbucket.py')
-rw-r--r--gitautodeploy/parsers/bitbucket.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/gitautodeploy/parsers/bitbucket.py b/gitautodeploy/parsers/bitbucket.py
new file mode 100644
index 0000000..b02a6ac
--- /dev/null
+++ b/gitautodeploy/parsers/bitbucket.py
@@ -0,0 +1,37 @@
+from WebhookRequestParser import WebhookRequestParser
+
+class BitBucketRequestParser(WebhookRequestParser):
+
+ def get_repo_params_from_request(self, request_headers, request_body):
+ import json
+ import logging
+
+ logger = logging.getLogger()
+ data = json.loads(request_body)
+
+ repo_urls = []
+ ref = ""
+ action = ""
+
+ logger.info("Received event from BitBucket")
+
+ if 'repository' not in data:
+ logger.error("Unable to recognize data format")
+ return [], ref or "master", action
+
+ # One repository may posses multiple URLs for different protocols
+ for k in ['url', 'git_url', 'clone_url', 'ssh_url']:
+ if k in data['repository']:
+ repo_urls.append(data['repository'][k])
+
+ if 'full_name' in data['repository']:
+ repo_urls.append('git@bitbucket.org:%s.git' % data['repository']['full_name'])
+
+ # Add a simplified version of the bitbucket HTTPS URL - without the username@bitbucket.com part. This is
+ # needed since the configured repositories might be configured using a different username.
+ repo_urls.append('https://bitbucket.org/%s.git' % (data['repository']['full_name']))
+
+ # Get a list of configured repositories that matches the incoming web hook reqeust
+ repo_configs = self.get_matching_repo_configs(repo_urls)
+
+ return repo_configs, ref or "master", action \ No newline at end of file