Handle forward compatability with cycle refactor

This handles the old and new data format for the builds/ and build/
endpoints.  Builds will soon include multiple refs.

Change-Id: I1db5e9fc3fd38864f72b914e09629d3d0637f355
This commit is contained in:
James E. Blair 2024-02-02 11:25:43 -08:00
parent 6250b3eb4d
commit 21785e1464

View File

@ -130,22 +130,26 @@ class PrettyTableFormatter(BaseFormatter):
return str(table)
def formatBuild(self, data) -> str:
if 'project' in data:
ref = data
else:
ref = data['ref']
output = ''
# This is based on the web UI
output += 'UUID: %s\n' % data.get('uuid', 'N/A')
output += '=' * len('UUID: %s' % data.get('uuid', 'N/A')) + '\n'
output += 'Result: %s\n' % data.get('result', 'N/A')
output += 'Pipeline: %s\n' % data.get('pipeline', 'N/A')
output += 'Project: %s\n' % data.get('project', 'N/A')
output += 'Project: %s\n' % ref.get('project', 'N/A')
output += 'Job: %s\n' % data.get('job_name', 'N/A')
if data.get('newrev'):
output += 'Ref: %s\n' % data.get('ref', 'N/A')
output += 'New Rev: %s\n' % data['newrev']
if data.get('change') and data.get('patchset'):
output += 'Change: %s\n' % (str(data['change']) + ',' +
str(data['patchset']))
output += 'Branch: %s\n' % data.get('branch', 'N/A')
output += 'Ref URL: %s\n' % data.get('ref_url', 'N/A')
if ref.get('newrev'):
output += 'Ref: %s\n' % ref.get('ref', 'N/A')
output += 'New Rev: %s\n' % ref['newrev']
if ref.get('change') and ref.get('patchset'):
output += 'Change: %s\n' % (str(ref['change']) + ',' +
str(ref['patchset']))
output += 'Branch: %s\n' % ref.get('branch', 'N/A')
output += 'Ref URL: %s\n' % ref.get('ref_url', 'N/A')
output += 'Event ID: %s\n' % data.get('event_id', 'N/A')
output += 'Buildset ID: %s\n' % data.get('buildset',
{}).get('uuid', 'N/A')
@ -245,10 +249,14 @@ class PrettyTableFormatter(BaseFormatter):
]
)
for build in data:
if build.get('change') and build.get('patchset'):
change = str(build['change']) + ',' + str(build['patchset'])
if 'project' in build:
ref = build
else:
change = build.get('ref', 'N/A')
ref = build['ref']
if ref.get('change') and ref.get('patchset'):
change = str(ref['change']) + ',' + str(ref['patchset'])
else:
change = ref.get('ref', 'N/A')
start_time = (
build.get('start_time') and
isoparse(build['start_time']) or
@ -257,8 +265,8 @@ class PrettyTableFormatter(BaseFormatter):
table.add_row([
build.get('uuid', 'N/A'),
build.get('job_name', 'N/A'),
build.get('project', 'N/A'),
build.get('branch', 'N/A'),
ref.get('project', 'N/A'),
ref.get('branch', 'N/A'),
build.get('pipeline', 'N/A'),
change,
build.get('duration', 'N/A'),