/usr/lib/python2.7/dist-packages/fedmsg_meta_fedora_infrastructure/bz.py is in python-fedmsg-meta-fedora-infrastructure 0.2.18-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | # This file is part of fedmsg.
# Copyright (C) 2012-2014 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: Ralph Bean <rbean@redhat.com>
from fasshim import gravatar_url, gravatar_url_from_email, email2fas
from fedmsg_meta_fedora_infrastructure import BaseProcessor
MAX_LEN = 40
def comma_join(fields, oxford=True):
""" Join together words. """
def fmt(field):
return "'%s'" % field
if not fields:
return "nothing"
elif len(fields) == 1:
return fmt(fields[0])
elif len(fields) == 2:
return " and ".join([fmt(f) for f in fields])
else:
result = ", ".join([fmt(f) for f in fields[:-1]])
if oxford:
result += ","
result += " and %s" % fmt(fields[-1])
return result
class BugzillaProcessor(BaseProcessor):
__name__ = "bugzilla"
__description__ = "Red Hat Bugzilla"
__link__ = "https://bugzilla.redhat.com"
__icon__ = "https://apps.fedoraproject.org/img/icons/bugzilla.png"
__docs__ = "https://bugzilla.redhat.com"
__obj__ = "Bug Updates"
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 _get_user(self, msg, **config):
email = msg['msg']['event'].get('who')
if not email:
email = msg['msg']['bug'].get('creator')
user, is_fas = self._email_to_fas(email, **config)
return user, is_fas
def link(self, msg, **config):
return msg['msg']['bug']['weburl']
def subtitle(self, msg, **config):
user, is_fas = self._get_user(msg, **config)
idx = msg['msg'].get('bug', {}).get('id')
title = msg['msg'].get('bug', {}).get('summary')
if len(title) > MAX_LEN:
title = title[:MAX_LEN] + "..."
if 'bug.update' in msg['topic']:
fields = [d['field_name'] for d in msg['msg']['event']['changes']]
fields = comma_join(fields)
tmpl = self._("{user} updated {fields} on RHBZ#{idx} '{title}'")
return tmpl.format(user=user, fields=fields, idx=idx, title=title)
elif 'bug.new' in msg['topic']:
tmpl = self._("{user} filed a new bug RHBZ#{idx} '{title}'")
return tmpl.format(user=user, idx=idx, title=title)
def secondary_icon(self, msg, **config):
user, is_fas = self._get_user(msg, **config)
if is_fas:
return gravatar_url(user)
else:
return gravatar_url_from_email(user)
def _gather_emails(self, msg):
users = set()
msg = msg['msg']
bug = msg['bug']
users.add(msg['event'].get('who'))
users.add(bug.get('creator'))
users.add(bug.get('assigned_to'))
for email in bug['cc']:
users.add(email)
# Strip anything that made it in erroneously
for user in list(users):
if not user:
users.remove(user)
continue
if user.endswith('lists.fedoraproject.org'):
users.remove(user)
continue
return users
def usernames(self, msg, **config):
emails = self._gather_emails(msg)
users = set()
for email in emails:
user, is_fas = self._email_to_fas(email, **config)
if is_fas:
users.add(user)
return users
def objects(self, msg, **config):
return set([
'/'.join([
msg['msg']['bug']['product'],
msg['msg']['bug']['component'],
str(msg['msg']['bug']['id']),
])
])
|