Skip to content

Commit

Permalink
Added test_report to build monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
Jürgen Pointinger authored and Jürgen Pointinger committed Jun 4, 2020
1 parent 2e034e1 commit bfb5349
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
37 changes: 28 additions & 9 deletions apps/monitor/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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),
Expand Down
7 changes: 7 additions & 0 deletions modules/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit bfb5349

Please sign in to comment.