Ejemplo n.º 1
0
 def addCommentToTicket(self, comment, idTicket):
     db = self.env.get_db_cnx()
     cursor = db.cursor()
     dtComment = parser.parse(comment['date'])
     timestamp = int(time.mktime(dtComment.timetuple())-time.timezone)
     userComment = self.getUserByTrelloId(comment['idMemberCreator'])
     m2w = markdowntowiki.MarkdownToWiki(comment['data']['text']).convert()
     cursor.execute("INSERT INTO ticket_change VALUES ((%s),(%s),(%s),(%s),(%s),(%s))",[idTicket,timestamp,userComment,'comment', '', m2w])
Ejemplo n.º 2
0
    def sendToTracController(self, req):
        #start db
        db = self.env.get_db_cnx()
        cursor = db.cursor()

        data = {}
        boardId = ''
        cardId = ''

        #get trello conf
        apiKey = self.config.get('trello', 'api_key')
        userAuthToken = self.config.get('trello', 'user_auth_token')
        boardList = self.config.getlist('trello', 'boards')

        agileTrac = self.config.getbool('trello', 'agile_trac')
        if agileTrac:
            field_list = TrelloToTracPlugin.__FIELD_AGILE_SINGLE
        else:
            field_list = TrelloToTracPlugin.__FIELD_SINGLE

        estimationTools = self.config.getbool('trello', 'estimationtools')

        #start trello
        trello = trelloclient.TrelloClient(apiKey,userAuthToken)

        #get list of boards
        boards = self.getBoardList(boardList, trello)
        milestones = self.getActiveMilestone()

        if req.method == 'GET':
            error_msg = None
            for field in field_list:
                value = req.args.get(field).strip()
                if len(value) == 0:
                    error_msgmsg = 'You must fill in the field "' + TrelloToTracPlugin.__FIELD_NAMES[field] + '".'
                    break
                # validate cardid exist
                if field == 'board':
                    boardId = value
                # validate cardid exist
                if field == 'card':
                    cardId = value
                # validate milestone exist
                if field == 'milestone':
                    result = self.validateMilestone(value)
                    if not result['res']:
                        error_msg = result['msg']
                        break
                    else:
                        milestone = value
                #validate iteration exist
                if field == 'iteration':
                    result = self.validateIteration(value)
                    if not result['res']:
                        error_msg = result['msg']
                        break
                    else:
                        iteration = value
                    break
            if error_msg:
                response = error_msg
            else:
                #general ticket data
                owner = ''
                version = ''
                severity = 'normale'
                status = 'new'
                resolution = ''
                priority = 'normale'
                keywords = ''
                component = ''
                task = 'task'

                #get board and card info
                board = trelloclient.TrelloBoard(trello, boardId)
                card = trelloclient.TrelloCard(trello,cardId)

                cardContent = {}
                cardInformation = card.getCardInformation()

                #Content
                cardContent['id'] = cardInformation['id']
                cardContent['name'] = cardInformation['name']
                cardContent['url'] = cardInformation['url']

                if (self.ticketCardExist(cardContent['id'])):
                    error_msg = 'Card "%s" already exists'% cardContent['name']
                else:
                    #size and name/title
                    if estimationTools:
                        resultSize = self.getSizeByName(cardInformation['name'])
                        size = resultSize['size']
                        cardContent['name'] = resultSize['name']

                    createCard = card.getCreateCard()

                    #date
                    dt = parser.parse(createCard['actions'][0]['date'])
                    cardContent['timestamp'] = int(time.mktime(dt.timetuple())-time.timezone)

                    #add link to card
                    cardContent['desc'] = '\'\'\'Card Link:\'\'\'[[br]]\n[' + cardContent['url'] + ' vai a Trello] [[br]] \n'
                    #covert desc markdown to trac wiki
                    m2w = markdowntowiki.MarkdownToWiki(cardInformation['desc'])
                    cardContent['desc'] += '[[br]]\'\'\'Description:\'\'\'[[br]]\n'+m2w.convert() + ' [[br]] \n'

                    idMemberCreator = createCard['actions'][0]['idMemberCreator']
                    reporter = self.getUserByTrelloId(idMemberCreator)
                    if reporter is None:
                        reporter = 'trello'
                    members=card.getMembers()

                    # owner
                    owner = self.getFirstMember(members)

                    # cc alla assigned member
                    cc = self.addMembersToCc(members)

                    # checklist
                    checklists = card.getChecklists()
                    cardContent['desc'] = self.addChecklistsToDesc(checklists, cardContent['desc'], trello)

                    # import attachments
                    attachments = card.getAttachments()
                    cardContent['desc'] = self.addAttachmentsToDesc(attachments, cardContent['desc'])

                    # labels
                    labels = cardInformation['labels']
                    cardContent['desc'] = self.addLabelsToDesc(labels, cardContent['desc'])

                    # insert card in ticket
                    try:
                        # id, type, time, changetime, component, severity, priority, owner, reporter, cc, version, milestone, status, resolution, summary, description, keywords
                        cursor.execute("INSERT INTO ticket (id, type, time, changetime, component, severity, priority, owner, reporter, cc, version, milestone, status, resolution, summary, description, keywords) VALUES (DEFAULT, (%s),(%s),(%s),(%s),(%s),(%s),(%s),(%s),(%s),(%s),(%s),(%s),(%s),(%s),(%s),(%s)) RETURNING id;",[ task, cardContent['timestamp'], cardContent['timestamp'], component , severity, priority, owner, reporter, cc, version, milestone, status, resolution, cardContent['name'], cardContent['desc'], keywords ])
                        idTicket = cursor.fetchone()[0]
                        # comment
                        comments = card.getComments()
                        self.addCommentsToTicket(comments, idTicket)

                        # Attach link to card on trello
                        card.addLinkAttachment(self.getLinkByTicketId(idTicket))
                        # add trellocard id on ticket custom fields
                        self.addTrellocardToTicket(idTicket, cardContent['id'])

                        # add ticket to iteration
                        if agileTrac:
                            self.addTicketToIteration(idTicket,iteration)
                        # add size
                        if estimationTools:
                            estimationToolsField = self.config.get('estimation-tools', 'estimation_field')
                            self.addSizeToTicket(size, estimationToolsField, idTicket, cardContent['timestamp'], reporter)

                    except:
                        db.rollback()
                        raise
                    db.commit()

                    notice_msg='Added card "%s" with id: %s' % (cardContent['name'], idTicket);
                    response = notice_msg

                if error_msg:
                    response = error_msg

        req.send_response(200)
        req.send_header('Content-Type', 'application/json')
        req.send_header('Content-Length', len(response))
        req.end_headers()
        req.write(response)
