Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added Git plugin

  • Loading branch information...
commit 7bd99ed95c59def924b325253af13c0952e8c244 1 parent 11a93f3
Michael B. Klein authored September 13, 2010
1  .gitignore
... ...
@@ -0,0 +1 @@
  1
+*.pyc
1  plugins/Git/README.txt
... ...
@@ -0,0 +1 @@
  1
+Insert a description of your plugin here, with any notes, etc. about using it.
66  plugins/Git/__init__.py
... ...
@@ -0,0 +1,66 @@
  1
+###
  2
+# Copyright (c) 2010, Michael B. Klein
  3
+# All rights reserved.
  4
+#
  5
+# Redistribution and use in source and binary forms, with or without
  6
+# modification, are permitted provided that the following conditions are met:
  7
+#
  8
+#   * Redistributions of source code must retain the above copyright notice,
  9
+#     this list of conditions, and the following disclaimer.
  10
+#   * Redistributions in binary form must reproduce the above copyright notice,
  11
+#     this list of conditions, and the following disclaimer in the
  12
+#     documentation and/or other materials provided with the distribution.
  13
+#   * Neither the name of the author of this software nor the name of
  14
+#     contributors to this software may be used to endorse or promote products
  15
+#     derived from this software without specific prior written consent.
  16
+#
  17
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  18
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  21
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  24
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  25
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  27
+# POSSIBILITY OF SUCH DAMAGE.
  28
+
  29
+###
  30
+
  31
+"""
  32
+Add a description of the plugin (to be presented to the user inside the wizard)
  33
+here.  This should describe *what* the plugin does.
  34
+"""
  35
+
  36
+import supybot
  37
+import supybot.world as world
  38
+
  39
+# Use this for the version of this plugin.  You may wish to put a CVS keyword
  40
+# in here if you're keeping the plugin in CVS or some similar system.
  41
+__version__ = ""
  42
+
  43
+# XXX Replace this with an appropriate author or supybot.Author instance.
  44
+__author__ = supybot.authors.unknown
  45
+
  46
+# This is a dictionary mapping supybot.Author instances to lists of
  47
+# contributions.
  48
+__contributors__ = {}
  49
+
  50
+# This is a url where the most recent plugin package can be downloaded.
  51
+__url__ = '' # 'http://supybot.com/Members/yourname/Codebase/download'
  52
+
  53
+import config
  54
+import plugin
  55
+reload(plugin) # In case we're being reloaded.
  56
+# Add more reloads here if you add third-party modules and want them to be
  57
+# reloaded when this plugin is reloaded.  Don't forget to import them as well!
  58
+
  59
+if world.testing:
  60
+    import test
  61
+
  62
+Class = plugin.Class
  63
+configure = config.configure
  64
+
  65
+
  66
+# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
49  plugins/Git/config.py
... ...
@@ -0,0 +1,49 @@
  1
+###
  2
+# Copyright (c) 2010, Michael B. Klein
  3
+# All rights reserved.
  4
+#
  5
+# Redistribution and use in source and binary forms, with or without
  6
+# modification, are permitted provided that the following conditions are met:
  7
+#
  8
+#   * Redistributions of source code must retain the above copyright notice,
  9
+#     this list of conditions, and the following disclaimer.
  10
+#   * Redistributions in binary form must reproduce the above copyright notice,
  11
+#     this list of conditions, and the following disclaimer in the
  12
+#     documentation and/or other materials provided with the distribution.
  13
+#   * Neither the name of the author of this software nor the name of
  14
+#     contributors to this software may be used to endorse or promote products
  15
+#     derived from this software without specific prior written consent.
  16
+#
  17
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  18
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  21
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  24
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  25
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  27
+# POSSIBILITY OF SUCH DAMAGE.
  28
+
  29
+###
  30
+
  31
+import supybot.conf as conf
  32
+import supybot.registry as registry
  33
+
  34
+def configure(advanced):
  35
+    # This will be called by supybot to configure this module.  advanced is
  36
+    # a bool that specifies whether the user identified himself as an advanced
  37
+    # user or not.  You should effect your configuration by manipulating the
  38
+    # registry as appropriate.
  39
+    from supybot.questions import expect, anything, something, yn
  40
+    conf.registerPlugin('Git', True)
  41
+
  42
+
  43
+Git = conf.registerPlugin('Git')
  44
+# This is where your configuration variables (if any) should go.  For example:
  45
+# conf.registerGlobalValue(Codebase, 'someConfigVariableName',
  46
+#     registry.Boolean(False, """Help for someConfigVariableName."""))
  47
+
  48
+
  49
+# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
1  plugins/Git/local/__init__.py
... ...
@@ -0,0 +1 @@
  1
+# Stub so local is a module, used for third-party modules
106  plugins/Git/plugin.py
... ...
@@ -0,0 +1,106 @@
  1
+###
  2
+# Copyright (c) 2010, Michael B. Klein
  3
+# All rights reserved.
  4
+#
  5
+# Redistribution and use in source and binary forms, with or without
  6
+# modification, are permitted provided that the following conditions are met:
  7
+#
  8
+#   * Redistributions of source code must retain the above copyright notice,
  9
+#     this list of conditions, and the following disclaimer.
  10
