Total Complexity | 12 |
Total Lines | 28 |
Duplicated Lines | 0 % |
1 | import httplib |
||
7 | class RunBuild(CircleCI): |
||
8 | |||
9 | def run(self, project, branch=None, tag=None, vcs_revision=None): |
||
10 | """ |
||
11 | Run build for a SHA in project. |
||
12 | """ |
||
13 | |||
14 | # Add some explicit mutually-exclusive checks. |
||
15 | if not(branch or tag or vcs_revision): |
||
16 | raise Exception('At least one of branch, tag or vcs_revision should be provided.') |
||
17 | if (branch and (tag or vcs_revision)) or (tag and vcs_revision): |
||
18 | raise Exception('Only one of branch, tag or vcs_revision should be provided.') |
||
19 | |||
20 | data = None |
||
21 | if branch: |
||
22 | path = 'project/%s/tree/%s' % (project, branch) |
||
23 | else: |
||
24 | path = 'project/%s' % project |
||
25 | data = {'tag': tag} if tag else {'revision': vcs_revision} |
||
26 | data = json.dumps(data) |
||
27 | |||
28 | response = self._perform_request(path, method='POST', data=data) |
||
29 | |||
30 | if response.status_code != httplib.CREATED: |
||
31 | message = response.json().get('message', 'Unknown reason.') |
||
32 | raise Exception('Failed to run build : %s' % message) |
||
33 | |||
34 | return response.json() |
||
35 |