From bfb5349f1ab99fded37085771144b6af573482c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Pointinger?= Date: Thu, 4 Jun 2020 18:38:23 +0200 Subject: [PATCH] Added test_report to build monitor --- apps/monitor/callbacks.py | 37 ++++++++++++++++++++++++++++--------- modules/gitlab.py | 7 +++++++ 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/apps/monitor/callbacks.py b/apps/monitor/callbacks.py index 3cd7953..7c4725b 100644 --- a/apps/monitor/callbacks.py +++ b/apps/monitor/callbacks.py @@ -35,6 +35,9 @@ def __get_pipeline_data(project_id, ref_name): def __get_active_jobs_data(project_id, pipeline_id): return gl.get_active_jobs(project_id, pipeline_id) +def __get_inactive_jobs_data(project_id, pipeline_id): + return gl.get_inactive_jobs(project_id, pipeline_id) + def __get_test_report_data(project_id, pipeline_id): return gl.get_test_report(project_id, pipeline_id) @@ -68,24 +71,40 @@ def render_card(n): elif 'failed' == status: color = 'danger' - if 'failed' == status: - test_report = __get_test_report_data(project_id, pipeline_id) - - joint_active_jobs = '' - if 'running' == status or 'failed' == status or 'manual' == status: + joint_jobs = '' + if 'failed' == status or 'canceled' == status: + inactive_jobs = __get_inactive_jobs_data(project_id, pipeline_id) + for job in inactive_jobs: + job_name = job['name'] + if joint_jobs == '': + joint_jobs = job_name + else: + joint_jobs = joint_jobs + ', ' + job_name + elif 'running' == status or 'manual' == status: active_jobs = __get_active_jobs_data(project_id, pipeline_id) for job in active_jobs: job_name = job['name'] - if joint_active_jobs == '': - joint_active_jobs = job_name + if joint_jobs == '': + joint_jobs = job_name else: - joint_active_jobs = joint_active_jobs + ', ' + job_name + joint_jobs = joint_jobs + ', ' + job_name + + test_details = '' + if 'failed' == status: + test_report = __get_test_report_data(project_id, pipeline_id) + if 'total_count' in test_report and test_report['total_count'] > 0: + test_details = 'Total ({}): Success ({}), Skipped ({}), Failed ({})'.format( + test_report['total_count'], + test_report['success_count'], + test_report['skipped_count'], + test_report['failed_count']) return [dbc.CardHeader(name), dbc.CardBody([ html.H2(status.upper(), className="mb-2", style={'text-align': 'center'}), html.Div(str(timedelta(seconds=duration)), className="mb-2", style={'text-align': 'center'}), - html.Div(joint_active_jobs, className="mb-2", style={'text-align': 'center'}), + html.Div(joint_jobs, className="mb-2", style={'text-align': 'center'}), + html.Div(test_details, className="mb-2", style={'text-align': 'center'}), html.Span([ dbc.Button( "Coverage: {:.2f} %".format(coverage), diff --git a/modules/gitlab.py b/modules/gitlab.py index a781ce1..999c992 100644 --- a/modules/gitlab.py +++ b/modules/gitlab.py @@ -129,6 +129,13 @@ def get_active_jobs(self, project_id, pipeline_id): retval = response.json() return retval + def get_inactive_jobs(self, project_id, pipeline_id): + retval = [] + response = self.get_request('/projects/{}/pipelines/{}/jobs?scope[]=failed&scope[]=canceled'.format(project_id, pipeline_id)) + if response.status_code == 200: + retval = response.json() + return retval + def get_test_report(self, project_id, pipeline_id): retval = [] response = self.get_request('/projects/{}/pipelines/{}/test_report'.format(project_id, pipeline_id))