Exemple #1
0
    def _email_to_fas(self, email, **config):
        user = email2fas(email, **config)

        if '@' in user:
            is_fas = False
        else:
            is_fas = True

        return user, is_fas
    def usernames(self, msg, **config):
        username = msg['msg'].get('agent')
        if not username and 'pagure.git.receive' in msg['topic']:
            email = msg['msg']['commit']['email']
            username = email2fas(email, **config)

        if username:
            return set([username])
        else:
            return set([])
 def _get_user(self, msg, **config):
     try:
         email = msg['msg']['message']['agent']
     except KeyError:
         return msg.get('username', 'anitya')
     else:
         if email.endswith('@fedoraproject.org'):
             return email.split('@fedoraproject.org')[0]
         else:
             return email2fas(email, **config)
 def _get_user(self, msg, **config):
     try:
         email = msg['msg']['message']['agent']
     except KeyError:
         return msg.get('username', 'anitya')
     else:
         if email.endswith('@fedoraproject.org'):
             return email.split('@fedoraproject.org')[0]
         else:
             return email2fas(email, **config)
    def usernames(self, msg, **config):
        username = msg['msg'].get('agent')
        if not username and 'pagure.git.receive' in msg['topic']:
            email = msg['msg']['commit']['email']
            username = email2fas(email, **config)

        if username:
            return set([username])
        else:
            return set([])
    def secondary_icon(self, msg, **config):
        full_from = msg['msg']['msg']['from']
        email = _full_email_to_email(full_from)

        # Can we find this person in FAS?
        username = email2fas(email, **config)

        if '@' in username:
            # No?  Then use their email for libravatar
            return avatar_url_from_email(email)
        else:
            # Yes?  Then use their openid like everywhere else.
            return avatar_url_from_openid(username)
    def secondary_icon(self, msg, **config):
        full_from = msg['msg']['msg']['from']
        email = _full_email_to_email(full_from)

        # Can we find this person in FAS?
        username = email2fas(email, **config)

        if '@' in username:
            # No?  Then use their email for libravatar
            return avatar_url_from_email(email)
        else:
            # Yes?  Then use their openid like everywhere else.
            return avatar_url_from_openid(username)
 def _get_user(self, msg, **config):
     try:
         agent = msg["msg"]["message"]["agent"]
     except KeyError:
         return msg.get("username", "anitya")
     else:
         if "id.fedoraproject.org" in agent:
             agent = agent.partition(".id.fedoraproject.org")[0].partition("//")[-1]
             return agent
         elif agent.endswith("@fedoraproject.org"):
             return agent.split("@fedoraproject.org")[0]
         elif "@" in agent:
             return email2fas(agent, **config)
         else:
             return agent
 def _get_user(self, msg, **config):
     try:
         agent = msg['msg']['message']['agent']
     except KeyError:
         return msg.get('username', 'anitya')
     else:
         if 'id.fedoraproject.org' in agent:
             agent = agent.partition('.id.fedoraproject.org')[0].partition(
                 '//')[-1]
             return agent
         elif agent.endswith('@fedoraproject.org'):
             return agent.split('@fedoraproject.org')[0]
         elif '@' in agent:
             return email2fas(agent, **config)
         else:
             return agent
def _git_receive_v1(msg, tmpl, **config):
    ''' Return the subtitle for the first version of pagure git.receive
    messages.
    '''
    repo = _get_project(msg['msg']['commit'], key='repo')
    email = msg['msg']['commit']['email']
    user = email2fas(email, **config)
    summ = msg['msg']['commit']['summary']
    whole = msg['msg']['commit']['message']
    if summ.strip() != whole.strip():
        summ += " (..more)"

    branch = msg['msg']['commit']['branch']
    if 'refs/heads/' in branch:
        branch = branch.replace('refs/heads/', '')
    return tmpl.format(user=user or email, repo=repo,
                       branch=branch, summary=summ)
