Skip to content

Commit

Permalink
Add SHA snarfing of in-channel messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Mueller committed Sep 2, 2011
1 parent 27e332e commit 1b6f1b4
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion plugin.py
Expand Up @@ -85,6 +85,13 @@ def fetch(self):
"Contact git repository and update last_commit appropriately."
self.repo.git.fetch()

def get_commit(self, sha):
"Fetch the commit with the given SHA. Returns None if not found."
try:
return self.repo.commit(sha)
except ValueError:
return None

def get_new_commits(self):
result = self.repo.commits_between(self.last_commit, self.branch)
self.last_commit = self.repo.commit(self.branch)
Expand Down Expand Up @@ -163,9 +170,11 @@ def format_message(self, commit):
result.append(outline)
return result

class Git(callbacks.Plugin):
class Git(callbacks.PluginRegexp):
"Please see the README file to configure and use this plugin."

threaded = True
unaddressedRegexps = [ '_snarf' ]

def __init__(self, irc):
self.__parent = super(Git, self)
Expand Down Expand Up @@ -274,6 +283,17 @@ def _read_config(self):
self.repositories.append(
Repository(repo_dir, section, parser.items(section)))

def _snarf(self, irc, msg, match):
r"""\b(?P<sha>[0-9a-f]{6,40})\b"""
sha = match.group('sha')
channel = msg.args[0]
repositories = filter(lambda r: r.channel == channel, self.repositories)
for repository in repositories:
commit = repository.get_commit(sha)
if commit:
self._display_commits(irc, repository, [commit])
break

def _start_polling(self):
self.poll_period = self.registryValue('pollPeriod')
if self.poll_period:
Expand Down

0 comments on commit 1b6f1b4

Please sign in to comment.