|
6 | 6 | import socket |
7 | 7 | from xml.etree import ElementTree |
8 | 8 |
|
9 | | -STATUSES = {'blue': {'symbol': 'S', |
10 | | - 'color': '\033[94m', |
11 | | - 'descr': 'Stable'}, |
12 | | - 'red': {'symbol': 'F', |
13 | | - 'color': '\033[91m', |
14 | | - 'descr': 'Failed'}, |
15 | | - 'yellow': {'symbol': 'U', |
16 | | - 'color': '\033[93m', |
17 | | - 'descr': 'Unstable'}, |
18 | | - 'disabled': {'symbol': 'D', |
19 | | - 'color': '\033[97m', |
20 | | - 'descr': 'Disabled'}, |
21 | | - 'aborted': {'symbol': 'A', |
22 | | - 'color': '\033[97m', |
23 | | - 'descr': 'Aborted'} |
24 | | - } |
| 9 | +STATUSES_COLOR = {'blue': {'symbol': 'S', |
| 10 | + 'color': '\033[94m', |
| 11 | + 'descr': 'Stable'}, |
| 12 | + 'red': {'symbol': 'F', |
| 13 | + 'color': '\033[91m', |
| 14 | + 'descr': 'Failed'}, |
| 15 | + 'yellow': {'symbol': 'U', |
| 16 | + 'color': '\033[93m', |
| 17 | + 'descr': 'Unstable'}, |
| 18 | + 'disabled': {'symbol': 'D', |
| 19 | + 'color': '\033[97m', |
| 20 | + 'descr': 'Disabled'}, |
| 21 | + 'unknown': {'symbol': '.', |
| 22 | + 'color': '\033[97m', |
| 23 | + 'descr': 'Unknown'}, |
| 24 | + 'aborted': {'symbol': 'A', |
| 25 | + 'color': '\033[97m', |
| 26 | + 'descr': 'Aborted'} |
| 27 | + } |
25 | 28 |
|
26 | 29 | # 'green': '\033[92m', |
27 | 30 |
|
28 | 31 |
|
29 | 32 | ENDCOLLOR = '\033[0m' |
30 | 33 | ANIME_SYMBOL = ['..', '>>'] |
31 | 34 |
|
| 35 | +RESULT_TO_COLOR = {"FAILURE": 'red', |
| 36 | + "SUCCESS": 'blue', |
| 37 | + "UNSTABLE": 'yellow', |
| 38 | + "ABORTED": 'aborted', |
| 39 | + "DISABLED": 'aborted' |
| 40 | + } |
32 | 41 |
|
33 | | -def get_formated_status(job_color, format_pattern="%(color)s%(symbol)s%(run_status)s%(endcollor)s"): |
| 42 | + |
| 43 | +def get_formated_status(job_color, format_pattern="%(color)s%(symbol)s%(run_status)s%(endcollor)s", extra_params={}): |
34 | 44 | color_status = job_color.split('_') |
35 | 45 | color = color_status[0] |
36 | 46 | run_status = color_status[1] if len(color_status) == 2 else None |
37 | | - status = STATUSES[color] |
38 | | - return format_pattern % {'color': status['color'], |
39 | | - 'symbol': status['symbol'], |
40 | | - 'descr': status['descr'], |
41 | | - 'run_status': ANIME_SYMBOL[run_status == 'anime'], |
42 | | - 'endcollor': ENDCOLLOR} |
| 47 | + status = STATUSES_COLOR[color] |
| 48 | + params = {'color': status['color'], |
| 49 | + 'symbol': status['symbol'], |
| 50 | + 'descr': status['descr'], |
| 51 | + 'run_status': ANIME_SYMBOL[run_status == 'anime'], |
| 52 | + 'endcollor': ENDCOLLOR} |
| 53 | + params.update(extra_params) |
| 54 | + return format_pattern % params |
43 | 55 |
|
44 | 56 |
|
45 | 57 | def get_jobs_legend(): |
46 | 58 | pattern = "%(color)s%(symbol)s..%(endcollor)s -> %(descr)s" |
47 | | - legend = [get_formated_status(job_color, pattern) for job_color in STATUSES.keys()] |
| 59 | + legend = [get_formated_status(job_color, pattern) for job_color in STATUSES_COLOR.keys()] |
48 | 60 | legend.append(".>> -> Build in progress") |
49 | 61 | return legend |
50 | 62 |
|
@@ -189,12 +201,34 @@ def start(self, args): |
189 | 201 | start_status = self.jenkins.build_job(job_name) |
190 | 202 | print("%s: %s" % (job_name, 'started' if not start_status else start_status)) |
191 | 203 |
|
| 204 | + def _get_build_changesets(self, build): |
| 205 | + if 'changeSet' in build and 'items' in build['changeSet']: |
| 206 | + return build['changeSet']['items'] |
| 207 | + else: |
| 208 | + return [] |
| 209 | + |
| 210 | + def _get_build_duration(self, build): |
| 211 | + return datetime.timedelta(milliseconds=build["duration"]) |
| 212 | + |
192 | 213 | def builds(self, args): |
193 | 214 | job_name = self._check_job(args.job_name) |
194 | 215 | job_info = self.jenkins.get_job_info(job_name, 1) |
195 | | - print(job_info) |
196 | | - # start_status = self.jenkins.build_job(job_name) |
197 | | - # print("%s: %s" % (job_name, 'started' if not start_status else start_status)) |
| 216 | + for build in job_info['builds'][:10]: |
| 217 | + color = RESULT_TO_COLOR.get(build['result'], 'unknown') |
| 218 | + if build['building']: |
| 219 | + color = color + "_anime" |
| 220 | + pattern = "%(color)s%(symbol)s%(run_status)s #%(number)s%(endcollor)s %(duration)s (%(changeset_count)s commits)" |
| 221 | + changeset_count = len(self._get_build_changesets(build)) |
| 222 | + status = get_formated_status(color, |
| 223 | + format_pattern=pattern, |
| 224 | + extra_params={'number': build['number'], |
| 225 | + 'duration': str(self._get_build_duration(build)).split('.')[0], |
| 226 | + 'changeset_count': changeset_count}) |
| 227 | + print(status) |
| 228 | +# "actions": [ |
| 229 | +#{ |
| 230 | +#"causes": [ |
| 231 | +# "number": 17191, |
198 | 232 |
|
199 | 233 | def stop(self, args): |
200 | 234 | job_name = self._check_job(args.job_name) |
|
0 commit comments