+#   * Redistributions in binary form must reproduce the above copyright notice,
  11
+#     this list of conditions, and the following disclaimer in the
  12
+#     documentation and/or other materials provided with the distribution.
  13
+#   * Neither the name of the author of this software nor the name of
  14
+#     contributors to this software may be used to endorse or promote products
  15
+#     derived from this software without specific prior written consent.
  16
+#
  17
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  18
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  21
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  24
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  25
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  27
+# POSSIBILITY OF SUCH DAMAGE.
  28
+
  29
+###
  30
+
  31
+import supybot.utils as utils
  32
+from supybot.commands import *
  33
+import supybot.plugins as plugins
  34
+import supybot.ircutils as ircutils
  35
+import supybot.callbacks as callbacks
  36
+
  37
+import re
  38
+import simplejson
  39
+import supybot.utils.web as web
  40
+
  41
+HEADERS = dict(ua = 'Zoia/1.0 (Supybot/0.83; Github Plugin; http://code4lib.org/irc)')
  42
+
  43
+class Git(callbacks.Plugin):
  44
+    """Git/Github-related commands"""
  45
+
  46
+    def _fetch_json(self, url):
  47
+        doc = web.getUrl(url, headers=HEADERS)
  48
+        try:
  49
+            json = simplejson.loads(doc)
  50
+        except ValueError:
  51
+            return None
  52
+        return json
  53
+
  54
+    def commits(self, irc, msg, args, opts, query):
  55
+      """[--author author] [--repo repo] [--branch branch] [--show number] [query]
  56
+      
  57
+      Display the last <number> log messages matching <query> from <author>'s commits to <branch> of <repo> on github"""
  58
+      repo = 'gsf/supybot-plugins'
  59
+      branch = 'master'
  60
+      author = ''
  61
+      path = None
  62
+      commits = 1
  63
+      for (opt, arg) in opts:
  64
+          if opt == 'repo':
  65
+            repo = arg
  66
+          if opt == 'branch':
  67
+            branch = arg
  68
+          if opt == 'path':
  69
+            path = arg
  70
+          if opt == 'show':
  71
+            commits = arg
  72
+          if opt == 'author':
  73
+            author = arg
  74
+      
  75
+      if path is None:
  76
+        branch_path = branch
  77
+      else:
  78
+        branch_path = '%s/%s' % (branch,path)
  79
+      data = self._fetch_json('http://github.com/api/v2/json/commits/list/%s/%s?author=%s' % (repo,branch_path,author))
  80
+
  81
+      if query is None:
  82
+        matching_commits = data['commits']
  83
+      else:
  84
+        pattern = re.compile(query)
  85
+        matching_commits = filter(lambda c: pattern.search(c['message']),data['commits'])
  86
+      
  87
+      found = min(commits,len(matching_commits))
  88
+      if found == 0:
  89
+        irc.reply('No matching commits found in %s:%s' % (repo, branch))
  90
+      else:
  91
+        for i in range(found):
  92
+          commit = matching_commits[i]
  93
+          (date, time) = commit['committed_date'][0:19].split('T')
  94
+          commit.update({ 'display_date' : date, 'display_time' : time, 'display_committer' : commit['committer']['login'] })
  95
+          commit['message'] = commit['message'].split('git-svn-id')[0].strip()
  96
+          log_line = "[%(display_date)10.10s %(display_time)8.8s] [%(display_committer)s] %(message)s" % commit
  97
+          log_line = re.sub(r'\n',' ',log_line)
  98
+          irc.reply(log_line, prefixNick=False)
  99
+    commits = wrap(commits, [getopts({'repo':'somethingWithoutSpaces',
  100
+      'branch':'somethingWithoutSpaces','path':'somethingWithoutSpaces',
  101
+      'show':'int','author':'somethingWithoutSpaces'}),optional('text')])
  102
+
  103
+Class = Git
  104
+
  105
+
  106
+# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
37  plugins/Git/test.py
... ...
@@ -0,0 +1,37 @@
  1
+###
  2
+# Copyright (c) 2010, Michael B. Klein
  3
+# All rights reserved.
  4
+#
  5
+# Redistribution and use in source and binary forms, with or without
  6
+# modification, are permitted provided that the following conditions are met:
  7
+#
  8
+#   * Redistributions of source code must retain the above copyright notice,
  9
+#     this list of conditions, and the following disclaimer.
  10
+#   * Redistributions in binary form must reproduce the above copyright notice,
  11
+#     this list of conditions, and the following disclaimer in the
  12
+#     documentation and/or other materials provided with the distribution.
  13
+#   * Neither the name of the author of this software nor the name of
  14
+#     contributors to this software may be used to endorse or promote products
  15
+#     derived from this software without specific prior written consent.
  16
+#
  17
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  18
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  21
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  24
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  25
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  27
+# POSSIBILITY OF SUCH DAMAGE.
  28
+
  29
+###
  30
+
  31
+from supybot.test import *
  32
+
  33
+class CodebaseTestCase(PluginTestCase):
  34
+    plugins = ('Codebase',)
  35
+
  36
+
  37
+# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:

0 notes on commit 7bd99ed

Please sign in to comment.
Something went wrong with that request. Please try again.