Roundup Tracker - Issues

Message6313

Author tekberg
Recipients rouilj, tekberg
Date 2019-01-08.19:50:21
Message-id <1546977022.25.0.591090513211.issue2551018@roundup.psfhosted.org>
In-reply-to
I have been working on an oncall tracker where is it useful for the
nosy email to show specific fields (problem description, page
date/time, call-back phone, etc.) even when they don't change. This
issue describes a modification to the roundup code that allows nosy
wmail to generate a custom body.

The modification involves passing a function as an optional parameter,
calling the function, if non-None, after the email body gets
built. The email body becomes whatever the function returns. The
function can return the original body or replace it with something
else.

The change is to the nosymessage function in roundup/roundupdb.py. The
new note_filter parameter to nosymessage defaults to None. If
note_filter is specified it is assumed to be a function with this
prototype:

            note_filter(original_note, issueid, newvalues, oldvalues)

If called, the note_filter function returns the new value for the
message body.

Example use:

Make a custom change to detectors/nosyreaction.py. In the nosyreaction
function change this line:

            cl.nosymessage(nodeid, msgid, oldvalues)

to something like this:

            cl.nosymessage(nodeid, msgid, oldvalues, 
note_filter=format_oncall_message)

Where format_oncall_message is a new function like this:

def format_oncall_message(original_note, issue_id, newvalues, 
oldvalues):
    """
    Format the message like the lmit_oncall tracker did with nice 
field names.

    Determine if the description changed or if there are new 
Update/Resolution,
    and return detail that should go into the body of the email 
message.
    """

    email_details = []
    new_description = newvalues.get(issue_id, 'description')
    # If this is a new issue and it has a description, or if the issue
    # was edited and the description changed.
    have_new_description = ((oldvalues is None and new_description) or
                            (oldvalues is not None and
                             'description' in oldvalues and
                             (oldvalues.get('description') != 
new_description)))
    new_messages = determineNewMessages(newvalues, issue_id, 
oldvalues)

    # Have new detail. Add the common detail first.
    if have_new_description or new_messages:
        if newvalues.get(issue_id, 'pagedate'):
            email_details.append('Page Date: %s' % 
(newvalues.get(issue_id, 'pagedate').pretty(format='%Y-%m-%d'),))
        if newvalues.get(issue_id, 'pagetime'):
            email_details.append('Page Time: %s' % 
(newvalues.get(issue_id, 'pagetime'),))
        email_details.append('Name: %s' % (newvalues.get(issue_id, 
'username'),))
        source_id = newvalues.get(issue_id, 'source')
        if source_id:
            email_details.append('Source: %s' % 
(db.source.get(source_id, 'name'),))
        location_id = newvalues.get(issue_id, 'location')
        if location_id:
            email_details.append('Location: %s' % 
(db.location.get(location_id, 'name'),))
    if have_new_description:
        email_details.append('Problem Description: %s' % 
(new_description,))

    # Add messages (Update/Resolution) if there are any.
    messages = newvalues.db.msg
    for msgid in new_messages:
        content = messages.get(msgid, 'content', '')
        if content:
            email_details.append('Update/Resolution: %s' % (content,))

    return '\n\n'.join(email_details)


This example of real code stores the lines of the email in
the email_details list. It checks carefully to see if there is a new
description, then adds the contents of several fields, and appends the
nosy meessages. The return joins the lines together to return a
string. [The final version of this code will include additional
fields.]

An example email is attached. Note that the code and the email differ
now, but will match when I finish with this tracker. I redacted where
the email was sent and the person that responded to the email.
History
Date User Action Args
2019-01-08 19:50:23tekbergsetrecipients: + tekberg, rouilj
2019-01-08 19:50:22tekbergsetmessageid: <1546977022.25.0.591090513211.issue2551018@roundup.psfhosted.org>
2019-01-08 19:50:22tekberglinkissue2551018 messages
2019-01-08 19:50:22tekbergcreate