man SVN::Notify () - Subversion activity notification

Name

SVN::Notify - Subversion activity notification

Synopsis

Use svnnotify in post-commit:

  svnnotify --repos-path "$1" --revision "$2" \
    --to developers@example.com [options]

  svnnotify --repos-path "$1" --revision "$2" \
    --to-cx-regex i10n@example.com=I10N [options]

Use the class in a custom script:

  use SVN::Notify;

  my $notifier = SVN::Notify->new(%params);
  $notifier->prepare;
  $notifier->execute;

Description

This class may be used for sending email messages for Subversion repository activity. There are a number of different modes supported, and SVN::Notify is fully subclassable, to easily add new functionality. By default, A list of all the files affected by the commit will be assembled and listed in a single message. An additional option allows diffs to be calculated for the changes and either appended to the message or added as an attachment. See the CWwith_diff and CWattach_diff options below.

Usage

To use SVN::Notify, simply add a call to svnnotify to your Subversion repository's post-commit script. This script lives at the root of the repository directory; consult the documentation in post-commit.tmpl for details. Make sure that you specify the complete path to svnnotify, as well as to svnlook and sendmail in the options passed to svnnotify so that everything executes properly.

Class Interface

Constructor

new

  my $notifier = SVN::Notify->new(%params);

Constructs and returns a new SVN::Notify object. This object is a handle on the whole process of collecting metadata and content for the commit email and then sending it. As such, it takes a number of parameters to affect that process.

Each of these parameters has a corresponding command-line option that can be passed to svnnotify. The options have the same names as these parameters, but any underscores you see here should be replaced with dashes when passed to svnnotify. Each also has a corresponding single-character option. All of these are documented here.

Supported parameters:

repos_path
  svnnotify --repos-path "$PATH"
  svnnotify -p "$PATH"
The path to the Subversion repository. The path is passed as the first argument when Subversion executes post-commit. So you can simply pass CW$1 to this parameter if you like. See the documentation in post-commit for details. Required.
revision
  svnnotify --revision "$REV"
  svnnotify -r "$REV"
The revision number for the current commit. The revision number is passed as the second argument when Subversion executes post-commit. So you can simply pass CW$2 to this parameter if you like. See the documentation in post-commit for details. Required.
to
  svnnotify --to commiters@example.com
  svnnotify -t commiters@example.com
The address or addresses to which to send the notification email. To specify multiple addresses, simply put them all into a comma-delimited list suitable for an SMTP From header. This parameter is required unless CWto_regex_map is specified.
to_regex_map
  svnnotify --to-regex-map translate@example.com=L18N \
            -x legal@example.com=License
This parameter specifies a hash reference of email addresses to regular expression strings. SVN::Notify will compile the regular expression strings into regular expression objects, and then send notification messages if and only if the name of one or more of the directories affected by a commit matches the regular expression. This is a good way to have a notification email sent to a particular mail address (or comma-delimited list of addresses) only for certain parts of the subversion tree. This parameter is required unless CWto is specified. The command-line options, CW--to-regex_map and CW-x, can be specified any number of times, once for each entry in the hash to be passed to CWnew(). The value passed to the option must be in the form of the key and the value separated by an equal sign. Consult the Getopt::Long documentation for more information.
from
  svnnotify --from somewhere@example.com
  svnnotify -f elsewhere@example.com
The email address to use in the From line of the email. If not specified, SVN::Notify will use the username from the commit, as returned by CWsvnlook info.
user_domain
  svnnotify --user-domain example.com
  svnnotify -D example.net
A domain name to append to the username for the From header of the email. During a Subversion commit, the username returned by CWsvnlook info is usually something like a Unix login name. SVN::Notify will use this username in the email From header unless the CWfrom parameter is specified. If you wish to have the username take the form of a real email address, specify a domain name and SVN::Notify will append CW\@$domain_name to the username in order to create a real email address. This can be useful if all of your committers have an email address that corresponds to their username at the domain specified by the CWuser_domain parameter.
svnlook
  svnnotify --svnlook /path/to/svnlook
  svnnotify --l /path/to/svnlook
