<commit_before># This file is part of fedmsg.
# Copyright (C) 2012 Red Hat, Inc.
#
# fedmsg is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# fedmsg is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with fedmsg; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Authors:  <NAME> <<EMAIL>>
#
from fedmsg_meta_fedora_infrastructure import BaseProcessor
from fasshim import gravatar_url


class TracProcessor(BaseProcessor):
    __name__ = "Trac"
    __description__ = "events from select Fedora Hosted projects"
    __link__ = "https://fedorahosted.org"
    __docs__ = "https://fedorahosted.org/readme"
    __obj__ = "Fedora Hosted Events"
    __icon__ = "http://www.edgewall.org/gfx/trac_bullet.png"

    def subtitle(self, msg, **config):
        if 'page' in msg['msg']:
            old_name = None
            user = msg['msg']['agent']
            name = msg['msg']['page']['name']
            project = msg['msg']['instance']['project_name']
            print msg['topic']
            if 'page.version.delete' in msg['topic']:
                tmpl = self._(
                    "{user} deleted a version of the '{name}' wiki "
                    "page on the {project} trac instance")
            elif 'page.delete' in msg['topic']:
                tmpl = self._(
                    "{user} straight-up deleted the '{name}' wiki "
                    "page on the {project} trac instance")
            elif 'page.rename' in msg['topic']:
                old_name = msg['msg']['old_name']
                tmpl = self._(
                    "{user} renamed the wiki page '{old_name}' to '{name}' "
                    "on the {project} trac instance")
            elif 'page.update' in msg['topic']:
                tmpl = self._(
                    "{user} updated the '{name}' wiki page "
                    "on the {project} trac instance")
            elif 'page.new' in msg['topic']:
                tmpl = self._(
                    "{user} created a new '{name}' wiki page "
                    "on the {project} trac instance")

            return tmpl.format(
                user=user,
                name=name,
                old_name=old_name,
                project=project)
        elif 'ticket' in msg['msg']:
            status = None
            resolution = None
            user = msg['msg']['agent']
            project = msg['msg']['instance']['project_name']
            if 'ticket.delete' in msg['topic']:
                tmpl = self._(
                    "{user} straight-up deleted a ticket "
                    "on the {project} trac instance")
            elif 'ticket.new' in msg['topic']:
                tmpl = self._(
                    "{user} opened a new ticket "
                    "on the {project} trac instance")
            elif 'ticket.update' in msg['topic']:
                tmpl = self._(
                    "{user} updated a ticket "
                    "on the {project} trac instance")
                status = msg['msg']['ticket']['status']
                if status == 'reopened':
                    tmpl = self._(
                        "{user} reopened a ticket "
                        "on the {project} trac instance")
                elif status == 'closed':
                    resolution = msg['msg']['ticket']['resolution']
                    tmpl = self._(
                        "{user} closed a ticket "
                        "on the {project} trac instance "
                        "as '{resolution}'")

            return tmpl.format(
                user=user,
                project=project,
                status=status,
                resolution=resolution,
            )
        elif 'git.receive' in msg['topic']:
            user = msg['msg']['commit']['username']
            project = msg['msg']['commit']['repo']
            tmpl = self._(
                "{user} pushed some commits to the '{project}' "
                "fedorahosted git repository")

            return tmpl.format(user=user, project=project)

    def secondary_icon(self, msg, **config):
        user = None

        try:
            user = msg['msg']['agent']
        except KeyError:
            pass

        try:
            user = msg['msg']['commit']['username']<commit_msg>Don't declare tickets open or closed unless the status has actually changed.<commit_after># This file is part of fedmsg.
# Copyright (C) 2012 Red Hat, Inc.
#
# fedmsg is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# fedmsg is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with fedmsg; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Authors:  <NAME> <<EMAIL>>
#
from fedmsg_meta_fedora_infrastructure import BaseProcessor
from fasshim import gravatar_url


class TracProcessor(BaseProcessor):
    __name__ = "Trac"
    __description__ = "events from select Fedora Hosted projects"
    __link__ = "https://fedorahosted.org"
    __docs__ = "https://fedorahosted.org/readme"
    __obj__ = "Fedora Hosted Events"
    __icon__ = "http://www.edgewall.org/gfx/trac_bullet.png"

    def subtitle(self, msg, **config):
        if 'page' in msg['msg']:
            old_name = None
            user = msg['msg']['agent']
            name = msg['msg']['page']['name']
            project = msg['msg']['instance']['project_name']
            print msg['topic']
            if 'page.version.delete' in msg['topic']:
                tmpl = self._(
                    "{user} deleted a version of the '{name}' wiki "
                    "page on the {project} trac instance")
            elif 'page.delete' in msg['topic']:
                tmpl = self._(
                    "{user} straight-up deleted the '{name}' wiki "
                    "page on the {project} trac instance")
            elif 'page.rename' in msg['topic']:
                old_name = msg['msg']['old_name']
                tmpl = self._(
                    "{user} renamed the wiki page '{old_name}' to '{name}' "
                    "on the {project} trac instance")
            elif 'page.update' in msg['topic']:
                tmpl = self._(
                    "{user} updated the '{name}' wiki page "
                    "on the {project} trac instance")
            elif 'page.new' in msg['topic']:
                tmpl = self._(
                    "{user} created a new '{name}' wiki page "
                    "on the {project} trac instance")

            return tmpl.format(
                user=user,
                name=name,
                old_name=old_name,
                project=project)
        elif 'ticket' in msg['msg']:
            status = None
            resolution = None
            user = msg['msg']['agent']
            project = msg['msg']['instance']['project_name']
            if 'ticket.delete' in msg['topic']:
                tmpl = self._(
                    "{user} straight-up deleted a ticket "
                    "on the {project} trac instance")
            elif 'ticket.new' in msg['topic']:
                tmpl = self._(
                    "{user} opened a new ticket "
                    "on the {project} trac instance")
            elif 'ticket.update' in msg['topic']:
                tmpl = self._(
                    "{user} updated a ticket "
                    "on the {project} trac instance")
                status = msg['msg']['ticket']['status']
                old_values = msg['msg']['old_values']
                if status == 'reopened' and 'status' in old_values:
                    tmpl = self._(
                        "{user} reopened a ticket "
                        "on the {project} trac instance")
                elif status == 'closed' and 'status' in old_values:
                    resolution = msg['msg']['ticket']['resolution']
                    tmpl = self._(
                        "{user} closed a ticket "
                        "on the {project} trac instance "
                        "as '{resolution}'")

            return tmpl.format(
                user=user,
                project=project,
                status=status,
                resolution=resolution,
            )
        elif 'git.receive' in msg['topic']:
            user = msg['msg']['commit']['username']
            project = msg['msg']['commit']['repo']
            tmpl = self._(
                "{user} pushed some commits to the '{project}' "
                "fedorahosted git repository")

            return tmpl.format(user=user, project=project)

    def secondary_icon(self, msg, **config):
        user = None

        try:
            user = msg['msg']['agent']
        except KeyError:
            pass

        try:
            user = msg['msg']['commit']['username']
{'fraction_non_alphanumeric': 0.11417120542595828, 'fraction_numerical': 0.0034939882848628095, 'mean_word_length': 1.6706915477497255, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3300628', 'n_tokens_mistral': 2605, 'n_tokens_neox': 2434, 'n_words': 846}