Skip to content
This repository was archived by the owner on Oct 4, 2024. It is now read-only.

Commit 7e1450c

Browse files
authored
Merge pull request #25 from velovint/support_branches_tags
Support branches and tags
2 parents 7b36f63 + 9608346 commit 7e1450c

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed
-277 KB
Binary file not shown.

functions/source/GitPullS3/lambda_function.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,35 +150,42 @@ def lambda_handler(event, context):
150150
secure = True
151151
# TODO: Add the ability to clone TFS repo using SSH keys
152152
try:
153+
# GitHub
153154
full_name = event['body-json']['repository']['full_name']
154155
except KeyError:
155156
try:
157+
# BitBucket #14
156158
full_name = event['body-json']['repository']['fullName']
157159
except KeyError:
158-
full_name = event['body-json']['repository']['path_with_namespace']
160+
try:
161+
# GitLab
162+
full_name = event['body-json']['repository']['path_with_namespace']
163+
except KeyError:
164+
# GitLab 8.5+
165+
full_name = event['body-json']['project']['path_with_namespace']
159166
if not secure:
160167
logger.error('Source IP %s is not allowed' % event['context']['source-ip'])
161168
raise Exception('Source IP %s is not allowed' % event['context']['source-ip'])
162169

170+
# GitHub publish event
163171
if('action' in event['body-json'] and event['body-json']['action'] == 'published'):
164172
branch_name = 'tags/%s' % event['body-json']['release']['tag_name']
165173
repo_name = full_name + '/release'
166174
else:
175+
repo_name = full_name
167176
try:
168-
branch_name = 'master'
169-
repo_name = event['body-json']['project']['path_with_namespace']
177+
# branch names should contain [name] only, tag names - "tags/[name]"
178+
branch_name = event['body-json']['ref'].replace('refs/heads/', '').replace('refs/tags/', 'tags/')
170179
except:
171-
if 'ref' in event['body-json']:
172-
branch_name = event['body-json']['ref'].replace('refs/heads/', '')
173-
else:
174-
branch_name = 'master'
175-
repo_name = full_name + '/branch/' + branch_name
180+
branch_name = 'master'
176181
try:
182+
# GitLab
177183
remote_url = event['body-json']['project']['git_ssh_url']
178184
except Exception:
179185
try:
180186
remote_url = 'git@'+event['body-json']['repository']['links']['html']['href'].replace('https://', '').replace('/', ':', 1)+'.git'
181187
except:
188+
# GitHub
182189
remote_url = event['body-json']['repository']['ssh_url']
183190
repo_path = '/tmp/%s' % repo_name
184191
creds = RemoteCallbacks(credentials=get_keys(keybucket, pubkey), )

0 commit comments

Comments
 (0)