Ejemplo n.º 3
0
    def indexController(self, req):
        #start db
        db = self.env.get_db_cnx()
        cursor = db.cursor()

        data = {}
        boardId = ''
        listId = ''

        #get trello conf
        apiKey = self.config.get('trello', 'api_key')
        userAuthToken = self.config.get('trello', 'user_auth_token')
        boardList = self.config.getlist('trello', 'boards')
        listList = self.config.getlist('trello', 'lists')

        agileTrac = self.config.getbool('trello', 'agile_trac')
        if agileTrac:
            field_list = TrelloToTracPlugin.__FIELD_AGILE
        else:
            field_list = TrelloToTracPlugin.__FIELD

        estimationTools = self.config.getbool('trello', 'estimationtools')

        #start trello
        trello = trelloclient.TrelloClient(apiKey,userAuthToken)

        #get board,list,milestone lists
        boards = self.getBoardList(boardList, trello)
        lists = self.getListList(listList, trello)
        milestones = self.getActiveMilestone()

        if req.method == 'POST':
            error_msg = None
            for field in field_list:
                value = req.args.get(field).strip()
                if len(value) == 0:
                    error_msg = 'You must fill in the field "' + TrelloToTracPlugin.__FIELD_NAMES[field] + '".'
                    break
                #validate board exist
                if field == 'board':
                    result = self.validateBoardId(value, trello)
                    if not result['res']:
                        error_msg = result['msg']
                        break
                    else:
                        boardId = value
                #validate list exist
                if field == 'thelist':
                    result = self.validateListId(value, trello)
                    if not result['res']:
                        error_msg = result['msg']
                        break
                    else:
                        listId = value
                #validate milestone exist
                if field == 'milestone':
                    result = self.validateMilestone(value)
                    if not result['res']:
                        error_msg = result['msg']
                        break
                    else:
                        milestone = value
                #validate iteration exist
                if field == 'iteration':
                    result = self.validateIteration(value)
                    if not result['res']:
                        error_msg = result['msg']
                        break
                    else:
                        iteration = value
                    break
            if error_msg:
                add_warning(req, error_msg)
                data = req.args
            else:
                #general ticket data
                owner = ''
                version = ''
                severity = 'normale'
                status = 'new'
                resolution = ''
                priority = 'normale'
                keywords = ''
                component = ''
                task = 'task'

                board = trelloclient.TrelloBoard(trello, boardId)
                theList = trelloclient.TrelloList(trello, listId)
                boardInformation = board.getBoardInformation()
                listInformation = theList.getListInformation()

                cards = theList.getCards()
                for c in cards:
                    cardContent = {}
                    cardInformation = c.getCardInformation()

                    #Content
                    cardContent['id'] = cardInformation['id']
                    cardContent['name'] = cardInformation['name']
                    cardContent['url'] = cardInformation['url']

                    if (self.ticketCardExist(cardContent['id'])):
                        error_msg = 'Card "%s" already exists'% cardContent['name']
                    else:
                        #size and name/title
                        if estimationTools:
                            resultSize = self.getSizeByName(cardInformation['name'])
                            size = resultSize['size']
                            cardContent['name'] = resultSize['name']

                        cardId = cardInformation['id']
                        card = trelloclient.TrelloCard(trello, cardId)
                        createCard = card.getCreateCard()

                        #date
                        dt = parser.parse(createCard['actions'][0]['date'])
                        cardContent['timestamp'] = int(time.mktime(dt.timetuple())-time.timezone)


                        #add link to card
                        cardContent['desc'] = '\'\'\'Card Link:\'\'\'[[br]]\n[' + cardContent['url'] + ' vai a Trello] [[br]] \n'
                        #covert desc markdown to trac wiki
                        m2w = markdowntowiki.MarkdownToWiki(cardInformation['desc'])
                        cardContent['desc'] += '[[br]]\'\'\'Description:\'\'\'[[br]]\n'+m2w.convert() + ' [[br]] \n'

                        idMemberCreator = createCard['actions'][0]['idMemberCreator']
                        reporter = self.getUserByTrelloId(idMemberCreator)
                        if reporter is None:
                            reporter = 'trello'
                        members=card.getMembers()

                        # owner
                        owner = self.getFirstMember(members)

                        #cc alla assigned member
                        cc = self.addMembersToCc(members)

                        #checklist
                        checklists = card.getChecklists()
                        cardContent['desc'] = self.addChecklistsToDesc(checklists, cardContent['desc'], trello)

                        #import attachments
                        attachments = card.getAttachments()
                        cardContent['desc'] = self.addAttachmentsToDesc(attachments, cardContent['desc'])

                        #labels
                        labels = cardInformation['labels']
                        cardContent['desc'] = self.addLabelsToDesc(labels, cardContent['desc'])

                        #insert card in ticket
                        try:
                            #id, type, time, changetime, component, severity, priority, owner, reporter, cc, version, milestone, status, resolution, summary, description, keywords
                            cursor.execute("INSERT INTO ticket (id, type, time, changetime, component, severity, priority, owner, reporter, cc, version, milestone, status, resolution, summary, description, keywords) VALUES (DEFAULT, (%s),(%s),(%s),(%s),(%s),(%s),(%s),(%s),(%s),(%s),(%s),(%s),(%s),(%s),(%s),(%s)) RETURNING id;",[ task, cardContent['timestamp'], cardContent['timestamp'], component , severity, priority, owner, reporter, cc, version, milestone, status, resolution, cardContent['name'], cardContent['desc'], keywords ])
                            idTicket = cursor.fetchone()[0]
                            #comment
                            comments = card.getComments()
                            self.addCommentsToTicket(comments, idTicket)

                            # Attach link to card on trello
                            card.addLinkAttachment(self.getLinkByTicketId(idTicket))
                            # add trellocard id on ticket custom fields
                            self.addTrellocardToTicket(idTicket, cardContent['id'])

                            #add ticket to iteration
                            if agileTrac:
                                self.addTicketToIteration(idTicket,iteration)

                            #add size
                            if estimationTools:
                                estimationToolsField = self.config.get('estimation-tools', 'estimation_field')
                                self.addSizeToTicket(size, estimationToolsField, idTicket, cardContent['timestamp'], reporter)

                        except:
                            db.rollback()
                            raise
                        db.commit()

                        notice_msg='Added card "%s" with id: %s' % (cardContent['name'], idTicket);
                        add_notice(req, notice_msg)

                    if error_msg:
                        add_warning(req, error_msg)
                        error_msg = ''
                data = req.args

        #forever view data
        data['milestone_placeholder'] = 'milestone name'
        data['iteration_placeholder'] = 'iteration number'
        data['agile_trac'] = agileTrac
        data['boards'] = boards
        data['lists'] = lists
        data['milestones'] = milestones
        add_stylesheet(req, 'trello/css/trello.css')

        # This tuple is for Genshi (template_name, data, content_type)
        # Without data the trac layout will not appear.
        return 'trello.html', data, None