|
8 | 8 | import boto3 |
9 | 9 | from botocore.vendored import requests |
10 | 10 | import logging |
| 11 | +import base64 |
11 | 12 | import os |
12 | 13 | import shutil |
13 | 14 | from zipfile import ZipFile |
@@ -66,6 +67,9 @@ def lambda_handler(event, context): |
66 | 67 | hostflavour = 'bitbucket' |
67 | 68 | elif event['params']['header']['User-Agent'].startswith('GitHub-Hookshot'): |
68 | 69 | hostflavour = 'github' |
| 70 | + elif event['body-json']['publisherId'] == 'tfs': |
| 71 | + hostflavour='tfs' |
| 72 | + |
69 | 73 | headers = {} |
70 | 74 | branch = 'master' |
71 | 75 | if hostflavour == 'githubent': |
@@ -100,6 +104,15 @@ def lambda_handler(event, context): |
100 | 104 | logger.error('Could not get OAuth token. %s: %s' % (r.json()['error'], r.json()['error_description'])) |
101 | 105 | raise Exception('Failed to get OAuth token') |
102 | 106 | headers['Authorization'] = 'Bearer ' + r.json()['access_token'] |
| 107 | + elif hostflavour == 'tfs': |
| 108 | + archive_url = event['body-json']['resourceContainers']['account']['baseUrl'] + 'DefaultCollection/' + event['body-json']['resourceContainers']['project']['id'] + '/_apis/git/repositories/' + event['body-json']['resource']['repository']['id'] + '/items' |
| 109 | + owner = event['body-json']['resource']['pushedBy']['displayName'] |
| 110 | + name = event['body-json']['resource']['repository']['name'] |
| 111 | + pat_in_base64 = base64.encodestring(':%s' % event['context']['git-token']) |
| 112 | + headers['Authorization'] = 'Basic %s' % pat_in_base64 |
| 113 | + headers['Authorization'] = headers['Authorization'].replace('\n','') |
| 114 | + headers['Accept'] = 'application/zip' |
| 115 | + |
103 | 116 | s3_archive_file = "%s/%s/%s/%s.zip" % (owner, name, branch, name) |
104 | 117 | # download the code archive via archive url |
105 | 118 | logger.info('Downloading archive from %s' % archive_url) |
|
0 commit comments