-
Notifications
You must be signed in to change notification settings - Fork 28
/
hipchat.py
45 lines (35 loc) · 1.61 KB
/
hipchat.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
from buildbot.status.base import StatusReceiverMultiService
from buildbot.status.builder import Results, SUCCESS
import os, urllib
class HipChatStatusPush(StatusReceiverMultiService):
def __init__(self, api_token, room_id, localhost_replace=False, **kwargs):
StatusReceiverMultiService.__init__(self)
self.api_token = api_token
self.room_id = room_id
self.localhost_replace = localhost_replace
def setServiceParent(self, parent):
StatusReceiverMultiService.setServiceParent(self, parent)
self.master_status = self.parent
self.master_status.subscribe(self)
self.master = self.master_status.master
def disownServiceParent(self):
self.master_status.unsubscribe(self)
self.master_status = None
for w in self.watched:
w.unsubscribe(self)
return StatusReceiverMultiService.disownServiceParent(self)
def builderAdded(self, name, builder):
return self # subscribe to this builder
def buildFinished(self, builderName, build, result):
url = self.master_status.getURLForThing(build)
if self.localhost_replace:
url = url.replace("//localhost", "//%s" % self.localhost_replace)
message = urllib.quote("<a href='%s'>%s</a> %s" % (url, builderName, Results[result].upper()))
if result == SUCCESS:
color = "green"
notify = "0"
else:
color = "red"
notify = "1"
# Yes, we are in Twisted and shouldn't do os.system :)
os.system('curl -d "room_id=%s&from=Buildbot&message=%s&color=%s¬ify=%s" https://api.hipchat.com/v1/rooms/message?auth_token=%s&format=json' % (self.room_id, message, color, notify, self.api_token))