/
campfire.py
82 lines (73 loc) · 3.95 KB
/
campfire.py
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
from lookout.base import ServiceBase
from pinder import Campfire, Room
class Service(ServiceBase):
"""
Campfire
This will send item events from Sprint.ly to your Campfire chat room. To install
the package follow the steps below:
1. `subdomain` is Campfire subdomain (e.g. `foobar` in `https://foobar.campfirenow.com`)
2. `room` is the actual name of the room from your Campfire Lobby. **NOTE:** It is not the ID of the room.
3. `token` is your API token. You can the "My info" link next to the "Settings" tab.
"""
def send(self, payload):
campfire = Campfire(self.options['subdomain'], self.options['token'])
room = campfire.find_room_by_name(self.options['room'])
if payload['model'] == 'Comment':
message = '%s %s. commented "%s" on %s "%s" (#%s) %s' % (
payload['attributes']['created_by']['first_name'],
payload['attributes']['created_by']['last_name'][0],
'%s...' % payload['attributes']['body'][0:50],
payload['attributes']['item']['type'],
payload['attributes']['item']['title'],
payload['attributes']['item']['number'],
payload['attributes']['item']['short_url'])
elif payload['model'] == 'Item':
message = '%s %s. created the %s "%s" (#%s) %s' % (
payload['attributes']['created_by']['first_name'],
payload['attributes']['created_by']['last_name'][0],
payload['attributes']['type'],
payload['attributes']['title'],
payload['attributes']['number'],
payload['attributes']['short_url'])
if payload['attributes']['assigned_to'] and \
payload['attributes']['assigned_to']['id'] != \
payload['attributes']['created_by']['id']:
message += ' and assigned it to %s %s.' % (
payload['attributes']['assigned_to']['first_name'],
payload['attributes']['assigned_to']['last_name'][0])
elif payload['model'] == 'Block':
message = '%s %s. indicated the %s "%s" (#%s) %s is blocked on the %s "%s" (#%s) %s' % (
payload['attributes']['user']['first_name'],
payload['attributes']['user']['last_name'][0],
payload['attributes']['blocked']['type'],
payload['attributes']['blocked']['title'],
payload['attributes']['blocked']['number'],
payload['attributes']['blocked']['short_url'],
payload['attributes']['item']['type'],
payload['attributes']['item']['title'],
payload['attributes']['item']['number'],
payload['attributes']['item']['short_url'])
if payload['attributes']['item']['assigned_to']:
message += ', which is owned by %s %s.' % (
payload['attributes']['item']['assigned_to']['first_name'],
payload['attributes']['item']['assigned_to']['last_name'][0])
elif payload['model'] == 'Favorite':
message = '%s %s. favorited the %s "%s" (#%s) %s' % (
payload['attributes']['user']['first_name'],
payload['attributes']['user']['last_name'][0],
payload['attributes']['item']['type'],
payload['attributes']['item']['title'],
payload['attributes']['item']['number'],
payload['attributes']['item']['short_url'])
elif payload['model'] == 'Deploy':
message = '%s %s. deployed %s items to %s.' % (
payload['attributes']['user']['first_name'],
payload['attributes']['user']['last_name'][0],
len(payload['attributes']['items']),
payload['attributes']['environment'])
else:
message = None
if not message:
return
room.join()
result = room.speak(message)