|
19 | 19 | import json |
20 | 20 | import os |
21 | 21 | import re |
| 22 | +from typing import List |
| 23 | +from typing import Optional |
22 | 24 |
|
23 | 25 | import apiclient |
24 | 26 | from oauth2client.service_account import ServiceAccountCredentials |
@@ -119,10 +121,22 @@ def download_artifact(client, bid, target, attempt_id, name, output_directory, |
119 | 121 | return output_path |
120 | 122 |
|
121 | 123 |
|
122 | | -def get_artifacts_for_build(client, bid, target, attempt_id='latest'): |
| 124 | +def get_artifacts_for_build(client, |
| 125 | + bid: str, |
| 126 | + target: str, |
| 127 | + attempt_id: str = 'latest', |
| 128 | + regexp: Optional[str] = None) -> List[str]: |
123 | 129 | """Return list of artifacts for a given build.""" |
124 | | - request = client.buildartifact().list( |
125 | | - buildId=bid, target=target, attemptId=attempt_id) |
| 130 | + if not regexp: |
| 131 | + request = client.buildartifact().list( |
| 132 | + buildId=bid, target=target, attemptId=attempt_id) |
| 133 | + else: |
| 134 | + request = client.buildartifact().list( |
| 135 | + buildId=bid, |
| 136 | + target=target, |
| 137 | + attemptId=attempt_id, |
| 138 | + nameRegexp=regexp, |
| 139 | + maxResults=100) |
126 | 140 |
|
127 | 141 | request_str = (f'{request.uri}, {request.method}, ' |
128 | 142 | f'{request.body}, {request.methodId}') |
@@ -239,7 +253,7 @@ def get(bid, target, regex, output_directory, output_filename=None): |
239 | 253 | def run_script(client, bid, target, regex, output_directory, output_filename): |
240 | 254 | """Download artifacts as specified.""" |
241 | 255 | artifacts = get_artifacts_for_build( |
242 | | - client=client, bid=bid, target=target, attempt_id='latest') |
| 256 | + client=client, bid=bid, target=target, attempt_id='latest', regexp=regex) |
243 | 257 | if not artifacts: |
244 | 258 | logs.error(f'Artifact could not be fetched for target {target}, ' |
245 | 259 | f'build id {bid}.') |
|
0 commit comments