The location of the svnlook executable. The default is /usr/local/bin/svnlook. Specify a different path or set the CW$SVNLOOK environment variable if this is not the location of svnlook on your box. It's important to provide a complete path to svnlook because the environment during the execution of post-commit is anemic, with nary a CW$PATH environment variable to be found. So if svnnotify appears not to be working at all (and Subversion seems loathe to log when it dies!), make sure that you have specified the complete path to a working svnlook executable.
sendmail
  svnnotify --sendmail /path/to/sendmail
  svnnotify --s /path/to/sendmail
The location of the sendmail executable. The default is /usr/sbin/sendmail. Specify a different path or set the CW$SENDMAIL environment variable if this is not the location of sendmail on your box. The same caveats as applied to the location of the svnlook executable apply here.
charset
  svnnotify --charset UTF-8
  svnnotify -c Big5
The character set typically used on the repository for log messages, file names, and file contents. Used to specify the character set in the email Content-Type headers. Defaults to UTF-8.
language
  svnnotify --language fr
  svnnotify -g i-klingon
The language typically used on the repository for log messages, file names, and file contents. Used to specify the email Content-Language header. Undefined by default, meaning that no Content-Language header is output.
with_diff
  svnnotify --with-diff
  svnnotify -d
A boolean value specifying whether or not to include the output of CWsvnlook diff in the notification email. The diff will be inline at the end of the email unless the CWattach_diff parameter specifies a true value.
attach_diff
  svnnotify --attach-diff
  svnnotify -a
A boolean value specifying whether or not to attach the output of CWsvnlook diff to the notification email. Rather than being inline in the body of the email, this parameter causes SVN::Notify to attach the diff as a separate file, named for the user who triggered the commit and the date and time UTC at which the commit took place. Specifying this parameter to a true value implicitly sets the CWwith_diff parameter to a true value.
reply_to
  svnnotify --reply-to devlist@example.com
  svnnotify --R developers@example.net
The email address to use in the Reply-To header of the notification email. No Reply-To header will be added to the email if no value is specified for the CWreply_to parameter.
subject_prefix
  svnnotify --subject-prefix [Devlist]
  svnnotify -P (Our-Developers)
An optional string to prepend to the beginning of the subject line of the notification email.
subject_cx
  svnnotify --subject-cx
  svnnotify -C
A boolean value indicating whether or not to include a the context of the commit in the subject line of the email. In a commit that affects multiple files, the context will be the name of the shortest directory affected by the commit. This should indicate up to how high up the Subversion repository tree the commit had an effect. If the commit affects a single file, then the context will simply be the name of that file.
strip_cx_regex
  svnnotify --strip-cx-regex '^trunk/'
  svnnotify --strip-cx-regex '^trunk/' --strip-cx-regex '^branches/'
  svnnotify -X '^trunk'
  svnnotify -X '^trunk' -X '^branches'
One or more regular expressions to be used to strip out parts of the subject context. This can be useful for very deep Subversion trees, where the commits you're sending will always be sent from a particular subtree, so you'd like to remove part of the tree. Used only if CWsubject_cx is set to a true value. Pass an array reference if calling CWnew() directly.
no_first_line
  svnnotify --no-first-line
  svnnotify --O
Omits the first line of the log message from the subject. This is most useful when used in combination with the CWsubject_cx parameter, so that just the commit context is displayed in the subject and no part of the log message.
max_sub_length
  svnnotify --max-sub-length 72
  svnnotify -i 76
The maximum length of the notification email subject line. SVN::Notify includes the first line of the commit log message, or the first sentence of the message (defined as any text up to the string . ), whichever is shorter. This could potentially be quite long. To prevent the subject from being over a certain number of characters, specify a maximum length here, and SVN::Notify will truncate the subject to the last word under that length.
handler
  svnnotify --handler HTML
  svnnotify -H HTML