Exemple #11
0
def _git_receive_v1(msg, tmpl, **config):
    ''' Return the subtitle for the first version of pagure git.receive
    messages.
    '''
    repo = _get_project(msg['msg']['commit'], key='repo')
    email = msg['msg']['commit']['email']
    user = email2fas(email, **config)
    summ = msg['msg']['commit']['summary']
    whole = msg['msg']['commit']['message']
    if summ.strip() != whole.strip():
        summ += " (..more)"

    branch = msg['msg']['commit']['branch']
    if 'refs/heads/' in branch:
        branch = branch.replace('refs/heads/', '')
    return tmpl.format(user=user or email, repo=repo,
                       branch=branch, summary=summ)
    def merge(self, constituents, subject, **config):
        ms = constituents  # shorthand

        count = len(ms)
        agents = set(
            [email2fas(m['msg']['commit']['email'], **config) for m in ms])
        repo = ms[0]['msg']['commit']['repo']['name']
        subtitle = '{agents} pushed {count} commits to the {repo} project'
        agents = self.list_to_series(agents)

        tmpl = self.produce_template(constituents, subject, **config)
        tmpl['subtitle'] = subtitle.format(
            agents=agents,
            repo=repo,
            count=count,
        )
        tmpl['subjective'] = tmpl['subtitle']

        tmpl['secondary_icon'] = avatar_url(list(agents)[0])
        link_template = 'https://pagure.io/{repo}/commits'
        tmpl['link'] = link_template.format(repo=repo)

        return tmpl
    def merge(self, constituents, subject, **config):
        ms = constituents  # shorthand

        count = len(ms)
        agents = set([
            email2fas(m['msg']['commit']['email'], **config) for m in ms
        ])
        repo = ms[0]['msg']['commit']['repo']['name']
        subtitle = '{agents} pushed {count} commits to the {repo} project'
        agents = self.list_to_series(agents)

        tmpl = self.produce_template(constituents, subject, **config)
        tmpl['subtitle'] = subtitle.format(
            agents=agents,
            repo=repo,
            count=count,
        )
        tmpl['subjective'] = tmpl['subtitle']

        tmpl['secondary_icon'] = avatar_url(list(agents)[0])
        link_template = 'https://pagure.io/{repo}/commits'
        tmpl['link'] = link_template.format(repo=repo)

        return tmpl
