mmueller / supybot-git

A Git plugin for Supybot (a Python IRC bot)
45 stars 24 forks source link

Supybot Git Plugin

This is a plugin for the IRC bot Supybot that introduces the ability to monitor Git repositories. Features:

NEWS

November 17, 2012

Interface changes:

Dependencies

This plugin depends on the Python packages:

Dependencies are also listed in requirements.txt. You can install them with the command pip install -r requirements.txt.

Configuration

The Git plugin has a few standard configuration settings, but the primary configuration - where the repositories are defined - lives in an INI file. By default, it will look for the file 'git.ini' in the directory where you run Supybot. You can override this with "config plugins.Git.configFile /path/to/file".

Here is an example of a repository definition:

[Prototype]
short name = prototype
url = https://github.com/sstephenson/prototype.git
commit link = https://github.com/sstephenson/prototype/commit/%c
channels = #prototype

Most of this will be self-explanatory. This defines a repository for the Prototype JavaScript library, so the Git plugin will be able to fetch a copy of it and display commits as they happen.

Let's break down the possible settings:

Commit Messages

Commit messages are produced from a general format string that you define. It uses the following substitution parameters:

%a       Author name
%b       Branch being watched
%c       Commit SHA (first 7 digits)
%C       Commit SHA (entire 40 digits)
%e       Author email
%l       Link to view commit on the web
%m       Commit message (first line only)
%n       Name of repository (config section heading)
%s       Short name of repository
%u       Git URL for repository
%(fg)    IRC color code (foreground only)
%(fg,bg) IRC color code (foreground and background)
%!       Toggle bold
%r       Reset text color and attributes
%%       A literal percent sign.

The format string can span multiple lines, in which case, the plugin will output multiple messages per commit. Here is a format string that I am partial to:

commit message = %![%!%(14)%s%(15)%!|%!%(14)%b%(15)%!|%!%(14)%a%(15)%!]%! %m
                 View%!:%! %(4)%l

As noted above, the default is a simpler version of this:

commit message = [%s|%b|%a] %m

Leading spaces in any line of the message are discarded, so you can format it nicely in the file.

Configurable Values

As mentioned above, there are a few things that can be configured within the Supybot configuration framework. For relative paths, they are relative to where Supybot is invoked. If you're unsure what that might be, just set them to absolute paths. The settings are found within supybot.plugins.Git:

How Notification Works

The first time a repository is loaded from the INI file, a clone will be performed and saved in the repoDir defined above.

Warning #1: If the repository is big and/or the network is slow, the first load may take a very long time!

Warning #2: If the repositories you track are big, this plugin will use a lot of disk space for its local clones.

After this, the poll operation involves a fetch (generally pretty quick), and then a check for any commits that arrived since the last check.

Repository clones are never deleted. If you decide to stop tracking one, you may want to go manually delete it to free up disk space.

Command List

As usual with Supybot plugins, you can call these commands by themselves or with the plugin name prefix, e.g. @git log. The latter form is only necessary if another plugin has a command called log as well, causing a conflict.

Known Bugs

In Supybot 0.83.4.1, the Owner plugin has a log command that might interfere with this plugin's log command. Not only that, but Owner's log is broken, and raises this exception:

TypeError: 'NoneType' object is not callable

If you see this, the simplest workaround is to set Git as the primary plugin to handle the log command:

@defaultplugin log Git

Alternatively, specify @git log instead of just @log when calling. This was reported as issue #9.