Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

Commit

Permalink
github: Refactor dispatcher to work with any callable.
Browse files Browse the repository at this point in the history
This will allow us to dispatch events to different methods on the
same object.
  • Loading branch information
spladug committed Oct 9, 2012
1 parent 9d0f4a6 commit 63c6932
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions harold/plugins/github.py
Expand Up @@ -100,13 +100,13 @@ def dispatch(self, parsed):
self._dispatch_bundle(parsed, repository, branch, commits) self._dispatch_bundle(parsed, repository, branch, commits)




class PullRequestDispatcher(object): class Salon(object):
def __init__(self, config, bot, shortener): def __init__(self, config, bot, shortener):
self.config = config self.config = config
self.bot = bot self.bot = bot
self.shortener = shortener self.shortener = shortener


def dispatch(self, parsed): def dispatch_pullrequest(self, parsed):
action = parsed["action"] action = parsed["action"]
if action != "opened": if action != "opened":
return return
Expand Down Expand Up @@ -135,9 +135,13 @@ class GitHubListener(ProtectedResource):
def __init__(self, config, http, bot): def __init__(self, config, http, bot):
ProtectedResource.__init__(self, http) ProtectedResource.__init__(self, http)
shortener = UrlShortener() shortener = UrlShortener()

push_dispatcher = PushDispatcher(config, bot, shortener)
salon = Salon(config, bot, shortener)

self.dispatchers = { self.dispatchers = {
"push": PushDispatcher(config, bot, shortener), "push": push_dispatcher.dispatch,
"pull_request": PullRequestDispatcher(config, bot, shortener), "pull_request": salon.dispatch_pullrequest,
} }


def _handle_request(self, request): def _handle_request(self, request):
Expand All @@ -147,7 +151,7 @@ def _handle_request(self, request):
if dispatcher: if dispatcher:
post_data = request.args['payload'][0] post_data = request.args['payload'][0]
parsed = json.loads(post_data) parsed = json.loads(post_data)
dispatcher.dispatch(parsed) dispatcher(parsed)




def make_plugin(config, http, irc): def make_plugin(config, http, irc):
Expand Down

0 comments on commit 63c6932

Please sign in to comment.