def _email_to_username(email):
    return email2fas(email, **config)
    def subtitle(self, msg, **config):
        try:
            project = self.__get_project(msg['msg'])
        except KeyError:
            try:
                project = self.__get_project(msg['msg']['pullrequest'])
            except KeyError:
                project = "(unknown)"
        user = msg['msg'].get('agent')

        if 'pagure.project.new' in msg['topic']:
            tmpl = self._('{user} created a new project "{project}"')
            return tmpl.format(user=user, project=project)
        elif 'pagure.issue.new' in msg['topic']:
            issueid = msg['msg']['issue']['id']
            title = msg['msg']['issue']['title']
            tmpl = self._(
                '{user} opened a new ticket {project}#{id}: "{title}"')
            return tmpl.format(user=user,
                               project=project,
                               title=title,
                               id=issueid)
        elif 'pagure.issue.drop' in msg['topic']:
            issueid = msg['msg']['issue']['id']
            title = msg['msg']['issue']['title']
            tmpl = self._('{user} deleted ticket {project}#{id}: "{title}"')
            return tmpl.format(user=user,
                               project=project,
                               title=title,
                               id=issueid)
        elif 'pagure.issue.comment.added' in msg['topic']:
            issueid = msg['msg']['issue']['id']
            title = msg['msg']['issue']['title']
            tmpl = self._(
                '{user} commented on ticket {project}#{id}: "{title}"')
            return tmpl.format(user=user,
                               project=project,
                               title=title,
                               id=issueid)
        elif 'pagure.issue.tag.added' in msg['topic']:
            issueid = msg['msg']['issue']['id']
            tags = msg['msg']['tags']
            tags = fedmsg.meta.base.BaseConglomerator.list_to_series(tags)
            tmpl = self._('{user} tagged ticket {project}#{id}: {tags}')
            return tmpl.format(user=user,
                               project=project,
                               id=issueid,
                               tags=tags)
        elif 'pagure.issue.tag.removed' in msg['topic']:
            issueid = msg['msg']['issue']['id']
            tags = msg['msg']['tags']
            tags = fedmsg.meta.base.BaseConglomerator.list_to_series(tags)
            tmpl = self._(
                '{user} removed the {tags} tags from ticket {project}#{id}')
            return tmpl.format(user=user,
                               project=project,
                               id=issueid,
                               tags=tags)
        elif 'pagure.issue.assigned.added' in msg['topic']:
            issueid = msg['msg']['issue']['id']
            assignee = msg['msg']['issue']['assignee']['name']
            tmpl = self._(
                '{user} assigned ticket {project}#{id} to {assignee}')
            return tmpl.format(user=user,
                               project=project,
                               id=issueid,
                               assignee=assignee)
        elif 'pagure.issue.assigned.reset' in msg['topic']:
            issueid = msg['msg']['issue']['id']
            tmpl = self._('{user} reset the assignee of ticket {project}#{id}')
            return tmpl.format(user=user, project=project, id=issueid)
        elif 'pagure.issue.dependency.added' in msg['topic']:
            issueid = msg['msg']['issue']['id']
            dep_id = msg['msg']['added_dependency']
            tmpl = self._(
                '{user} added ticket {project}#{id} as a dependency of '
                'ticket {project}#{dep_id}')
            return tmpl.format(user=user,
                               project=project,
                               id=issueid,
                               dep_id=dep_id)
        elif 'pagure.issue.dependency.removed' in msg['topic']:
            issueid = msg['msg']['issue']['id']
            removed = msg['msg']['removed_dependency']
            tmpl = self._(
                '{user} removed ticket {project}#{id} as a dependency '
                'of ticket {project}#{removed}')
            return tmpl.format(user=user,
                               project=project,
                               id=issueid,
                               removed=removed)
        elif 'pagure.issue.edit' in msg['topic']:
            issueid = msg['msg']['issue']['id']
            fields = msg['msg']['fields']
            fields = fedmsg.meta.base.BaseConglomerator.list_to_series(fields)
            tmpl = self._('{user} edited the {fields} fields of ticket '
                          '{project}#{id}')
            return tmpl.format(user=user,
                               project=project,
                               id=issueid,
                               fields=fields)
        elif 'pagure.project.edit' in msg['topic']:
            fields = msg['msg']['fields']
            fields = fedmsg.meta.base.BaseConglomerator.list_to_series(fields)
            tmpl = self._(
                '{user} edited the {fields} fields of project {project}')
            return tmpl.format(user=user, project=project, fields=fields)
        elif 'pagure.project.user.added' in msg['topic']:
            new_user = msg['msg']['new_user']
            tmpl = self._('{user} added "{new_user}" to project {project}')
            return tmpl.format(user=user, project=project, new_user=new_user)
        elif 'pagure.project.tag.removed' in msg['topic']:
            tags = msg['msg']['tags']
            tags = fedmsg.meta.base.BaseConglomerator.list_to_series(tags)
            tmpl = self._(
                '{user} removed tags "{tags}" from project {project}')
            return tmpl.format(user=user, project=project, tags=tags)
        elif 'pagure.project.tag.edited' in msg['topic']:
            old_tag = msg['msg']['old_tag']
            new_tag = msg['msg']['new_tag']
            tmpl = self._('{user} altered tags on project {project} from '
                          '"{old_tag}" to "{new_tag}"')
            return tmpl.format(user=user,
                               project=project,
                               old_tag=old_tag,
                               new_tag=new_tag)
        elif 'pagure.project.forked' in msg['topic']:
            old_project = msg['msg']['project']['parent']['name']
            tmpl = self._(
                '{user} forked project "{old_project}" to "{project}"')
            return tmpl.format(user=user,
                               old_project=old_project,
                               project=project)
        elif 'pagure.pull-request.comment.added' in msg['topic']:
            prid = msg['msg']['pullrequest']['id']
            tmpl = self._('{user} commented on pull-request#{id} of project '
                          '"{project}"')
            return tmpl.format(user=user, id=prid, project=project)
        elif 'pagure.pull-request.closed' in msg['topic']:
            prid = msg['msg']['pullrequest']['id']
            merged = msg['msg']['merged']
            if merged:
                tmpl = self._('{user} merged pull-request#{id} of project '
                              '"{project}"')
            else:
                tmpl = self._(
                    '{user} closed (without merging) pull-request#{id} '
                    'of project "{project}"')
            return tmpl.format(user=user, id=prid, project=project)
        elif 'pagure.pull-request.new' in msg['topic']:
            prid = msg['msg']['pullrequest']['id']
            title = msg['msg']['pullrequest']['title']
            tmpl = self._('{user} opened pull-request#{id}: "{title}" on '
                          'project "{project}"')
            return tmpl.format(user=user,
                               id=prid,
                               project=project,
                               title=title)
        elif 'pagure.pull-request.flag.added' in msg['topic']:
            prid = msg['msg']['pullrequest']['id']
            username = msg['msg']['flag']['username']
            comment = msg['msg']['flag']['comment']
            tmpl = self._('{username} flagged {project}#{id} with "{comment}"')
            return tmpl.format(username=username,
                               id=prid,
                               comment=comment,
                               project=project)

        elif 'pagure.pull-request.flag.updated' in msg['topic']:
            prid = msg['msg']['pullrequest']['id']
            username = msg['msg']['flag']['username']
            comment = msg['msg']['flag']['comment']
            tmpl = self._(
                '{username} updated the flags on {project}#{id} with: '
                '"{comment}"')
            return tmpl.format(username=username,
                               id=prid,
                               comment=comment,
                               project=project)
        elif 'pagure.git.receive' in msg['topic']:
            repo = self.__get_project(msg['msg']['commit'], key='repo')
            email = msg['msg']['commit']['email']
            user = email2fas(email, **config)
            summ = msg['msg']['commit']['summary']
            whole = msg['msg']['commit']['message']
            if summ.strip() != whole.strip():
                summ += " (..more)"

            branch = msg['msg']['commit']['branch']
            if 'refs/heads/' in branch:
                branch = branch.replace('refs/heads/', '')
            tmpl = self._('{user} pushed to {repo} ({branch}). "{summary}"')
            return tmpl.format(user=user or email,
                               repo=repo,
                               branch=branch,
                               summary=summ)

        else:
            pass
