@@ -0,0 +1,2904 @@
+#!/usr/bin/python%0A#%0A# Humbug trac plugin -- sends humbugs when tickets change.%0A#%0A# Install by placing in the plugins/ subdirectory and then adding%0A# %22humbug_trac%22 to the %5Bcomponents%5D section of the conf/trac.ini file,%0A# like so:%0A#%0A# %5Bcomponents%5D%0A# humbug_trac = enabled%0A%0Afrom trac.core import *%0Afrom trac.util.html import html%0Afrom trac.ticket import ITicketChangeListener%0Aimport sys%0A%0Asys.path.append(%22/home/humbug/humbug%22)%0Aimport api.common%0Aclient = api.common.HumbugAPI(email=%22humbug+trac@humbughq.com%22,%0A                              api_key=%22xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%22)%0A%0Adef markdown_ticket_url(ticket, heading=%22ticket%22):%0A    return %22%5B%25s #%25s%5D(https://trac.humbughq.com/ticket/%25s)%22 %25 (heading, ticket.id, ticket.id)%0A%0Adef markdown_block(desc):%0A    return %22%5Cn~~~~%5Cn%25s%5Cn~~~~%5Cn%22 %25 (desc,)%0A%0Adef trac_subject(ticket):%0A    return %22Trac #%25s%22 %25 ticket.id%0A%0Adef send_update(ticket, content):%0A    client.send_message(%7B%0A            %22type%22: %22stream%22,%0A            %22stream%22: %22devel%22,%0A            %22content%22: content,%0A            %22subject%22: trac_subject(ticket)%0A            %7D)%0A%0Aclass HelloWorldPlugin(Component):%0A    implements(ITicketChangeListener)%0A%0A    def ticket_created(self, ticket):%0A        %22%22%22Called when a ticket is created.%22%22%22%0A        content = %22%25s created new %25s in component %25s:%5Cn%25s%22 %25 (ticket.values.get(%22reporter%22),%0A                                                              markdown_ticket_url(ticket),%0A                                                              ticket.values.get(%22component%22),%0A                                                              ticket.values.get(%22summary%22))%0A        if ticket.values.get(%22description%22) != %22%22:%0A            content += %22:%25s%22 %25 markdown_block(ticket.values.get(%22description%22))%0A        send_update(ticket, content)%0A%0A    def ticket_changed(self, ticket, comment, author, old_values):%0A        %22%22%22Called when a ticket is modified.%0A        %0A        %60old_values%60 is a dictionary containing the previous values of the%0A        fields that have changed.%0A        %22%22%22%0A        content = %22%25s updated %25s:%5Cn%5Cn%22 %25 (author, markdown_ticket_url(ticket))%0A        for key in old_values.keys():%0A            if key != %22description%22:%0A                content += '- Changed %25s from %22%25s%22 to %22%25s%22%5Cn' %25 (key, old_values.get(key), %0A                                                                 ticket.values.get(key))%0A            else:%0A                content += '- Changed %25s from %25s to %25s' %25 (key, markdown_block(old_values.get(key)), %0A                                                           markdown_block(ticket.values.get(key)))%0A%0A        if comment:%0A            content += '- Added a comment: %25s' %25 (markdown_block(comment,))%0A        send_update(ticket, content)%0A%0A    def ticket_deleted(self, ticket):%0A        %22%22%22Called when a ticket is deleted.%22%22%22%0A        content = %22%25s was deleted.%22 %25 markdown_ticket_url(ticket, heading=%22Ticket%22)%0A        send_update(ticket, content)%0A

Add Humbug trac plugin.