1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
|
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
from collections import OrderedDict
_WORK_ITEM_TITLE_TRUNCATION_LENGTH = 70
_PATH_TRUNCATION_LENGTH = 50
def transform_work_item_relation_type_table_output(result):
table_output = []
for item in result:
table_row = OrderedDict()
table_row['Name'] = item['name']
table_row['ReferenceName'] = item['referenceName']
table_row['Enabled'] = item['attributes']['enabled']
table_row['Usage'] = item['attributes']['usage']
table_output.append(table_row)
return table_output
def transform_work_item_relations(result):
if result['relations'] is None:
return []
relations = result['relations']
table_output = []
for item in relations:
table_row = OrderedDict()
table_row['Relation Type'] = item['rel']
table_row['Url'] = item['url']
table_output.append(table_row)
return table_output
def transform_work_items_table_output(result):
table_output = []
for item in result:
table_output.append(_transform_work_items_row(item))
return table_output
def transform_work_item_table_output(result):
table_output = [_transform_work_items_row(result)]
return table_output
def _transform_work_items_row(row):
table_row = OrderedDict()
table_row['ID'] = row['id']
if 'fields' in row:
if 'System.WorkItemType' in row['fields']:
table_row['Type'] = row['fields']['System.WorkItemType']
else:
table_row['Type'] = ' '
if 'System.Title' in row['fields']:
title = row['fields']['System.Title']
if len(title) > _WORK_ITEM_TITLE_TRUNCATION_LENGTH:
title = title[0:_WORK_ITEM_TITLE_TRUNCATION_LENGTH - 3] + '...'
table_row['Title'] = title
else:
table_row['Title'] = ' '
if 'System.AssignedTo' in row['fields']:
table_row['Assigned To'] = row['fields']['System.AssignedTo']['uniqueName']
else:
table_row['Assigned To'] = ' '
if 'System.State' in row['fields']:
table_row['State'] = row['fields']['System.State']
else:
table_row['State'] = ' '
else:
table_row['Type'] = ' '
table_row['Title'] = ' '
table_row['Assigned To'] = ' '
table_row['State'] = ' '
return table_row
def transform_work_item_query_result_table_output(result):
table_output = []
for item in result:
if 'fields' in item:
table_output.append(transform_work_item_query_result_row_output(item['fields']))
return table_output
def transform_work_item_query_result_row_output(row):
from azext_devops.dev.boards.work_item import get_last_query_result
table_row = OrderedDict()
max_columns = 5
i = 0
for field_reference in get_last_query_result().columns:
if field_reference.reference_name in row:
if row[field_reference.reference_name] == 0:
# knack hides column values that are equal to numeric 0.
table_row[field_reference.name] = '0'
else:
if field_reference.reference_name == 'System.Title':
title = row[field_reference.reference_name]
if len(title) > _WORK_ITEM_TITLE_TRUNCATION_LENGTH:
title = title[0:_WORK_ITEM_TITLE_TRUNCATION_LENGTH - 3] + '...'
table_row[field_reference.name] = title
elif field_reference.reference_name == 'System.AssignedTo':
table_row[field_reference.name] = row[field_reference.reference_name]['uniqueName']
else:
table_row[field_reference.name] = row[field_reference.reference_name]
else:
table_row[field_reference.name] = ' '
i += 1
if i >= max_columns:
# limit number of columns in table view
break
return table_row
def transform_work_item_team_iterations_table_output(result):
table_output = []
for item in sorted(result, key=_get_team_iteration_key):
table_output.append(_transform_team_iteration_row(item))
return table_output
def transform_work_item_team_iteration_table_output(result):
table_output = [_transform_team_iteration_row(result)]
return table_output
def _transform_team_iteration_row(row):
table_row = OrderedDict()
table_row['ID'] = row['id']
table_row['Name'] = row['name']
if row['attributes']:
if row['attributes']['startDate'] is None:
table_row['Start Date'] = ''
else:
table_row['Start Date'] = row['attributes']['startDate']
if row['attributes']['finishDate'] is None:
table_row['Finish Date'] = ''
else:
table_row['Finish Date'] = row['attributes']['finishDate']
if 'timeFrame' in row['attributes']:
table_row['Time Frame'] = row['attributes']['timeFrame']
table_row['Path'] = row['path']
return table_row
def transform_work_item_team_iteration_work_items(result):
table_output = []
for item in result['workItemRelations']:
table_output.append(_transform_team_iteration_work_item_row(item))
return table_output
def _transform_team_iteration_work_item_row(row):
table_row = OrderedDict()
if row['source']:
table_row['Source'] = row['source']['id']
if row['target']:
table_row['Target'] = row['target']['id']
table_row['Relation Type'] = row['rel']
return table_row
def transform_work_item_team_default_iteration_table_output(result):
table_output = []
table_row = OrderedDict()
if result['defaultIteration']:
table_row = _transform_team_iteration_row(result['defaultIteration'])
table_row['Default Iteration Macro'] = result['defaultIterationMacro']
table_output.append(table_row)
return table_output
def transform_work_item_team_backlog_iteration_table_output(result):
table_output = []
table_output.append(_transform_team_iteration_row(result['backlogIteration']))
return table_output
def transform_work_item_project_classification_nodes_table_output(response):
table_op = []
table_op = transform_work_item_project_classification_nodes_table_output_recursive(response, table_op)
return table_op
def transform_work_item_project_classification_nodes_table_output_recursive(result, table_output):
table_output.append(_transform_project_classification_node_row(result))
if result['children']:
for item in result['children']:
table_output = transform_work_item_project_classification_nodes_table_output_recursive(item, table_output)
return table_output
def transform_work_item_project_classification_node_table_output(result):
table_output = [_transform_project_classification_node_row(result[0])]
return table_output
def _transform_project_classification_node_row(row):
table_row = OrderedDict()
table_row['ID'] = row['id']
table_row['Identifier'] = row['identifier']
table_row['Name'] = row['name']
if row['attributes']:
table_row['Start Date'] = row['attributes']['startDate']
table_row['Finish Date'] = row['attributes']['finishDate']
path = row['path']
if len(path) > _PATH_TRUNCATION_LENGTH:
path = path[0:_PATH_TRUNCATION_LENGTH - 3] + '...'
table_row['Path'] = path
table_row['Has Children'] = row['hasChildren']
return table_row
def transform_work_item_team_areas_table_output(result):
table_output = []
for item in sorted(result['values'], key=_get_team_area_key):
table_output.append(_transform_work_item_team_area_row(item, default_area_path=result['defaultValue']))
return table_output
def _transform_work_item_team_area_row(row, default_area_path):
table_row = OrderedDict()
table_row['Area'] = row['value']
table_row['Include sub areas'] = row['includeChildren']
if row['value'] == default_area_path:
table_row['Is Default'] = True
else:
table_row['Is Default'] = False
return table_row
def _get_team_iteration_key(team_iteration_row):
return team_iteration_row['name'].lower()
def _get_team_area_key(team_area_row):
return team_area_row['value'].lower()
|