Skip to content

Commit 6a6689d

Browse files
committed
I see a codebase and I want it painted black
Just run Black. No other change. Signed-off-by: Aurélien Bompard <aurelien@bompard.org>
1 parent b5b7258 commit 6a6689d

8 files changed

Lines changed: 1108 additions & 1053 deletions

File tree

bugzilla2fedmsg/relay.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ def _bz4_compat_transform(bug, event, objdict, obj):
3131
if bug.get("operating_system"):
3232
bug["op_sys"] = bug["operating_system"]
3333
if not bug.get("weburl"):
34-
bug["weburl"] = "https://bugzilla.redhat.com/show_bug.cgi?id=%s" % bug['id']
34+
bug["weburl"] = "https://bugzilla.redhat.com/show_bug.cgi?id=%s" % bug["id"]
3535
event["who"] = event["user"]["login"]
3636
event["changes"] = event.get("changes", [])
3737
for change in event["changes"]:
3838
change["field_name"] = change["field"]
39-
if obj == 'comment':
39+
if obj == "comment":
4040
# I would expect this to be real_name so we're not spaffing
4141
# email addresses all over, but I checked and historically
4242
# it was definitely login
43-
objdict[obj]['author'] = event.get('user', {}).get('login', '')
43+
objdict[obj]["author"] = event.get("user", {}).get("login", "")
4444

4545

4646
class MessageRelay:
@@ -61,18 +61,18 @@ def on_stomp_message(self, body, headers):
6161
# destination looks something like
6262
# "/topic/VirtualTopic.eng.bugzilla.bug.modify"
6363
# this splits out the 'bug' part
64-
obj = headers['destination'].split('bugzilla.')[1].split('.')[0]
64+
obj = headers["destination"].split("bugzilla.")[1].split(".")[0]
6565
if obj not in body:
6666
LOGGER.debug("DROP: message has no object field. Non public.")
6767
return
6868
objdict = {}
6969
bug = None
70-
if obj == 'bug':
70+
if obj == "bug":
7171
# just take the bug dict, converting datetimes
72-
bug = convert_datetimes(body['bug'])
72+
bug = convert_datetimes(body["bug"])
7373
else:
7474
# unpick the bug dict from the object dict
75-
bug = convert_datetimes(body[obj].pop('bug'))
75+
bug = convert_datetimes(body[obj].pop("bug"))
7676
objdict[obj] = convert_datetimes(body[obj])
7777

7878
# As of https://bugzilla.redhat.com/show_bug.cgi?id=1248259, bugzilla
@@ -93,7 +93,7 @@ def on_stomp_message(self, body, headers):
9393
_bz4_compat_transform(bug, event, objdict, obj)
9494

9595
topic = "bug.update"
96-
if 'bug.create' in headers['destination']:
96+
if "bug.create" in headers["destination"]:
9797
topic = "bug.new"
9898

9999
# construct message dict, add the object dict we got earlier
@@ -105,7 +105,7 @@ def on_stomp_message(self, body, headers):
105105
)
106106
body.update(objdict)
107107

108-
LOGGER.debug("Republishing #%s" % bug['id'])
108+
LOGGER.debug("Republishing #%s" % bug["id"])
109109
messageclass = MessageV1
110110
if self._bz4_compat_mode:
111111
messageclass = MessageV1BZ4
@@ -117,6 +117,8 @@ def on_stomp_message(self, body, headers):
117117
)
118118
publish(message)
119119
except PublishReturned as e:
120-
LOGGER.warning("Fedora Messaging broker rejected message {}: {}".format(message.id, e))
120+
LOGGER.warning(
121+
"Fedora Messaging broker rejected message {}: {}".format(message.id, e)
122+
)
121123
except ConnectionException as e:
122124
LOGGER.warning("Error sending message {}: {}".format(message.id, e))

bugzilla2fedmsg/utils.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,15 @@
1414

1515

