Commits

Tetsuya Morimoto committed cbadd2b

added to show debug log message
fixed to except own ticket id when it found in comment
added to "cc" to make the new ticket with relationships

Comments (0)

Files changed (4)

         links = None
         desc_refs = get_refs_in_comment(ticket["description"])
         if desc_refs:
+            self.log.debug("TicketRefsPlugin: refs in description %s" % (
+                           str(desc_refs)))
             ticket[TICKETREF] = cnv_sorted_refs(ticket[TICKETREF], desc_refs)
             links = TicketLinks(self.env, ticket)
             links.add_reference(desc_refs)
 
         if self.has_ticket_refs(ticket):
-            self.log.debug("TracTicketReference: ticket are creating")
+            self.log.debug("TicketRefsPlugin: ticket are creating")
             if not links:
                 links = TicketLinks(self.env, ticket)
-            links.create()
+            try:
+                links.create()
+            except Exception, err:
+                self.log.error("TicketRefsPlugin: ticket_created %s" % err)
+            self.log.debug("TicketRefsPlugin: ticket are created")
 
     def ticket_changed(self, ticket, comment, author, old_values):
         links = None
         need_change = TICKETREF in old_values
 
-        com_refs = get_refs_in_comment(comment)
+        com_refs = get_refs_in_comment(comment, [ticket.id])
         if com_refs:
+            self.log.debug("TicketRefsPlugin: refs in comment %s" % (
+                           str(com_refs)))
             links = TicketLinks(self.env, ticket)
             links.add_reference(com_refs)
             need_change = True
 
         if need_change:
-            self.log.debug("TracTicketReference: ticket are changing")
+            self.log.debug("TicketRefsPlugin: ticket are changing")
             if not links:
                 links = TicketLinks(self.env, ticket)
-            links.change(author, old_values.get(TICKETREF))
+            try:
+                links.change(author, old_values.get(TICKETREF))
+            except Exception, err:
+                self.log.error("TicketRefsPlugin: ticket_changed %s" % err)
+            self.log.debug("TicketRefsPlugin: ticket are changed")
 
     def ticket_deleted(self, ticket):
         if self.has_ticket_refs(ticket):
-            self.log.debug("TracTicketReference: ticket are deleting")
+            self.log.debug("TicketRefsPlugin: ticket are deleting")
             links = TicketLinks(self.env, ticket)
-            links.delete()
+            try:
+                links.delete()
+            except Exception, err:
+                self.log.error("TicketRefsPlugin: ticket_deleted %s" % err)
+            self.log.debug("TicketRefsPlugin: ticket are deleted")
 
     # ITicketManipulator methods
     def prepare_ticket(self, req, ticket, fields, actions):

ticketref/model.py

         refs = cnv_text2list(self.ticket[TICKETREF])
         self.add_cross_reference(refs, self.ticket["reporter"])
         self.db.commit()
-        self.env.log.debug("TracTicketReference: cross-refs are created")
 
     def change(self, author, old_refs_text):
         old_refs = cnv_text2list(old_refs_text)
         self.remove_cross_reference(old_refs - new_refs, author)
         self.add_cross_reference(new_refs - old_refs, author)
         self.db.commit()
-        self.env.log.debug("TracTicketReference: cross-refs are updated")
 
     def delete(self):
         refs = cnv_text2list(self.ticket[TICKETREF])
         self.remove_cross_reference(refs, "admin")
         self.db.commit()
-        self.env.log.debug("TracTicketReference: cross-refs are deleted")

ticketref/utils.py

     (?P<ref_text>(ref.*?)\s+(\#\d+[,|\s]*){1,})
 """, re.U | re.M | re.X)
 
-def get_refs_in_comment(comment):
+def get_refs_in_comment(comment, except_ids=None):
     """ pick out reference text and convert text to ids
     >>> get_refs_in_comment(u"refs. #1")
     set([1])
     set([1, 3, 5])
     >>> get_refs_in_comment(u"adding.\\nsecond\\nrefs #2")
     set([2])
+    >>> get_refs_in_comment(u"except ids\\nrefs #1 #3", [3])
+    set([1])
+    >>> get_refs_in_comment(u"except ids\\nrefs #1 #3 #5", [1, 5])
+    set([3])
+    >>> get_refs_in_comment(u"ref. #21", [23])
+    set([21])
+    >>> get_refs_in_comment(u"ref. #21 #22", [23, 24])
+    set([21, 22])
+    >>> get_refs_in_comment(u"ref. #3 #4", [1])
+    set([3, 4])
+    >>> get_refs_in_comment(u"ref. #3 #4", [1, 3])
+    set([4])
     """
     ref_ids = set([])
     match = re.search(_RE_REFS_WITH_IDS, comment)
     if match:
         ref_text = match.groupdict().get("ref_text")
         ref_ids = get_ref_ids_in_comment(ref_text)
+        if except_ids:
+            exc_ids = [i for i in ref_ids if i in except_ids]
+            for id_ in exc_ids:
+                ref_ids.remove(id_)
     return ref_ids
 
 _RE_TICKET_IDS = re.compile(r"(#\d+)", re.U)
     """ return only id numbers with list
     >>> get_ref_ids_in_comment("")
     set([])
+    >>> get_ref_ids_in_comment("text only")
+    set([])
     >>> get_ref_ids_in_comment("#1")
     set([1])
     >>> get_ref_ids_in_comment("refs #1")

ticketref/web_ui.py

 
 COPY_TICKET_FIELDS = [
     "type", "priority", "milestone", "component", "version", "keywords",
-    "owner",
+    "owner", "cc",
 ]
 
 
 
     # ITemplateStreamFilter methods
     def filter_stream(self, req, method, filename, stream, data):
+        self.log.debug("TicketRefsTemplate: filter_stream start")
         if not data or (not filename in TEMPLATE_FILES):
             return stream
 
         if "row_groups" in data and isinstance(data["row_groups"], list):
             self._filter_row_groups(req, data)
 
+        self.log.debug("TicketRefsTemplate: filter_stream end")
         return stream
 
     def _filter_fields(self, req, data):
     def pre_process_request(self, req, handler):
         return handler
 
-    def post_process_request(self, req, template, content_type):
-        return template, content_type
-
     def post_process_request(self, req, template, data, content_type):
-        if template == "ticket.html":
+        self.log.debug("TicketRefsTemplate: post_process_request, %s, %s" % (
+                       req.path_info, template))
+        if req.path_info.startswith("/ticket/"):
             add_stylesheet(req, "ticketref/ticket.css")
             add_script(req, "ticketref/ticket.js")
         return template, data, content_type
 
     # ITemplateProvider methods
     def get_htdocs_dirs(self):
-        """Return the absolute path of a directory containing additional
-        static resources (such as images, style sheets, etc).
-        """
-        return [("ticketref", resource_filename(__name__, "htdocs"))]
+        yield ("ticketref", resource_filename(__name__, "htdocs"))
 
     def get_templates_dirs(self):
-        """Return the absolute path of the directory containing the provided
-        ClearSilver templates.
-        """
-        return [resource_filename(__name__, "templates")]
+        return []