21 Jul 2011 zanee   » (Journeyer)

Issue Department Detector for Roundup

Could find no samples for immediate team/department email on issue creation for Roundup. There used to be one that was shipped with it but that code is broken. Anyway, I needed it so I had to waste my morning writing it. The roundup api is a bit hairy but this example is simple. You’ll need to modify your tracker schema and it will send an email on creation of a ticket or issue to a specific department or team address. Obviously if you change the order or mapping you’ll need to update that in the detector code. Cheers!

  # Copyright (c) 2011 Christopher Warner - cwarner@kernelcode.com (http://cwarner.kernelcode.com)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
#   The above copyright notice and this permission notice shall be included in
#   all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
from roundup.anypy.sets_ import set
from roundup import roundupdb, hyperdb

def deptissue(db, cl, nodeid, oldvalues):

    # get all message info
    create = cl.generateCreateNote(nodeid)
    dept_id = cl.get(nodeid, 'department')
    print dept_id

    ''' BUILDING DEPARTMENT '''
    # You have to know the id mapping
    #  technically we could find this

    if dept_id == '1':
        for msgid in cl.get(nodeid, 'messages'):
            try:
                print "Alerting Building Engineering Department"
                cl.send_message(nodeid, msgid, create, ['christopher.warner@drms.dla.mil'])
            except roundupdb.MessageSendError, message:
                raise roundupdb.DetectorError, message

    elif dept_id == '2':
        for msgid in cl.get(nodeid, 'messages'):
            try:
                print "Alerting Technology Department"
                cl.send_message(nodeid, msgid, create, ['Technology EMAIL ADDRESS HERE'])
            except roundupdb.MessageSendError, message:
                raise roundupdb.DetectorError, message

    elif dept_id == '3':
        for msgid in cl.get(nodeid, 'messages'):
            try:
                print "Alerting Research Department"
                cl.send_message(nodeid, msgid, create, ['RESEARCH EMAIL ADDRESS HERE'])
            except roundupdb.MessageSendError, message:
                raise roundupdb.DetectorError, message
    else:
        print "Department doesn't exist"
        pass

def init(db):
    # check on create of ticket
    db.issue.react('create', deptissue)


Share/Bookmark

Syndicated 2011-07-21 17:19:48 from Christopher Warner » Advogato

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!