diff --git a/functions/packages/GitPullS3/lambda.zip b/functions/packages/GitPullS3/lambda.zip index 199d2a8..fe694c3 100644 Binary files a/functions/packages/GitPullS3/lambda.zip and b/functions/packages/GitPullS3/lambda.zip differ diff --git a/functions/source/GitPullS3/lambda_function.py b/functions/source/GitPullS3/lambda_function.py index 03d5659..87d1883 100644 --- a/functions/source/GitPullS3/lambda_function.py +++ b/functions/source/GitPullS3/lambda_function.py @@ -150,35 +150,42 @@ def lambda_handler(event, context): secure = True # TODO: Add the ability to clone TFS repo using SSH keys try: + # GitHub full_name = event['body-json']['repository']['full_name'] except KeyError: try: + # BitBucket #14 full_name = event['body-json']['repository']['fullName'] except KeyError: - full_name = event['body-json']['repository']['path_with_namespace'] + try: + # GitLab + full_name = event['body-json']['repository']['path_with_namespace'] + except KeyError: + # GitLab 8.5+ + full_name = event['body-json']['project']['path_with_namespace'] if not secure: logger.error('Source IP %s is not allowed' % event['context']['source-ip']) raise Exception('Source IP %s is not allowed' % event['context']['source-ip']) + # GitHub publish event if('action' in event['body-json'] and event['body-json']['action'] == 'published'): branch_name = 'tags/%s' % event['body-json']['release']['tag_name'] repo_name = full_name + '/release' else: + repo_name = full_name try: - branch_name = 'master' - repo_name = event['body-json']['project']['path_with_namespace'] + # branch names should contain [name] only, tag names - "tags/[name]" + branch_name = event['body-json']['ref'].replace('refs/heads/', '').replace('refs/tags/', 'tags/') except: - if 'ref' in event['body-json']: - branch_name = event['body-json']['ref'].replace('refs/heads/', '') - else: - branch_name = 'master' - repo_name = full_name + '/branch/' + branch_name + branch_name = 'master' try: + # GitLab remote_url = event['body-json']['project']['git_ssh_url'] except Exception: try: remote_url = 'git@'+event['body-json']['repository']['links']['html']['href'].replace('https://', '').replace('/', ':', 1)+'.git' except: + # GitHub remote_url = event['body-json']['repository']['ssh_url'] repo_path = '/tmp/%s' % repo_name creds = RemoteCallbacks(credentials=get_keys(keybucket, pubkey), )