Specify the subclass of SVN::Notify to be constructed and returned, and therefore to handle the notification. Of course you can just use a subclass directly, but this parameter is designed to make it easy to just use CWSVN::Notify->new without worrying about loading subclasses, such as in svnnotify.
svnweb_url
  svnnotify --svnweb-url 'http://svn.example.com/index.cgi/revision/?rev=%s'
  svnnotify -S 'http://svn.example.net/index.cgi/revision/?rev=%s'
If a URL is specified for this parameter, then it will be used to create a link to the SVN::Web URL corresponding to the current revision number. The URL must have the %s format where the Subversion revision number should be put into the URL. Mutually exclusive with CWviewcvs_url.
viewcvs_url
  svnnotify --viewcvs-url 'http://svn.example.com/viewcvs/?rev=%s&view=rev'
  svnnotify -U 'http://svn.example.net/viewcvs?rev=%s&view=rev'
If a URL is specified for this parameter, then it will be used to create a link to the ViewCVS URL corresponding to the current revision number. The URL must have the %s format where the Subversion revision number should be put into the URL. Mutually exclusive with CWsvnweb_url.
rt_url
  svnnotify --rt-url 'http://rt.cpan.org/NoAuth/Bugs.html?id=%s'
  svnnotify -T 'http://rt.perl.org/NoAuth/Bugs.html?id=%s'
The URL of a Request Tracker (RT) server. If passed in, any strings in the log message of the form Ticket # 12 or ticket 6 or even Ticket#1066 will be turned into links to the RT server. The URL must have the %s format where the RT ticket ID should be put into the URL.
bugzilla_url
  svnnotify --bugzilla-url 'http://bugzilla.mozilla.org/show_bug.cgi?id=%s'
  svnnotify -B 'http://bugs.bricolage.cc/show_bug.cgi?id=%s'
The URL of a Bugzilla server. If passed in, any strings in the log message of the form Bug # 12 or bug 6 or even Bug#1066 will be turned into links to the Bugzilla server. The URL must have the %s format where the Bugzilla Bug ID should be put into the URL.
jira_url
  svnnotify --jira-url 'http://jira.atlassian.com/secure/ViewIssue.jspa?key=%s'
  svnnotify -J 'http://nagoya.apache.org/jira/secure/ViewIssue.jspa?key=%s'
The URL of a JIRA server. If passed in, any strings in the log message that appear to be JIRA keys (such as JRA-1234) will be turned into links to the JIRA server. The URL must have the %s format where the Jira key should be put into the URL.
gnats_url
  svnnotify --gnats-url 'http://gnatsweb.example.com/cgi-bin/gnatsweb.pl?cmd=view&pr=%s'
  svnnotify -G 'http://gnatsweb.example.com/cgi-bin/gnatsweb.pl?cmd=view&pr=%s'
The URL of a GnatsWeb server. If passed in, any strings in the log message that appear to be GNATS PRs (such as PR 1234) will be turned into links to the GnatsWeb server. The URL must have the %s format where the GNATS PR number should be put into the URL.
ticket_url
  svnnotify --ticket-url 'http://ticket.example.com/showticket.html?id=%s'
The URL of a custom ticket system. If passed in, any strings in the log message that match CWticket_regex will be turned into links to the custom ticket system. The URL must have the %s format where the first match (usually the ticket identifier) in the regex should be put into the URL.
ticket_regex
  svnnotify --ticket-regex '\[?#\s*(\d+)\s*\]?'
