@@ -154,50 +154,61 @@ def lambda_handler(event, context):
154154 secure = True
155155 # TODO: Add the ability to clone TFS repo using SSH keys
156156 try :
157+ # GitHub
157158 full_name = event ['body-json' ]['repository' ]['full_name' ]
158159 except KeyError :
159160 try :
161+ # BitBucket #14
160162 full_name = event ['body-json' ]['repository' ]['fullName' ]
161163 except KeyError :
162164 try :
165+ # GitLab
163166 full_name = event ['body-json' ]['repository' ]['path_with_namespace' ]
164167 except KeyError :
165168 try :
166- full_name = event ['body-json' ]['repository' ]['name' ]
167- except KeyError : # BitBucket pull-request
168- full_name = event ['body-json' ]['pullRequest' ]['fromRef' ]['repository' ]['name' ]
169+ # GitLab 8.5+
170+ full_name = event ['body-json' ]['project' ]['path_with_namespace' ]
171+ except KeyError :
172+ try :
173+ # BitBucket server
174+ full_name = event ['body-json' ]['repository' ]['name' ]
175+ except KeyError :
176+ # BitBucket pull-request
177+ full_name = event ['body-json' ]['pullRequest' ]['fromRef' ]['repository' ]['name' ]
169178 if not secure :
170179 logger .error ('Source IP %s is not allowed' % event ['context' ]['source-ip' ])
171180 raise Exception ('Source IP %s is not allowed' % event ['context' ]['source-ip' ])
172181
182+ # GitHub publish event
173183 if ('action' in event ['body-json' ] and event ['body-json' ]['action' ] == 'published' ):
174184 branch_name = 'tags/%s' % event ['body-json' ]['release' ]['tag_name' ]
175185 repo_name = full_name + '/release'
176186 else :
187+ repo_name = full_name
177188 try :
178- branch_name = 'master'
179- repo_name = event ['body-json' ]['project' ][ 'path_with_namespace' ]
189+ # branch names should contain [name] only, tag names - "tags/[name]"
190+ branch_name = event ['body-json' ]['ref' ]. replace ( 'refs/heads/' , '' ). replace ( 'refs/tags/' , 'tags/' )
180191 except :
181- if 'ref' in event ['body-json' ]:
182- branch_name = event ['body-json' ]['ref' ].replace ('refs/heads/' , '' )
183- else :
184- branch_name = 'master'
185- repo_name = full_name + '/branch/' + branch_name
192+ branch_name = 'master'
186193 try :
194+ # GitLab
187195 remote_url = event ['body-json' ]['project' ]['git_ssh_url' ]
188196 except Exception :
189197 try :
190198 remote_url = 'git@' + event ['body-json' ]['repository' ]['links' ]['html' ]['href' ].replace ('https://' , '' ).replace ('/' , ':' , 1 )+ '.git'
191199 except :
192200 try :
201+ # GitHub
193202 remote_url = event ['body-json' ]['repository' ]['ssh_url' ]
194- except : #Bitbucket
203+ except :
204+ # Bitbucket
195205 try :
196206 for i , url in enumerate (event ['body-json' ]['repository' ]['links' ]['clone' ]):
197207 if url ['name' ] == 'ssh' :
198208 ssh_index = i
199209 remote_url = event ['body-json' ]['repository' ]['links' ]['clone' ][ssh_index ]['href' ]
200- except : # BitBucket pull-request
210+ except :
211+ # BitBucket pull-request
201212 for i , url in enumerate (event ['body-json' ]['pullRequest' ]['fromRef' ]['repository' ]['links' ]['clone' ]):
202213 if url ['name' ] == 'ssh' :
203214 ssh_index = i
0 commit comments