2222logger .handlers [0 ].setFormatter (logging .Formatter ('[%(asctime)s][%(levelname)s] %(message)s' ))
2323logging .getLogger ('boto3' ).setLevel (logging .ERROR )
2424logging .getLogger ('botocore' ).setLevel (logging .ERROR )
25-
25+ params = None
2626s3_client = boto3 .client ('s3' )
2727
2828
@@ -52,6 +52,7 @@ def get_members(zip):
5252
5353
5454def lambda_handler (event , context ):
55+
5556 logger .info ('Event %s' , event )
5657 OAUTH_token = event ['context' ]['git-token' ]
5758 OutputBucket = event ['context' ]['output-bucket' ]
@@ -90,10 +91,16 @@ def lambda_handler(event, context):
9091 # add access token information to archive url
9192 archive_url = archive_url + '?access_token=' + OAUTH_token
9293 elif hostflavour == 'gitlab' :
93- # https://gitlab.com/jaymcconnell/gitlab-test-30/repository/archive.zip?ref=master
94- archive_url = event ['body-json' ]['project' ]['http_url' ].replace ('.git' , '/repository/archive.zip?ref=master' )+ '&private_token=' + OAUTH_token
94+ #https://gitlab.com/jaymcconnell/gitlab-test-30/repository/archive.zip?ref=master
95+ archive_root = event ['body-json' ]['project' ]['http_url' ].strip ('.git' )
96+ project_id = event ['body-json' ]['project_id' ]
97+ branch = event ['body-json' ]['ref' ].replace ('refs/heads/' , '' )
98+ archive_url = f"https://gitlab.com/api/v4/projects/{ project_id } /repository/archive.zip"
99+ params = {'private_token' : OAUTH_token , 'sha' : branch }
100+
95101 owner = event ['body-json' ]['project' ]['namespace' ]
96102 name = event ['body-json' ]['project' ]['name' ]
103+
97104 elif hostflavour == 'bitbucket' :
98105 branch = event ['body-json' ]['push' ]['changes' ][0 ]['new' ]['name' ]
99106 archive_url = event ['body-json' ]['repository' ]['links' ]['html' ]['href' ]+ '/get/' + branch + '.zip'
@@ -116,7 +123,7 @@ def lambda_handler(event, context):
116123 s3_archive_file = "%s/%s/%s/%s.zip" % (owner , name , branch , name )
117124 # download the code archive via archive url
118125 logger .info ('Downloading archive from %s' % archive_url )
119- r = requests .get (archive_url , verify = verify , headers = headers )
126+ r = requests .get (archive_url , verify = verify , headers = headers , params = params )
120127 f = StringIO (r .content )
121128 zip = ZipFile (f )
122129 path = '/tmp/code'
0 commit comments