1616
def convert_datetimes(obj):
17-
""" Recursively convert the ISO-8601ish date/time strings we get
17+
"""Recursively convert the ISO-8601ish date/time strings we get
1818
from stomp to epoch integers (because this is what fedmsg used to
1919
emit when we sent it datetime instances).
2020
"""
2121

2222
if isinstance(obj, list):
2323
return [convert_datetimes(item) for item in obj]
2424
elif isinstance(obj, dict):
25-
return dict([
26-
(k, convert_datetimes(v))
27-
for k, v in obj.items()
28-
])
25+
return dict([(k, convert_datetimes(v)) for k, v in obj.items()])
2926
else:
3027
try:
3128
# the string we get is YYYY-MM-DDTHH:MM:SS, no timezone,

bugzilla2fedmsg_schema/schema.py

Lines changed: 80 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ def __str__(self):
2020
def summary(self):
2121
"""A summary of the message."""
2222
(user, _) = email_to_fas(self._primary_email)
23-
idx = self.bug['id']
24-
title = self.bug['summary']
25-
action = self.body['event']['action']
26-
target = self.body['event']['target']
23+
idx = self.bug["id"]
24+
title = self.bug["summary"]
25+
action = self.body["event"]["action"]
26+
target = self.body["event"]["target"]
2727

2828
if len(title) > 40:
2929
title = title[:40] + "..."
@@ -32,19 +32,21 @@ def summary(self):
3232
tmpl = "{user} filed a new bug RHBZ#{idx} '{title}'"
3333
return tmpl.format(user=user, idx=idx, title=title)
3434

35-
elif self.body['event']['action'] == "create":
35+
elif self.body["event"]["action"] == "create":
3636
tmpl = "{user} added {target} on RHBZ#{idx} '{title}'"
3737
return tmpl.format(user=user, target=target, idx=idx, title=title)
3838

3939
# at this point 'action' must be "modify": we're modifying the
4040
# target
41-
fields = [d['field'] for d in self.body['event'].get('changes', [])]
41+
fields = [d["field"] for d in self.body["event"].get("changes", [])]
4242
fields = comma_join(fields)
4343
if target == "bug":
4444
tmpl = "{user} updated {fields} on RHBZ#{idx} '{title}'"
4545
return tmpl.format(user=user, fields=fields, idx=idx, title=title)
4646
tmpl = "{user} updated {fields} for {target} on RHBZ#{idx} '{title}'"
47-
return tmpl.format(user=user, fields=fields, target=target, idx=idx, title=title)
47+
return tmpl.format(
48+
user=user, fields=fields, target=target, idx=idx, title=title
49+
)
4850

4951
@property
5052
def url(self):
@@ -53,7 +55,7 @@ def url(self):
5355
Returns:
5456
str: A relevant URL.
5557
"""
56-
return "https://bugzilla.redhat.com/show_bug.cgi?id={}".format(self.bug['id'])
58+
return "https://bugzilla.redhat.com/show_bug.cgi?id={}".format(self.bug["id"])
5759

5860
@property
5961
def app_icon(self):
@@ -78,14 +80,14 @@ def packages(self):
7880
# these are Bugzilla components that are not Fedora packages
7981
# add any more you can think of
8082
notpackages = [
81-
'distribution',
82-
'LiveCD',
83-
'LiveCD - FEL',
84-
'LiveCD - Games',
85-
'LiveCD - KDE',
86-
'LiveCD - LXDE',
87-
'LiveCD - Xfce',
88-
'Package Review',
83+
"distribution",
84+
"LiveCD",
85+
"LiveCD - FEL",
86+
"LiveCD - Games",
87+
"LiveCD - KDE",
88+
"LiveCD - LXDE",
89+
"LiveCD - Xfce",
90+
"Package Review",
8991
]
9092
if compname in notpackages:
9193
return []
@@ -101,7 +103,7 @@ def _primary_email(self):
101103
"""The email for the primary user associated with the action
102104
that generated this message.
103105
"""
104-
return self.body['event']['user']['login']
106+
return self.body["event"]["user"]["login"]
105107

106108
@property
107109
def _all_emails(self):
@@ -114,27 +116,27 @@ def _all_emails(self):
114116
users.add(self._primary_email)
115117

116118
# bug reporter and assignee
117-
users.add(self.bug['reporter']['login'])
119+
users.add(self.bug["reporter"]["login"])
118120
users.add(self.assigned_to_email)
119121

120-
for change in self.body['event'].get('changes', []):
121-
if change['field'] == "cc":
122+
for change in self.body["event"].get("changes", []):
123+
if change["field"] == "cc":
122124
# anyone added to CC list
123-
for user in change['added'].split(','):
125+
for user in change["added"].split(","):
124126
user.strip()
125127
if user:
126128
users.add(user)
127-
elif change['field'] == "flag.needinfo":
129+
elif change["field"] == "flag.needinfo":
128130
# anyone for whom a 'needinfo' flag is set
129131
# this is extracting the email from a value like:
130132
# "? (senrique@redhat.com)"
131-
user = change['added'].split('(', 1)[1].rsplit(')', 1)[0]
133+
user = change["added"].split("(", 1)[1].rsplit(")", 1)[0]
132134
if user:
133135
users.add(user)
134136

135137
# Strip anything that made it in erroneously
136138
for user in list(users):
137-
if user.endswith('lists.fedoraproject.org'):
139+
if user.endswith("lists.fedoraproject.org"):
138140
users.remove(user)
139141

