@@ -81,7 +81,11 @@ def pull_repo(repo, branch_name, remote_url, creds):
8181 remote = repo .create_remote ('origin' , remote_url )
8282 logger .info ('Fetching and merging changes from %s branch %s' , remote_url , branch_name )
8383 remote .fetch (callbacks = creds )
84- remote_branch_id = repo .lookup_reference ('refs/remotes/origin/' + branch_name ).target
84+ if (branch_name .startswith ('tags/' )):
85+ ref = 'refs/' + branch_name
86+ else :
87+ ref = 'refs/remotes/origin/' + branch_name
88+ remote_branch_id = repo .lookup_reference (ref ).target
8589 repo .checkout_tree (repo .get (remote_branch_id ))
8690 # branch_ref = repo.lookup_reference('refs/heads/' + branch_name)
8791 # branch_ref.set_target(remote_branch_id)
@@ -148,12 +152,17 @@ def lambda_handler(event, context):
148152 if not secure :
149153 logger .error ('Source IP %s is not allowed' % event ['context' ]['source-ip' ])
150154 raise Exception ('Source IP %s is not allowed' % event ['context' ]['source-ip' ])
151- try :
152- branch_name = 'master'
153- repo_name = event ['body-json' ]['project' ]['path_with_namespace' ]
154- except :
155- branch_name = event ['body-json' ]['ref' ].replace ('refs/heads/' , '' )
156- repo_name = event ['body-json' ]['repository' ]['full_name' ] + '/' + branch_name
155+
156+ if ('action' in event ['body-json' ] and event ['body-json' ]['action' ] == 'published' ):
157+ branch_name = 'tags/%s' % event ['body-json' ]['release' ]['tag_name' ]
158+ repo_name = event ['body-json' ]['repository' ]['full_name' ] + '/release'
159+ else :
160+ try :
161+ branch_name = 'master'
162+ repo_name = event ['body-json' ]['project' ]['path_with_namespace' ]
163+ except :
164+ branch_name = event ['body-json' ]['ref' ].replace ('refs/heads/' , '' )
165+ repo_name = event ['body-json' ]['repository' ]['full_name' ] + '/branch/' + branch_name
157166 try :
158167 remote_url = event ['body-json' ]['project' ]['git_ssh_url' ]
159168 except Exception :
0 commit comments