python 将任务从todolist * .tdl文件导入YouTrack.Support功能和任务。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 将任务从todolist * .tdl文件导入YouTrack.Support功能和任务。相关的知识,希望对你有一定的参考价值。

import xml.etree.ElementTree as ET
from youtrack.connection import Connection


class Task(object):
    def __init__(self, title, description):
        self.title = title.encode('utf-8')
        self.description = description.encode('utf-8')
        self.feature = False
        self.sub_tasks = []
        self.parent = None
        self.issue_id = None

    def add_sub(self, task):
        task.parent = self
        self.sub_tasks.append(task)

    def __repr__(self):
        return self.title

    @staticmethod
    def create_from_xml(task_el):
        title = task_el.get('TITLE')
        comment = task_el.find('COMMENTS')
        task = Task(title, comment.text if comment is not None else '')

        for sub in task_el.findall('TASK'):
            task.feature = True
            sub_task = Task.create_from_xml(sub) # recursion
            task.add_sub(sub_task)

        return task

    @staticmethod
    def parse_todolist_exported(filename):
        result = []

        tree = ET.parse(filename)
        for task_el in tree.getroot():
            task = Task.create_from_xml(task_el)
            result.append(task)

        return result

    def _extract_id(self, result):
        index = result.rfind('/')
        return result[index + 1:]

    def save(self, connection, project, assignee, iteration):
        print 'save %s' % self.title

        issue_type = 'feature' if self.feature else 'task'

        create_result = connection.createIssue(project, assignee, self.title, self.description, type=issue_type)
        self.issue_id = self._extract_id(create_result)
        connection.executeCommand(self.issue_id, 'Fix versions ' + iteration)

        if self.parent:
            connection.importLinks([dict(
                typeName='Subtask',
                source=self.parent.issue_id,
                target=self.issue_id
            )])

        for sub_task in self.sub_tasks:
            sub_task.save(connection, project, assignee, iteration)


tasks = Task.parse_todolist_exported('todolist.tdl')

connection = Connection('http://example.com/youtrack/', 'user', 'password')

for task in tasks:
    task.save(connection, 'project', 'assignee', 'iteration (sprint)')

以上是关于python 将任务从todolist * .tdl文件导入YouTrack.Support功能和任务。的主要内容,如果未能解决你的问题,请参考以下文章

vue学习笔记のtodolist的实现

小黄条:能嵌入桌面的跨平台todolist

小黄条:能嵌入桌面的跨平台todolist

todolist要分开写吗

开发“todolist“”项目及其自己的感悟

当下拉列表中的“选择”更改时,按 ID 填充表 TD