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

Commit 56f390f

Browse files
author
Vitali Yakavenka
committed
Use ref from webhook when fetching code instead of defaulting to master branch.
1 parent 78c2702 commit 56f390f

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

functions/source/GitPullS3/lambda_function.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,35 +150,39 @@ 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:
158160
try:
161+
# GitLab
159162
full_name = event['body-json']['repository']['path_with_namespace']
160163
except KeyError:
164+
# GitLab 8.5+
161165
full_name = event['body-json']['project']['path_with_namespace']
162166
if not secure:
163167
logger.error('Source IP %s is not allowed' % event['context']['source-ip'])
164168
raise Exception('Source IP %s is not allowed' % event['context']['source-ip'])
165169

170+
# GitHub publish event
166171
if('action' in event['body-json'] and event['body-json']['action'] == 'published'):
167172
branch_name = 'tags/%s' % event['body-json']['release']['tag_name']
168173
repo_name = full_name + '/release'
169174
else:
170-
try:
171-
branch_name = 'master'
172-
repo_name = event['body-json']['project']['path_with_namespace']
173-
except:
174-
branch_name = event['body-json']['ref'].replace('refs/heads/', '')
175-
repo_name = full_name + '/branch/' + branch_name
175+
# branch names should contain [name] only, tag names - "tags/[name]"
176+
branch_name = event['body-json']['ref'].replace('refs/heads/', '').replace('refs/tags/', 'tags/')
177+
repo_name = full_name
176178
try:
179+
# GitLab
177180
remote_url = event['body-json']['project']['git_ssh_url']
178181
except Exception:
179182
try:
180183
remote_url = 'git@'+event['body-json']['repository']['links']['html']['href'].replace('https://', '').replace('/', ':', 1)+'.git'
181184
except:
185+
# GitHub
182186
remote_url = event['body-json']['repository']['ssh_url']
183187
repo_path = '/tmp/%s' % repo_name
184188
creds = RemoteCallbacks(credentials=get_keys(keybucket, pubkey), )

0 commit comments

Comments
 (0)