Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

github: Refactor dispatcher to work with any callable.

This will allow us to dispatch events to different methods on the
same object.
  • Loading branch information...
commit 63c69324ea634893ed6c7b3efcb9a4ad5ccc5580 1 parent 9d0f4a6
@spladug authored
Showing with 9 additions and 5 deletions.
  1. +9 −5 harold/plugins/github.py
View
14 harold/plugins/github.py
@@ -100,13 +100,13 @@ def dispatch(self, parsed):
self._dispatch_bundle(parsed, repository, branch, commits)
-class PullRequestDispatcher(object):
+class Salon(object):
def __init__(self, config, bot, shortener):
self.config = config
self.bot = bot
self.shortener = shortener
- def dispatch(self, parsed):
+ def dispatch_pullrequest(self, parsed):
action = parsed["action"]
if action != "opened":
return
@@ -135,9 +135,13 @@ class GitHubListener(ProtectedResource):
def __init__(self, config, http, bot):
ProtectedResource.__init__(self, http)
shortener = UrlShortener()
+
+ push_dispatcher = PushDispatcher(config, bot, shortener)
+ salon = Salon(config, bot, shortener)
+
self.dispatchers = {
- "push": PushDispatcher(config, bot, shortener),
- "pull_request": PullRequestDispatcher(config, bot, shortener),
+ "push": push_dispatcher.dispatch,
+ "pull_request": salon.dispatch_pullrequest,
}
def _handle_request(self, request):
@@ -147,7 +151,7 @@ def _handle_request(self, request):
if dispatcher:
post_data = request.args['payload'][0]
parsed = json.loads(post_data)
- dispatcher.dispatch(parsed)
+ dispatcher(parsed)
def make_plugin(config, http, irc):
Please sign in to comment.
Something went wrong with that request. Please try again.