The regex to match a ticket tag of a custom ticket system. This should return a single match to be interpolated into the CWticket_url option. The example shown matches [#1234] or #1234 or [# 1234]. This regex should be as specific as possible, preferably wrapped in \b tags and the like.
verbose
  svnnotify --verbose -V
A value between 0 and 3 specifying how verbose SVN::Notify should be. The default is 0, meaning that SVN::Notify will be silent. A value of 1 causes SVN::Notify to output some information about what it's doing, while 2 and 3 each cause greater verbosity. To set the verbosity on the command line, simply pass the CW--verbose or CW-V option once for each level of verbosity, up to three times.
boundary
The boundary to use between email body text and attachments. This is normally generated by SVN::Notify.
subject
The subject of the email to be sent. This attribute is normally generated by CWprepare_subject().

Class Methods

content_type

  my $content_type = SVN::Notify->content_type;

Returns the content type of the notification message, text/plain. Used to set the Content-Type header for the message.

register_attributes

  SVN::Notify::Subclass->register_attributes(
      foo_attr => 'foo-attr=s',
      bar      => 'bar',
      bat      => undef,
  );

This class method is used by subclasses to register new attributes. Pass in a list of key/value pairs, where the keys are the attribute names and the values are option specifications in the format required by Getopt::Long. SVN::Notify will create accessors for each attribute, and if the corresponding value is defined, it will be used by the CWget_options() class method to get a command-line option value.

See <LSVN::Notify::HTML|SVN::Notify::HTML> for an example usage of CWregister_attributes().

get_options

  my $options = SVN::Notify->get_options;

Parses the command-line options in CW@ARGV to a hash reference suitable for passing as the parameters to CWnew(). See new for a complete list of the supported parameters and their corresponding command-line options.

This method use Getopt::Long to parse CW@ARGV. It then looks for a CWhandler option and, if it finds one, loads the appropriate subclass and parsed any options it requires from CW@ARGV. Subclasses should use CWregister_attributes() to register any attributes and options they require.

file_label_map

  my $map = SVN::Notify->file_label_map;

Returns a hash reference of the labels to be used for the lists of files. A hash reference of file lists is stored in the CWfiles attribute after CWprepare_files() has been called. The hash keys in that list correspond to Subversion status codes, and these are mapped to their appropriate labels by the hash reference returned by this method:

  { U => 'Modified Paths',
    A => 'Added Paths',
    D => 'Removed Paths',
    _ => 'Property Changed'
  }

Instance Interface

Instance Methods

prepare

  $notifier->prepare;

Prepares the SVN::Notify object, collecting all the data it needs in preparation for sending the notification email. Really it's just a shortcut for:

  $notifier->prepare_recipients;
  $notifier->prepare_contents;
  $notifier->prepare_files;
  $notifier->prepare_subject;

Only it returns after the call to CWprepare_recipients() if there are no recipients (that is, as when recipients are specified solely by the CWto_regex_map parameter and none of the regular expressions match any of the affected directories).

prepare_recipients

  $notifier->prepare_recipients;

Collects and prepares a list of the notification recipients. The recipients are a combination of the value passed to the CWto parameter as well as any email addresses specified as keys in the hash reference passed CWto_regex_map parameter, where the regular expressions stored in the values match one or more of the names of the directories affected by the commit.

If the subject_cx parameter to CWnew() has a true value, CWprepare_recipients() also determines the directory name to use for the context.

prepare_contents

  $notifier->prepare_contents;

Prepares the contents of the commit message, including the name of the user who triggered the commit (and therefore the contents of the From header to be used in the email) and the log message.

prepare_files

  $notifier->prepare_files;

Prepares the lists of files affected by the commit, sorting them into their categories: modified files, added files, and deleted files. It also compiles a list of files wherein a property was set, which might have some overlap with the list of modified files (if a single commit both modified a file and set a property on it).

If the CWsubject_cx parameter was specified and a single file was affected by the commit, then CWprepare_files() will also specify that file name as the context to be used in the subject line of the commit email.

prepare_subject

  $notifier->prepare_subject;

Prepares the subject line for the notification email. This method must be called after CWprepare_recipients() and CWprepare_files(), since each of those methods potentially sets up the context for use in the the subject line. The subject may have a prefix defined by the CWsubject_prefix parameter to CWnew(), it has the revision number, it might have the context if the CWsubject_cx specified a true value, and it will have the first sentence or line of the commit, whichever is shorter. The subject may then be truncated to the maximum length specified by the CWmax_sub_length parameter.

execute

  $notifier->execute;

Sends the notification message. This involves opening a file handle to sendmail and passing it to CWoutput(). This is the main method used to send notifications or execute any other actions in response to Subversion activity.

output

  $notifier->output($file_handle);

Called internally by CWexecute() to output a complete email message. The file handle passed is a piped connection to sendmail, so that CWoutput() and its related methods can print directly to sendmail.

Really CWoutput() is a simple wrapper around a number of other method calls. It is thus essentially a shortcut for:

    $notifier->output_headers($out);
    $notifier->output_content_type($out);
    $notifier->start_body($out);
    $self->output_metadata($out);
    $notifier->output_log_message($out);
    $notifier->output_file_lists($out);
    if ($notifier->with_diff) {
        if ($notifier->attach_diff) {
            $notifier->end_body($out);
            $notifier->output_attached_diff($out);
        } else {
            $notifier->output_diff($out);
            $notifier->end_body($out);
        }
    } else {
        $notifier->end_body($out);
    }
    $notifier->end_message($out);

output_headers

  $notifier->output_headers($file_handle);

Outputs the headers for the notification message. If the CWattach_diff parameter was set to true, then a boundary string will be generated and the Content-Type set to multipart/mixed and stored as the CWboundary attribute.

output_content_type

  $notifier->output_content_type($file_handle);

Outputs the content type and transfer encoding headers. These demarcate the body of the message. This method outputs the content type returned by CWcontent_type(), the character set specified by the CWcharset attribute, and a Content-Transfer-Encoding of 8bit. Subclasses can either rely on this functionality or override this method to provide their own content type headers.

start_body

  $notifier->start_body($file_handle);

This method starts the body of the notification message. It doesn't actually do anything in this class, but see subclasses for other behaviors.

output_metadata

  $notifier->output_metadata($file_handle);

This method outputs the metadata of the commit, including the revision number, author (user), and date of the revision. If the CWviewcvs_url or CWsvnweb_url attributes have been set, then the appropriate URL(s) for the revision will also be output.

output_log_message

  $notifier->output_log_message($file_handle);

Outputs the commit log message, as well as the label Log Message.

output_file_lists

  $notifier->output_log_message($file_handle);

Outputs the lists of modified, added, and deleted files, as well as the list of files for which properties were changed. The labels used for each group are pulled in from the CWfile_label_map() class method.

end_body

  $notifier->end_body($file_handle);

Closes out the body of the email. Designed to be called when the body of the message is complete, and before any call to CWoutput_attached_diff().

output_diff

  $notifier->output_diff($out_file_handle, $diff_file_handle);

Reads diff data from CW$diff_file_handle and outputs it to to CW$out_file_handle.

output_attached_diff

  $notifier->output_attached_diff($out_file_handle, $diff_file_handle);

Reads diff data from CW$diff_file_handle and outputs it to to CW$out_file_handle as an attachment.

end_message

  $notifier->end_message($file_handle);

Outputs the final part of the message,. In this case, that means only a boundary if the CWattach_diff parameter is true. Designed to be called after any call to CWoutput_attached_diff().

Accessors

repos_path

  my $repos_path = $notifier->repos_path;
  $notifier = $notifier->repos_path($repos_path);

Gets or sets the value of the CWrepos_path attribute.

revision

  my $revision = $notifier->revision;
  $notifier = $notifier->revision($revision);

Gets or sets the value of the CWrevision attribute.

to

  my $to = $notifier->to;
  $notifier = $notifier->to($to);

Gets or sets the value of the CWto attribute.

to_regex_map

  my $to_regex_map = $notifier->to_regex_map;
  $notifier = $notifier->to_regex_map($to_regex_map);

Gets or sets the value of the CWto_regex_map attribute, which is a hash reference of email addresses mapped to regular expressions.

from

  my $from = $notifier->from;
  $notifier = $notifier->from($from);

Gets or sets the value of the CWfrom attribute.

user_domain

  my $user_domain = $notifier->user_domain;
  $notifier = $notifier->user_domain($user_domain);

Gets or sets the value of the CWuser_domain attribute.

svnlook

  my $svnlook = $notifier->svnlook;
  $notifier = $notifier->svnlook($svnlook);

Gets or sets the value of the CWsvnlook attribute.

sendmail

  my $sendmail = $notifier->sendmail;
  $notifier = $notifier->sendmail($sendmail);

Gets or sets the value of the CWsendmail attribute.

charset

  my $charset = $notifier->charset;
  $notifier = $notifier->charset($charset);

Gets or sets the value of the CWcharset attribute.

language

  my $language = $notifier->language;
  $notifier = $notifier->language($language);

Gets or sets the value of the CWlanguage attribute.

with_diff

  my $with_diff = $notifier->with_diff;
  $notifier = $notifier->with_diff($with_diff);

Gets or sets the value of the CWwith_diff attribute.

attach_diff

  my $attach_diff = $notifier->attach_diff;
  $notifier = $notifier->attach_diff($attach_diff);

Gets or sets the value of the CWattach_diff attribute.

reply_to

  my $reply_to = $notifier->reply_to;
  $notifier = $notifier->reply_to($reply_to);

Gets or sets the value of the CWreply_to attribute.

subject_prefix

  my $subject_prefix = $notifier->subject_prefix;
  $notifier = $notifier->subject_prefix($subject_prefix);

Gets or sets the value of the CWsubject_prefix attribute.

subject_cx

  my $subject_cx = $notifier->subject_cx;
  $notifier = $notifier->subject_cx($subject_cx);

Gets or sets the value of the CWsubject_cx attribute.

max_sub_length

  my $max_sub_length = $notifier->max_sub_length;
  $notifier = $notifier->max_sub_length($max_sub_length);

Gets or sets the value of the CWmax_sub_length attribute.

svnweb_url

  my $svnweb_url = $notifier->svnweb_url;
  $notifier = $notifier->svnweb_url($svnweb_url);

Gets or sets the value of the CWsvnweb_url attribute. Mutually exclusive with CWviewcvs_url.

viewcvs_url

  my $viewcvs_url = $notifier->viewcvs_url;
  $notifier = $notifier->viewcvs_url($viewcvs_url);

Gets or sets the value of the CWviewcvs_url attribute. Mutually exclusive with CWsvnweb_url.

verbose

  my $verbose = $notifier->verbose;
  $notifier = $notifier->verbose($verbose);

Gets or sets the value of the CWverbose attribute.

bondary

  my $bondary = $notifier->bondary;
  $notifier = $notifier->bondary($bondary);

Gets or sets the value of the CWbondary attribute. This string is normally set by a call to CWoutput_headers(), but may be set ahead of time.

user

  my $user = $notifier->user;
  $notifier = $notifier->user($user);

Gets or sets the value of the CWuser attribute, which is set to the value pulled in from svnlook by the call to CWprepare_contents().

date

  my $date = $notifier->date;
  $notifier = $notifier->date($date);

Gets or sets the value of the CWdate attribute, which is set to the value pulled in from svnlook by the call to CWprepare_contents().

message

  my $message = $notifier->message;
  $notifier = $notifier->message($message);

Gets or sets the value of the CWmessage attribute, which is set to an array reference of strings by the call to CWprepare_contents().

message_size

  my $message_size = $notifier->message_size;
  $notifier = $notifier->message_size($message_size);

Gets or sets the value of the CWmessage_size attribute, which is set to the value pulled in from svnlook by the call to CWprepare_contents().

subject

  my $subject = $notifier->subject;
  $notifier = $notifier->subject($subject);

Gets or sets the value of the CWsubject attribute, which is normally set by a call to CWprepare_subject(), but may be set explicitly.

files

  my $files = $notifier->files;
  $notifier = $notifier->files($files);

Gets or sets the value of the CWfiles attribute, which is set to a hash reference of change type mapped to arrays of strings by the call to CWprepare_files().

See Also

SVN::Notify::HTML
Subclasses SVN::Notify.

Bugs

Please send bug reports to <bug-svn-notify@rt.cpan.org>.

To Do

•
Port to Win32. I think it just needs to use Win32::Process to manage communication with svnlook and sendmail. See comments in the source code.

Author

David Wheeler <david@kineticode.com>

Copyright and License

Copyright (c) 2004-2005 Kineticode, Inc. All Rights Reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.