140142
users = list(users)
@@ -233,11 +235,31 @@ class MessageV1(BaseMessage):
233235
},
234236
"whiteboard": {"type": "string"},
235237
},
236-
"required": ["alias", "assigned_to", "classification", "component",
237-
"creation_time", "flags", "id", "is_private", "keywords",
238-
"last_change_time", "operating_system", "platform", "priority",
239-
"product", "qa_contact", "reporter", "resolution", "severity",
240-
"status", "summary", "url", "version", "whiteboard"],
238+
"required": [
239+
"alias",
240+
"assigned_to",
241+
"classification",
242+
"component",
243+
"creation_time",
244+
"flags",
245+
"id",
246+
"is_private",
247+
"keywords",
248+
"last_change_time",
249+
"operating_system",
250+
"platform",
251+
"priority",
252+
"product",
253+
"qa_contact",
254+
"reporter",
255+
"resolution",
256+
"severity",
257+
"status",
258+
"summary",
259+
"url",
260+
"version",
261+
"whiteboard",
262+
],
241263
},
242264
"event": {
243265
"description": "An object representing the event the message relates to",
@@ -260,8 +282,15 @@ class MessageV1(BaseMessage):
260282
},
261283
},
262284
},
263-
"required": ["action", "bug_id", "change_set", "routing_key", "target",
264-
"time", "user"],
285+
"required": [
286+
"action",
287+
"bug_id",
288+
"change_set",
289+
"routing_key",
290+
"target",
291+
"time",
292+
"user",
293+
],
265294
},
266295
"comment": {
267296
"description": "An object representing a comment affected by the event",
@@ -289,9 +318,18 @@ class MessageV1(BaseMessage):
289318
"is_private": {"type": "boolean"},
290319
"last_change_time": {"type": "number"},
291320
},
292-
"required": ["content_type", "creation_time", "description", "file_name",
293-
"flags", "id", "is_obsolete", "is_patch", "is_private",
294-
"last_change_time"],
321+
"required": [
322+
"content_type",
323+
"creation_time",
324+
"description",
325+
"file_name",
326+
"flags",
327+
"id",
328+
"is_obsolete",
329+
"is_patch",
330+
"is_private",
331+
"last_change_time",
332+
],
295333
},
296334
},
297335
"required": ["bug", "event"],
@@ -300,22 +338,22 @@ class MessageV1(BaseMessage):
300338
@property
301339
def bug(self):
302340
"""The bug dictionary from the message."""
303-
return self.body['bug']
341+
return self.body["bug"]
304342

305343
@property
306344
def assigned_to_email(self):
307345
"""The email address of the user to which the bug is assigned."""
308-
return self.bug['assigned_to']['login']
346+
return self.bug["assigned_to"]["login"]
309347

310348
@property
311349
def component_name(self):
312350
"""The name of the component against which the bug is filed."""
313-
return self.bug['component']['name']
351+
return self.bug["component"]["name"]
314352

315353
@property
316354
def product_name(self):
317355
"""The name of the product against which the bug is filed."""
318-
return self.bug['product']['name']
356+
return self.bug["product"]["name"]
319357

320358

321359
class MessageV1BZ4(MessageV1):
@@ -345,19 +383,19 @@ class MessageV1BZ4(MessageV1):
345383
@property
346384
def bug(self):
347385
"""The bug dictionary from the message."""
348-
return self.body['bug']
386+
return self.body["bug"]
349387

350388
@property
351389
def assigned_to_email(self):
352390
"""The email address of the user to which the bug is assigned."""
353-
return self.bug['assigned_to']
391+
return self.bug["assigned_to"]
354392

355393
@property
356394
def component_name(self):
357395
"""The name of the component against which the bug is filed."""
358-
return self.bug['component']
396+
return self.bug["component"]
359397

360398
@property
361399
def product_name(self):
362400
"""The name of the product against which the bug is filed."""
363-
return self.bug['product']
401+
return self.bug["product"]

bugzilla2fedmsg_schema/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
def comma_join(fields, oxford=True):
5-
""" Join together words. """
5+
"""Join together words."""
66

77
def fmt(field):
88
return "'%s'" % field
@@ -30,6 +30,6 @@ def email_to_fas(email):
3030
we can just do this easily. For all other addresses, we really
3131
need that full feature added to fedora-messaging.
3232
"""
33-
if email.endswith('@fedoraproject.org'):
34-
return (email.rsplit('@', 1)[0], True)
33+
if email.endswith("@fedoraproject.org"):
34+
return (email.rsplit("@", 1)[0], True)
3535
return (email, False)

setup.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55

66
setup(
7-
name='bugzilla2fedmsg',
8-
version='1.0.0',
9-
description='Consume Bugzilla messages over STOMP and republish to Fedora Messaging',
10-
license='LGPLv2+',
11-
author='Ralph Bean',
12-
author_email='rbean@redhat.com',
13-
url='https://github.com/fedora-infra/bugzilla2fedmsg',
7+
name="bugzilla2fedmsg",
8+
version="1.0.0",
9+
description="Consume Bugzilla messages over STOMP and republish to Fedora Messaging",
10+
license="LGPLv2+",
11+
author="Ralph Bean",
12+
author_email="rbean@redhat.com",
13+
url="https://github.com/fedora-infra/bugzilla2fedmsg",
1414
# Possible options are at https://pypi.python.org/pypi?%3Aaction=list_classifiers
1515
classifiers=[
1616
"Development Status :: 5 - Production/Stable",

0 commit comments

Comments
 (0)