Skip to content

Please support wiki page changes #2

Description

@akorn

Hi,

without completely understanding what I'm doing I was able to make it kinda work for at least wiki page edits like this:

diff --git a/irker_notification/__init__.py b/irker_notification/__init__.py
index e5c4d8b..d6090c7 100644
--- a/irker_notification/__init__.py
+++ b/irker_notification/__init__.py
@@ -5,7 +5,19 @@ from trac.core import *
 from trac.config import Option, IntOption
 from trac.ticket.api import ITicketChangeListener
 #from trac.versioncontrol.api import IRepositoryChangeListener
-#from trac.wiki.api import IWikiChangeListener
+from trac.wiki.api import IWikiChangeListener
+
+def add_environment_info(env, values):
+       """Add infos about the trac to the values dict."""
+       url = env.abs_href()
+       if not url.endswith('/'):
+               url += '/'
+       values['trac'] = {
+               'name':         env.project_name,
+               'description':  env.project_description,
+               'url':          url
+       }
+       return values

 def prepare_ticket_values(ticket, action=None):
        values = ticket.values.copy()
@@ -15,8 +27,27 @@ def prepare_ticket_values(ticket, action=None):
        values['project'] = ticket.env.project_name.encode('utf-8').strip()
        return values

+def prepare_wiki_page_values(page, action=None):
+       """Converts a wiki page object into a dict."""
+       values = add_environment_info(page.env, {
+               'name':         page.name,
+               'id':           page.name,
+               'version':      page.version,
+               'readonly':     page.readonly,
+               'exists':       page.exists,
+               'author':       page.author or '',
+               'comment':      page.comment or '',
+               'summary':      page.comment or '',
+               'url':          page.env.abs_href.wiki(page.name),
+               'project':      page.env.project_name.encode('utf-8').strip()
+       })
+       if action is not None:
+               values['action'] = action
+       return values
+
 class IrkerNotifcationPlugin(Component):
        implements(ITicketChangeListener)
+       implements(IWikiChangeListener)
        host = Option('irker', 'host', 'localhost',
                doc="Host on which the irker daemon resides.")
        port = IntOption('irker', 'port', 6659,
@@ -29,7 +60,7 @@ class IrkerNotifcationPlugin(Component):
                values['author'] = re.sub(r' <.*', '', values['author'])
                #template = '%(project)s/%(branch)s %(rev)s %(author)s: %(logmsg)s'
                #template = '%(project)s %(rev)s %(author)s: %(logmsg)s'
-               template = '%(project)s %(type)s %(id)s %(action)s %(author)s: %(summary)s'
+               template = '%(project)s %(type)s %(id)s %(action)s by %(author)s: %(summary)s [%(url)s]'
                message = template % values
                #message = ' '.join(['%s=%s' % (key, value) for (key, value) in values.items()])
                data = {"to": self.target, "privmsg": message.encode('utf-8').strip() }
@@ -62,7 +93,21 @@ class IrkerNotifcationPlugin(Component):
        def ticket_deleted(self, ticket):
                pass

-       #def wiki_page_added(self, page):
-       #def wiki_page_changed(self, page, version, t, comment, author, ipnr):
-       #def wiki_page_deleted(self, page):
-       #def wiki_page_version_deleted(self, page):
+       def wiki_page_added(self, page):
+               pass
+
+       def wiki_page_changed(self, page, version, t, comment, author, ipnr):
+               self.log.debug('irker: entering wiki_page_changed')
+               action = 'changed'
+               values = prepare_wiki_page_values(page, action)
+               values.update({
+                       'comment':      comment or '',
+                       'last_author':  author or ''
+               })
+               self.notify('wikipage', values)
+
+       def wiki_page_deleted(self, page):
+               pass
+
+       def wiki_page_version_deleted(self, page):
+               pass

Obviously this is a mess, so I'm not submitting a pull request; you'd be out of your mind to pull this code (some of it's been lifted from the old https://trac-hacks.org/svn/ircannouncerplugin, fwiw).

Any chance of a clean solution?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions