Last active
August 31, 2024 19:49
-
-
Save nico-i/3dac35782eeefea43194e197e9522f0a to your computer and use it in GitHub Desktop.
This script converts an Azure DevOps export csv file to a csv file that can be imported into Trello with "Import to Trello by Blue Cat (CSV, Excel)"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
# export method I used: https://debug.to/6112/export-work-items-in-azure-devops | |
class AzureItem: | |
# Item ID,Board Column,Parent ID,Work Item Type,Title,Description,Assigned To,State,Tags | |
item_id = '' | |
board_column = '' | |
parent_id = '' | |
work_item_type = '' | |
title = '' | |
description = '' | |
assigned_to = '' | |
state = '' | |
tags = '' | |
def __init__(self, item_id, board_column, parent_id, work_item_type, title, description, assigned_to, state, tags): | |
self.item_id = item_id | |
self.board_column = board_column | |
self.parent_id = parent_id | |
self.work_item_type = work_item_type | |
self.title = title | |
self.description = description | |
self.assigned_to = assigned_to | |
self.state = state | |
self.tags = tags | |
class TrelloItem: | |
# Card Name,Card Description,Labels,Members,Due Date,Start Date,List Name,Checklist,Checklist item,Checklist item due,Checklist item member | |
card_name = '' | |
card_description = '' | |
labels = '' | |
members = '' | |
due_date = '' | |
start_date = '' | |
list_name = '' | |
checklist = '' | |
checklist_item = '' | |
checklist_item_due = '' | |
checklist_item_member = '' | |
def __init__(self, card_name, card_description, labels, members, due_date, start_date, list_name, checklist, checklist_item, checklist_item_due, checklist_item_member): | |
# perform preprocessing on these fields as necessary | |
self.members = members | |
self.checklist_item_member = checklist_item_member | |
self.card_name = card_name | |
self.card_description = card_description | |
self.labels = labels | |
self.due_date = due_date | |
self.start_date = start_date | |
self.list_name = list_name | |
self.checklist = checklist | |
self.checklist_item = checklist_item | |
self.checklist_item_due = checklist_item_due | |
def __repr__(self): | |
return f'{self.card_name}, {self.card_description}, {self.labels}, {self.members}, {self.due_date}, {self.start_date}, {self.list_name}, {self.checklist}, {self.checklist_item}, {self.checklist_item_due}, {self.checklist_item_member}' | |
azure_items = [] | |
# read azure export csv file | |
input_file_name = 'data_in.csv' | |
with open(input_file_name, encoding="utf8") as csv_file: | |
csv_reader = csv.reader(csv_file, delimiter=',') | |
line_count = 0 | |
for row in csv_reader: | |
if line_count == 0: | |
print(f'Column names are {", ".join(row)}') | |
line_count += 1 | |
else: | |
# The rows of your csv may be different than the ones I used | |
if row[3] != 'Feature': | |
azure_items.append(AzureItem( | |
row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8])) | |
line_count += 1 | |
print(f'Processed {line_count} lines.') | |
trello_items = [] | |
counter = 0 | |
# convert azure_items to trello_items | |
for item in azure_items: | |
if item.work_item_type == 'User Story': | |
trello_items.append(TrelloItem( | |
item.title, item.description, item.tags, item.assigned_to, '', '', item.board_column, '', '', '', '')) | |
elif item.work_item_type == 'Task': | |
trello_items.append(TrelloItem( | |
'', '', '', '', '', '', '', 'Checklist', item.title, '', item.assigned_to)) | |
print(trello_items[counter]) | |
counter += 1 | |
# write trello_items to csv file | |
output_file_name = 'data_out.csv' | |
with open(output_file_name, 'w', newline='', encoding="utf8") as csvfile: | |
fieldnames = [ | |
'Card Name', 'Card Description', 'Labels', 'Members', 'Due Date', 'Start Date', 'List Name', 'Checklist', 'Checklist item', 'Checklist item due', 'Checklist item member'] | |
writer = csv.DictWriter(csvfile, fieldnames=fieldnames) | |
writer.writeheader() | |
for item in trello_items: | |
writer.writerow({'Card Name': item.card_name, 'Card Description': item.card_description, 'Labels': item.labels, 'Members': item.members, 'Due Date': item.due_date, 'Start Date': item.start_date, | |
'List Name': item.list_name, 'Checklist': item.checklist, 'Checklist item': item.checklist_item, 'Checklist item due': item.checklist_item_due, 'Checklist item member': item.checklist_item_member}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment