Total Complexity | 5 |
Total Lines | 23 |
Duplicated Lines | 0 % |
1 | import httplib |
||
6 | class GetBuildNumberAction(CircleCI): |
||
7 | |||
8 | def run(self, vcs_revision, project, search_limit=10): |
||
9 | """ |
||
10 | Get build number for a SHA in project. |
||
11 | """ |
||
12 | path = 'project/' + project |
||
13 | |||
14 | response = self._perform_request( |
||
15 | path, method='GET', |
||
16 | extra_headers={'limit': int(search_limit)} |
||
17 | ) |
||
18 | |||
19 | if response.status_code != httplib.OK: |
||
20 | raise Exception('Project %s not found.' % project) |
||
21 | |||
22 | for build in response.json(): |
||
23 | if build['vcs_revision'] == vcs_revision: |
||
24 | build_num = build.get('build_num', None) |
||
25 | if not build_num: |
||
26 | raise Exception( |
||
27 | 'API must have changed. build_num not found.') |
||
28 | return build_num |
||
29 |