Exemple #16
0
    def matches(self, msg):

        # First, do a lightweight check to see if the msg matches a pattern.
        if not self.trigger.matches(msg):
            return set()

        # Before proceeding further, let's see who would get this badge if
        # our more heavyweight checks matched up.  If the user specifies a
        # recipient_key, we can use that to extract the potential awardee.  If
        # that is not specified, we just use `msg2usernames`.
        if self.recipient_key:
            subs = construct_substitutions(msg)
            obj = format_args(self.recipient_key, subs)

            if isinstance(obj, (basestring, int, float)):
                obj = [obj]

            # On the way, it is possible for the fedmsg message to contain None
            # for "agent".  A problem here though is that None is not iterable,
            # so let's replace it with an equivalently empty iterable so code
            # further down doesn't freak out.  An instance of this is when a
            # user without a fas account comments on a bodhi update.
            if obj is None:
                obj = []

            awardees = frozenset(obj)

            if self.recipient_nick2fas:
                awardees = frozenset(
                    [nick2fas(nick, **fedmsg_config) for nick in awardees])

            if self.recipient_email2fas:
                awardees = frozenset(
                    [email2fas(email, **fedmsg_config) for email in awardees])
        else:
            usernames = fedmsg.meta.msg2usernames(msg)
            awardees = usernames.difference(self.banned_usernames)

        # Strip anyone who is an IP address
        awardees = frozenset([
            user for user in awardees
            if not (user.startswith('192.168.') or user.startswith('10.'))
        ])

        # If no-one would get the badge by default, then no reason to waste
        # time doing any further checks.  No need to query the Tahrir DB.
        if not awardees:
            return awardees

        # Limit awardees to only those who do not already have this badge.
        # Do this only if we have an active connection to the Tahrir DB.
        if self.tahrir:
            awardees = frozenset([
                user for user in awardees if not self.tahrir.assertion_exists(
                    self.badge_id, "*****@*****.**" % user)
            ])

            # Also, exclude any potential awardees who have opted out.
            awardees = frozenset([
                user for user in awardees
                if not self.tahrir.person_opted_out("*****@*****.**" %
                                                    user)
            ])

        # If no-one would get the badge at this point, then no reason to waste
        # time doing any further checks.  No need to query datanommer.
        if not awardees:
            return awardees

        # Check our backend criteria -- likely, perform datanommer queries.
        try:
            if not self.criteria.matches(msg):
                return set()
        except IOError as e:
            log.exception(e)
            return set()

        # Lastly, and this is probably most expensive.  Make sure the person
        # actually has a FAS account before we award anything.
        # https://github.com/fedora-infra/tahrir/issues/225
        awardees = set(
            [u for u in awardees if user_exists_in_fas(fedmsg_config, u)])

        return awardees
