def _create_or_update_ticket(self, runid, testaction, comment, req): """ creates or updates a ticket for an action (default ticket type if failed, enhancement if otherwise (e.g. passed with comment)) update means add a comment to the already created ticket and add keyword if neccesary """ self.dbg('accordion.request._create_or_update_ticket(%s)' % req.args) testrun = Ticket(self.env, tkt_id=runid) display = get_display_states(self.env) # build ticket summary: <todo>: <action> of <testcase>, e.g.: # 'Creator checks in the model of TcCaddocCreate failed.' todo = STATES_DISPLAY[testaction.status] testcase = models.TestCaseQuery(self.env, tcid=testaction.tcid).execute()[0] summary = "%s of %s %s." % ( testaction.title, testcase.wiki, display[todo]) # build description description = "Related test case: %s.\n\n%s" % ( self._build_tc_link(testaction, req), comment ) # check if a similar ticket already exists... existing_tickets = Query.from_string( self.env, "summary=%s" % summary ).execute() if existing_tickets: # if yes return the ticket id t = Ticket(self.env, existing_tickets[0]['id']) tp_title = self._get_testplan_title(testrun) if t['keywords']: kws = t['keywords'].split(',') if not tp_title in kws: t['keywords'] += ',%s' % tp_title else: t['keywords'] = tp_title t.save_changes(author=req.authname, comment=description) return t.id # build the ticket ticket = Ticket(self.env) # determine type of ticket ticket_type = ticket.get_default('type') if testaction.status != FAILED: ticket_type = 'enhancement' data = { 'reporter': req.authname, 'summary': summary, 'type': ticket_type, 'description': description, 'priority': req.args.get('priority', 'major'), 'status': 'new', 'keywords': self._get_testplan_title(testrun), } self.dbg('ticket data: %s' % data) try: ticket.populate(data) tid = ticket.insert() ticket.save_changes() except TracError as e: self.env.log.error(e) raise TracError( safe_unicode( "ticket could not be created: %s" % e.message ) ) return tid