humbug_trac: Try to compress the rest of the changes.

(imported from commit a7bdf3cb8243d43837705d4c9eb00d5e6d75d4b5)
This commit is contained in:
Tim Abbott 2012-10-31 11:49:42 -04:00
parent a75348cb71
commit 1fc6248725

View file

@ -50,12 +50,11 @@ class HumbugPlugin(Component):
def ticket_created(self, ticket): def ticket_created(self, ticket):
"""Called when a ticket is created.""" """Called when a ticket is created."""
content = "%s created new %s in component %s:\n%s" % (ticket.values.get("reporter"), content = "%s created %s in component **%s**, priority **%s**:\n" % \
markdown_ticket_url(ticket), (ticket.values.get("reporter"), markdown_ticket_url(ticket),
ticket.values.get("component"), ticket.values.get("component"), ticket.values.get("priority"))
ticket.values.get("summary"))
if ticket.values.get("description") != "": if ticket.values.get("description") != "":
content += ":%s" % markdown_block(ticket.values.get("description")) content += "%s" % markdown_block(ticket.values.get("description"))
send_update(ticket, content) send_update(ticket, content)
def ticket_changed(self, ticket, comment, author, old_values): def ticket_changed(self, ticket, comment, author, old_values):
@ -64,23 +63,25 @@ class HumbugPlugin(Component):
`old_values` is a dictionary containing the previous values of the `old_values` is a dictionary containing the previous values of the
fields that have changed. fields that have changed.
""" """
content = "%s updated %s:\n\n" % (author, markdown_ticket_url(ticket)) content = "%s updated %s" % (author, markdown_ticket_url(ticket))
if "summary" not in old_values: if comment:
content += "(%s)\n" % (ticket.values.get("summary"),) content += ' with comment: %s\n\n' % (markdown_block(comment,))
else:
content += ":\n\n"
field_changes = []
for key in old_values.keys(): for key in old_values.keys():
if key == "description": if key == "description":
content += '- Changed %s from %s to %s' % (key, markdown_block(old_values.get(key)), content += '- Changed %s from %s to %s' % (key, markdown_block(old_values.get(key)),
markdown_block(ticket.values.get(key))) markdown_block(ticket.values.get(key)))
elif old_values.get(key) == "": elif old_values.get(key) == "":
content += '- Added %s **%s**\n' % (key, ticket.values.get(key)) field_changes.append('%s: => **%s**' % (key, ticket.values.get(key)))
elif ticket.values.get(key) == "": elif ticket.values.get(key) == "":
content += '- Remove %s **%s**\n' % (key, old_values.get(key)) field_changes.append('%s: **%s** => ""' % (key, old_values.get(key)))
else: else:
content += '- Changed %s from **%s** to **%s**\n' % (key, old_values.get(key), field_changes.append('%s: **%s** => **%s**' % (key, old_values.get(key),
ticket.values.get(key)) ticket.values.get(key)))
content += ", ".join(field_changes)
if comment:
content += '- Added a comment: %s' % (markdown_block(comment,))
send_update(ticket, content) send_update(ticket, content)
def ticket_deleted(self, ticket): def ticket_deleted(self, ticket):