def _email_to_username(email):
    return email2fas(email, **config)
Exemple #18
0
    def matches(self, msg):

        # First, do a lightweight check to see if the msg matches a pattern.
        if not self.trigger.matches(msg):
            return set()

        # Before proceeding further, let's see who would get this badge if
        # our more heavyweight checks matched up.  If the user specifies a
        # recipient_key, we can use that to extract the potential awardee.  If
        # that is not specified, we just use `msg2usernames`.
        if self.recipient_key:
            subs = construct_substitutions(msg)
            obj = format_args(self.recipient_key, subs)

            if isinstance(obj, (basestring, int, float)):
                obj = [obj]

            # On the way, it is possible for the fedmsg message to contain None
            # for "agent".  A problem here though is that None is not iterable,
            # so let's replace it with an equivalently empty iterable so code
            # further down doesn't freak out.  An instance of this is when a
            # user without a fas account comments on a bodhi update.
            if obj is None:
                obj = []

            awardees = frozenset(obj)

            if self.recipient_nick2fas:
                awardees = frozenset([
                    nick2fas(nick, **fedmsg_config) for nick in awardees
                ])

            if self.recipient_email2fas:
                awardees = frozenset([
                    email2fas(email, **fedmsg_config) for email in awardees
                ])
        else:
            usernames = fedmsg.meta.msg2usernames(msg)
            awardees = usernames.difference(self.banned_usernames)

        # Strip anyone who is an IP address
        awardees = frozenset([
            user for user in awardees if not (
                user.startswith('192.168.') or
                user.startswith('10.')
            )
        ])

        # If no-one would get the badge by default, then no reason to waste
        # time doing any further checks.  No need to query the Tahrir DB.
        if not awardees:
            return awardees

        # Limit awardees to only those who do not already have this badge.
        # Do this only if we have an active connection to the Tahrir DB.
        if self.tahrir:
            awardees = frozenset([
                user for user in awardees
                if not self.tahrir.assertion_exists(
                    self.badge_id, "*****@*****.**" % user
                )])

            # Also, exclude any potential awardees who have opted out.
            awardees = frozenset([
                user for user in awardees
                if not self.tahrir.person_opted_out(
                    "*****@*****.**" % user
                )])

        # If no-one would get the badge at this point, then no reason to waste
        # time doing any further checks.  No need to query datanommer.
        if not awardees:
            return awardees

        # Check our backend criteria -- likely, perform datanommer queries.
        try:
            if not self.criteria.matches(msg):
                return set()
        except IOError as e:
            log.exception(e)
            return set()

        # Lastly, and this is probably most expensive.  Make sure the person
        # actually has a FAS account before we award anything.
        # https://github.com/fedora-infra/tahrir/issues/225
        awardees = set([
            u for u in awardees if user_exists_in_fas(fedmsg_config, u)
        ])

        return awardees
    def subtitle(self, msg, **config):
        try:
            project = self.__get_project(msg['msg'])
        except KeyError:
            try:
                project = self.__get_project(msg['msg']['pullrequest'])
            except KeyError:
                project = "(unknown)"
        user = msg['msg'].get('agent')

        if 'pagure.project.new' in msg['topic']:
            tmpl = self._(
                '{user} created a new project "{project}"'
            )
            return tmpl.format(user=user, project=project)
        elif 'pagure.issue.new' in msg['topic']:
            issueid = msg['msg']['issue']['id']
            title = msg['msg']['issue']['title']
            tmpl = self._(
                '{user} opened a new ticket {project}#{id}: "{title}"')
            return tmpl.format(
                user=user, project=project, title=title, id=issueid)
        elif 'pagure.issue.drop' in msg['topic']:
            issueid = msg['msg']['issue']['id']
            title = msg['msg']['issue']['title']
            tmpl = self._(
                '{user} deleted ticket {project}#{id}: "{title}"')
            return tmpl.format(
                user=user,project=project,title=title,id=issueid)
        elif 'pagure.issue.comment.edited' in msg['topic']:
            issueid = msg['msg']['issue']['id']
            title = msg['msg']['issue']['title']
            tmpl = self._(
                '{user} edited a comment on ticket {project}#{id}: "{title}"')
            return tmpl.format(
                user=user, project=project, title=title, id=issueid)
        elif 'pagure.issue.comment.added' in msg['topic']:
            issueid = msg['msg']['issue']['id']
            title = msg['msg']['issue']['title']
            tmpl = self._(
                '{user} commented on ticket {project}#{id}: "{title}"')
            return tmpl.format(
                user=user, project=project, title=title, id=issueid)
        elif 'pagure.issue.tag.added' in msg['topic']:
            issueid = msg['msg']['issue']['id']
            tags = msg['msg']['tags']
            tags = fedmsg.meta.base.BaseConglomerator.list_to_series(tags)
            tmpl = self._(
                '{user} tagged ticket {project}#{id}: {tags}')
            return tmpl.format(
                user=user, project=project, id=issueid, tags=tags)
        elif 'pagure.issue.tag.removed' in msg['topic']:
            issueid = msg['msg']['issue']['id']
            tags = msg['msg']['tags']
            tags = fedmsg.meta.base.BaseConglomerator.list_to_series(tags)
            tmpl = self._(
                '{user} removed the {tags} tags from ticket {project}#{id}')
            return tmpl.format(
                user=user, project=project, id=issueid, tags=tags)
        elif 'pagure.issue.assigned.added' in msg['topic']:
            issueid = msg['msg']['issue']['id']
            assignee = msg['msg']['issue']['assignee']['name']
            tmpl = self._(
                '{user} assigned ticket {project}#{id} to {assignee}')
            return tmpl.format(
                user=user, project=project, id=issueid, assignee=assignee)
        elif 'pagure.issue.assigned.reset' in msg['topic']:
            issueid = msg['msg']['issue']['id']
            tmpl = self._(
                '{user} reset the assignee of ticket {project}#{id}')
            return tmpl.format(user=user, project=project, id=issueid)
        elif 'pagure.issue.dependency.added' in msg['topic']:
            issueid = msg['msg']['issue']['id']
            dep_id = msg['msg']['added_dependency']
            tmpl = self._(
                '{user} added ticket {project}#{id} as a dependency of '
                'ticket {project}#{dep_id}'
            )
            return tmpl.format(
                user=user, project=project, id=issueid,
                dep_id=dep_id)
        elif 'pagure.issue.dependency.removed' in msg['topic']:
            issueid = msg['msg']['issue']['id']
            removed = msg['msg']['removed_dependency']
            tmpl = self._(
                '{user} removed ticket {project}#{id} as a dependency '
                'of ticket {project}#{removed}'
            )
            return tmpl.format(
                user=user, project=project, id=issueid, removed=removed)
        elif 'pagure.issue.edit' in msg['topic']:
            issueid = msg['msg']['issue']['id']
            fields = msg['msg']['fields']
            if fields == ['status']:
                status = msg['msg']['issue']['status']
                tmpl = self._(
                    '{user} set the status of ticket {project}#{id} to: '
                    '{status}')
                return tmpl.format(
                    user=user, project=project, id=issueid, status=status)
            fields = fedmsg.meta.base.BaseConglomerator.list_to_series(fields)
            tmpl = self._(
                '{user} edited the {fields} fields of ticket '
                '{project}#{id}'
            )
            return tmpl.format(
                user=user, project=project, id=issueid, fields=fields)
        elif 'pagure.project.edit' in msg['topic']:
            fields = msg['msg']['fields']
            fields = fedmsg.meta.base.BaseConglomerator.list_to_series(fields)
            tmpl = self._(
                '{user} edited the {fields} fields of project {project}')
            return tmpl.format(user=user, project=project, fields=fields)
        elif 'pagure.project.user.added' in msg['topic']:
            new_user = msg['msg']['new_user']
            tmpl = self._(
                '{user} added "{new_user}" to project {project}'
            )
            return tmpl.format(user=user, project=project, new_user=new_user)
        elif 'pagure.project.tag.removed' in msg['topic']:
            tags = msg['msg']['tags']
            tags = fedmsg.meta.base.BaseConglomerator.list_to_series(tags)
            tmpl = self._(
                '{user} removed tags "{tags}" from project {project}'
            )
            return tmpl.format(user=user, project=project, tags=tags)
        elif 'pagure.project.tag.edited' in msg['topic']:
            old_tag = msg['msg']['old_tag']
            new_tag = msg['msg']['new_tag']
            tmpl = self._(
                '{user} altered tags on project {project} from '
                '"{old_tag}" to "{new_tag}"'
            )
            return tmpl.format(
                user=user, project=project,
                old_tag=old_tag, new_tag=new_tag)
        elif 'pagure.project.forked' in msg['topic']:
            old_project = msg['msg']['project']['parent']['name']
            tmpl = self._(
                '{user} forked project "{old_project}" to "{project}"'
            )
            return tmpl.format(
                user=user, old_project=old_project, project=project)
        elif 'pagure.pull-request.comment.added' in msg['topic']:
            prid = msg['msg']['pullrequest']['id']
            tmpl = self._(
                '{user} commented on pull-request#{id} of project '
                '"{project}"'
            )
            return tmpl.format(user=user, id=prid, project=project)
        elif 'pagure.pull-request.closed' in msg['topic']:
            prid = msg['msg']['pullrequest']['id']
            merged = msg['msg']['merged']
            if merged:
                tmpl = self._(
                    '{user} merged pull-request#{id} of project '
                    '"{project}"'
                )
            else:
                tmpl = self._(
                    '{user} closed (without merging) pull-request#{id} '
                    'of project "{project}"'
                )
            return tmpl.format(user=user, id=prid, project=project)
        elif 'pagure.pull-request.new' in msg['topic']:
            prid = msg['msg']['pullrequest']['id']
            title = msg['msg']['pullrequest']['title']
            tmpl = self._(
                '{user} opened pull-request#{id}: "{title}" on '
                'project "{project}"'
            )
            return tmpl.format(
                user=user, id=prid, project=project, title=title)
        elif 'pagure.pull-request.flag.added' in msg['topic']:
            prid = msg['msg']['pullrequest']['id']
            username = msg['msg']['flag']['username']
            comment = msg['msg']['flag']['comment']
            tmpl = self._(
                '{username} flagged {project}#{id} with "{comment}"'
            )
            return tmpl.format(
                username=username, id=prid, comment=comment, project=project)

        elif 'pagure.pull-request.flag.updated' in msg['topic']:
            prid = msg['msg']['pullrequest']['id']
            username = msg['msg']['flag']['username']
            comment = msg['msg']['flag']['comment']
            tmpl = self._(
                '{username} updated the flags on {project}#{id} with: '
                '"{comment}"'
            )
            return tmpl.format(
                username=username, id=prid, comment=comment, project=project)
        elif 'pagure.git.receive' in msg['topic']:
            repo = self.__get_project(msg['msg']['commit'], key='repo')
            email = msg['msg']['commit']['email']
            user = email2fas(email, **config)
            summ = msg['msg']['commit']['summary']
            whole = msg['msg']['commit']['message']
            if summ.strip() != whole.strip():
                summ += " (..more)"

            branch = msg['msg']['commit']['branch']
            if 'refs/heads/' in branch:
                branch = branch.replace('refs/heads/', '')
            tmpl = self._('{user} pushed to {repo} ({branch}). "{summary}"')
            return tmpl.format(user=user or email, repo=repo,
                               branch=branch, summary=summ)

        else:
            pass