-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.py
146 lines (123 loc) · 5.32 KB
/
plugin.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
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
139
140
141
142
143
144
145
146
###
# Copyright (c) 2011, Chip Childers
# All rights reserved.
#
#
###
import supybot.utils as utils
from supybot.commands import *
import supybot.plugins as plugins
import supybot.ircutils as ircutils
import supybot.callbacks as callbacks
import time
import supybot.ircmsgs as ircmsgs
import supybot.schedule as schedule
from activity import ActivityFeed
from bamboo import BambooFeed
class JiraStudioObserver(callbacks.Plugin):
"""Add the help for "@plugin help JiraStudioObserver" here
This should describe *how* to use this plugin."""
threaded = True
def __init__(self, irc):
self.__parent = super(JiraStudioObserver, self)
self.__parent.__init__(irc)
self.bambooChannel = self.registryValue('channel', value=True)
self.bambooTime = 30
streams = self.registryValue('streams')
self.activityFeeds = []
for stream in streams:
self.activityFeeds.append(ActivityFeed(stream, self.registryValue('username'), self.registryValue('password')))
try:
schedule.removeEvent('myJiraStudioObserverEvent')
except KeyError:
pass
def myEventCaller():
self.bambooEvent(irc)
schedule.addPeriodicEvent(myEventCaller, self.bambooTime, 'myJiraStudioObserverEvent')
self.irc = irc
def bambooEvent(self, irc):
self.getFeedUpdates(irc)
def start(self, irc, msg, args):
"""takes no arguments
A command to start the bamboo watcher."""
# don't forget to redefine the event wrapper
def myEventCaller():
self.bambooEvent(irc)
try:
schedule.addPeriodicEvent(myEventCaller, self.bambooTime, 'myJiraStudioObserverEvent', False)
except AssertionError:
irc.reply('Error: JiraStudioObserver was already running!')
else:
irc.reply('JiraStudioObserver started!')
start = wrap(start)
def stop(self, irc, msg, args):
"""takes no arguments
A command to stop the JiraStudioObserver."""
try:
schedule.removeEvent('myJiraStudioObserverEvent')
except KeyError:
irc.reply('Error: the build watcher wasn\'t running!')
else:
irc.reply('JiraStudioObserver stopped.')
stop = wrap(stop)
def reset(self, irc, msg, args):
"""takes no arguments
Resets the bamboo build watcher. Can be useful if something changes and you want the
updates to reflect that. For example, if you defined the bambooChannel as a
supybot config, and changed it while the bamboo build watcher was running, it would still
keep going on the same channel until you reset it."""
def myEventCaller():
self.bambooEvent(irc)
try:
schedule.removeEvent('myJiraStudioObserverEvent')
except KeyError:
irc.reply('Build watcher wasn\'t running')
schedule.addPeriodicEvent(myEventCaller, self.bambooTime, 'myJiraStudioObserverEvent', False)
irc.reply('Build watcher reset sucessfully!')
reset = wrap(reset)
def anyupdates(self, irc, msg, args):
"""takes no arguments
Checks the observed activity feeds for new updates, and reports any new items
back to the channel."""
if not self.getFeedUpdates(irc, force_latest = True):
irc.queueMsg(ircmsgs.privmsg(self.bambooChannel, "Nothing to update you about."))
anyupdates = wrap(anyupdates)
def getFeedUpdates(self, irc, force_latest=False):
updated = False
for feed in self.activityFeeds:
feed.update_feed()
while 1 == 1:
item = feed.find_next_item()
if item is None:
break
else:
updated = True
irc.queueMsg(ircmsgs.privmsg(self.bambooChannel, item.get_summary()))
return updated
def thanks(self, irc, msg, args):
irc.queueMsg(
ircmsgs.privmsg(
self.bambooChannel,
"You're quite welcome. Want another pint?"))
thanks = wrap(thanks)
def latestbuild(self, irc, msg, args):
"""takes no arguments
Returns the next random number from the random number generator.
"""
#irc.reply('test' + str(self.bambooChannel))
self.getLatest(irc, True)
latestbuild = wrap(latestbuild)
def getLatest(self, irc, force=False):
bb = BambooFeed(self.registryValue('bambooapiurl'), self.registryValue('username'), self.registryValue('password'))
latest = bb.latest
if force or self.lastBuild != latest["results"]["result"][0]["key"]:
irc.queueMsg(ircmsgs.privmsg(self.bambooChannel, "Latest build reported as: " +
str(latest["results"]['result'][0]["lifeCycleState"]) +
" - " +
str(latest["results"]['result'][0]["state"])))
irc.queueMsg(ircmsgs.privmsg(self.bambooChannel, "URL to latest build: " +
"https://mountdiablo.jira.com/builds/browse/" +
str(latest["results"]['result'][0]["key"])))
if str(latest["results"]['result'][0]["lifeCycleState"]) == "Finished":
self.lastBuild = latest["results"]["result"][0]["key"]
Class = JiraStudioObserver