|
NameSVN::Notify - Subversion activity notificationSynopsisUse 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; DescriptionThis 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 add new functionality, and offers comprehensive content filtering to easily modify the format of its messages. 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 "with_diff" and "attach_diff" options below.UsageTo use SVN::Notify, simply add a call to svnnotify to your Subversion repository's post-commit script. This script lives in the hooks directory 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. And if you specify any string options, be sure that they are in the encoding specified by the "--encoding" option, or UTF-8 if you have not specified "--encoding".Windows UsageTo get SVN::Notify to work properly in a post-commit script, you must set the following environment variables, as they will likely not be present inside Apache:
See Windows Subversion + Apache + TortoiseSVN + SVN::Notify HOWTO <http://svn.haxx.se/users/archive-2006-05/0593.shtml> for more detailed information on getting SVN::Notify running on Windows. If you have issues with asynchronous execution, try using HookStart.exe <http://www.koders.com/csharp/fidE2724F44EF2D47F1C0FE76C538006435FA20051D.aspx> to run svnnotify. Class InterfaceConstructornewmy $notifier = SVN::Notify->new(%params); Constructs and returns a new SVN::Notify object. This object is a handle on the whole process of collecting meta data 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. Most also have a corresponding single-character option. On Perl 5.8 and higher, If you pass parameters to "new()", they must be decoded into Perl's internal form if they have any non-ASCII characters. Supported parameters:
Class Methodscontent_typemy $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 "get_options()" class method to get a command-line option value. See <LSVN::Notify::HTML|SVN::Notify::HTML> for an example usage of "register_attributes()". get_options my $options = SVN::Notify->get_options; Parses the command-line options in @ARGV to a hash reference suitable for passing as the parameters to "new()". See "new" for a complete list of the supported parameters and their corresponding command-line options. This method use Getopt::Long to parse @ARGV. It then looks for any "handler" and "filter" options and, if it finds any, loads the appropriate classes and parses any options they requires from @ARGV. Subclasses and filter classes should use "register_attributes()" to register any attributes and options they require. After that, on Perl 5.8 and later, it decodes all of the string option from the encoding specified by the "encoding" option or UTF-8. This allows options to be passed to SVN::Notify in that encoding and end up being displayed properly in the resulting notification message. 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 "files" attribute after "prepare_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' } find_exe my $exe = SVN::Notify->find_exe($exe_name); This method searches through the system path, as well as the extra directories /usr/local/bin and /usr/sbin (because they're common paths for "svnlook" and "sendmail" for an executable file with the name $exe_name. The first one it finds is returned with its full path. If none is found, "find_exe()" returns undef. Instance InterfaceInstance Methodsprepare$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 "prepare_recipients()" if there are no recipients (that is, as when recipients are specified solely by the "to_regex_map" or "to_email_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 "to" parameter as well as any email addresses specified as keys in the hash reference passed "to_regex_map" parameter or values passed to the "to_email_map" parameter, where the corresponding regular expressions stored in the hash matches one or more of the names of the directories affected by the commit. If the subject_cx parameter to "new()" has a true value, "prepare_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 "subject_cx" parameter was specified and a single file was affected by the commit, then "prepare_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 "prepare_recipients()" and "prepare_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 "subject_prefix" parameter to "new()", it has the revision number, it might have the context if the "subject_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 "max_sub_length" parameter. execute $notifier->execute; Sends the notification message. This involves opening a file handle to sendmail or a tied file handle connected to an SMTP server and passing it to "output()". This is the main method used to send notifications or execute any other actions in response to Subversion activity. output $notifier->output($file_handle); $notifier->output($file_handle, $no_headers); Called internally by "execute()" to output a complete email message. The file a file handle, so that "output()" and its related methods can print directly to the email message. The optional second argument, if true, will suppress the output of the email headers. Really "output()" is a simple wrapper around a number of other method calls. It is thus essentially a shortcut for: $notifier->output_headers($out) unless $no_headers; $notifier->output_content_type($out); $notifier->start_body($out); $notifier->output_metadata($out); $notifier->output_log_message($out); $notifier->output_file_lists($out); if ($notifier->with_diff) { my $diff_handle = $self->diff_handle; if ($notifier->attach_diff) { $notifier->end_body($out); $notifier->output_attached_diff($out, $diff_handle); } else { $notifier->output_diff($out, $diff_handle); $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 headers. Should be called only once for a single email message. output_content_type $notifier->output_content_type($file_handle); Outputs the content type and transfer encoding headers. These demarcate the body of the message. If the "attach_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 "boundary" attribute. After that, this method outputs the content type returned by "content_type()", the character set specified by the "encoding" 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, which means that it outputs the contents of the "header" attribute, if there are any. Otherwise it outputs nothing, 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 "author_url" or "revision_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_file_lists($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 "file_label_map()" class method. end_body $notifier->end_body($file_handle); Closes out the body of the email by outputting the contents of the "footer" attribute, if any, and then a couple of newlines. Designed to be called when the body of the message is complete, and before any call to "output_attached_diff()". output_diff $notifier->output_diff($out_file_handle, $diff_file_handle); Reads diff data from $diff_file_handle and outputs it to to $out_file_handle. output_attached_diff $notifier->output_attached_diff($out_file_handle, $diff_file_handle); Reads diff data from $diff_file_handle and outputs it to to $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 "attach_diff" parameter is true. Designed to be called after any call to "output_attached_diff()". run_ticket_map $notifier->run_ticket_map( \&callback, @params ); Loops over the ticket systems you have defined, calling the $callback function for each one, passing to it the regex, url and @params specified as its parameters. run_filters $data = $notifier->run_filters( $output_type => $data ); Runs the filters for $output_type on $data. Used internally by SVN::Notify and by subclasses. filters_for my $filters = $notifier->filters_for( $output_type ); Returns an array reference of of the filters loaded for $output_type. Returns "undef" if there are no filters have been loaded for $output_type. diff_handle my $diff = $notifier->diff_handle; while (<$diff>) { print } Returns a file handle reference providing access to the the commit diff. It will usually be passed as the second argument to "output_diff()" or "output_attached_diff()". Accessorsrepos_pathmy $repos_path = $notifier->repos_path; $notifier = $notifier->repos_path($repos_path); Gets or sets the value of the "repos_path" attribute. revision my $revision = $notifier->revision; $notifier = $notifier->revision($revision); Gets or sets the value of the "revision" attribute. to my $to = $notifier->to; $notifier = $notifier->to($to); my @tos = $notifier->to; $notifier = $notifier->to(@tos); Gets or sets the list of values stored in the "to" attribute. In a scalar context, it returns only the first value in the list, for backwards compatibility with older versions of SVN::Notify. In list context, it of course returns the entire list. Pass in one or more values to set all of the values for the "to" 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 "to_regex_map" attribute, which is a hash reference of email addresses mapped to regular expressions. to_email_map my $to_email_map = $notifier->to_email_map; $notifier = $notifier->to_email_map($to_email_map); Gets or sets the value of the "to_email_map" attribute, which is a hash reference of regular expressions mapped to email addresses. from my $from = $notifier->from; $notifier = $notifier->from($from); Gets or sets the value of the "from" attribute. user_domain my $user_domain = $notifier->user_domain; $notifier = $notifier->user_domain($user_domain); Gets or sets the value of the "user_domain" attribute. svnlook my $svnlook = $notifier->svnlook; $notifier = $notifier->svnlook($svnlook); Gets or sets the value of the "svnlook" attribute. sendmail my $sendmail = $notifier->sendmail; $notifier = $notifier->sendmail($sendmail); Gets or sets the value of the "sendmail" attribute. set_sender my $set_sender = $notifier->set_sender; $notifier = $notifier->set_sender($set_sender); Gets or sets the value of the "set_sender" attribute. smtp my $smtp = $notifier->smtp; $notifier = $notifier->smtp($smtp); Gets or sets the value of the "smtp" attribute. encoding my $encoding = $notifier->encoding; $notifier = $notifier->encoding($encoding); Gets or sets the value of the "encoding" attribute. "charset" is an alias preserved for backward compatibility. svn_encoding my $svn_encoding = $notifier->svn_encoding; $notifier = $notifier->svn_encoding($svn_encoding); Gets or sets the value of the "svn_encoding" attribute. diff_encoding my $diff_encoding = $notifier->diff_encoding; $notifier = $notifier->diff_encoding($diff_encoding); Gets or sets the value of the "diff_encoding" attribute. language my $language = $notifier->language; $notifier = $notifier->language($language); Gets or sets the value of the "language" attribute. env_lang my $env_lang = $notifier->env_lang; $notifier = $notifier->env_lang($env_lang); Gets or sets the value of the "env_lang" attribute, which is set to "$notify->language . '.' . $notify->encoding" when "language" is set, and otherwise is "undef". This attribute is used to set the $LANG environment variable, if it is not already set by the environment, before executing "sendmail". svn_env_lang my $svn_env_lang = $notifier->svn_env_lang; $notifier = $notifier->svn_env_lang($svn_env_lang); Gets or sets the value of the "svn_env_lang" attribute, which is set to "$notify->language . '.' . $notify->svn_encoding" when "language" is set, and otherwise is "undef". This attribute is used to set the $LANG environment variable, if it is not already set by the environment, before executing "svnlook". It is not used for "svnlook diff", however, as the diff itself will be emitted in raw octets except for headers such as "Modified", which need to be in English so that subclasses can parse them. Thus, $LANG is always set to "C" for the execution of "svnlook diff". with_diff my $with_diff = $notifier->with_diff; $notifier = $notifier->with_diff($with_diff); Gets or sets the value of the "with_diff" attribute. attach_diff my $attach_diff = $notifier->attach_diff; $notifier = $notifier->attach_diff($attach_diff); Gets or sets the value of the "attach_diff" attribute. diff_switches my $diff_switches = $notifier->diff_switches; $notifier = $notifier->diff_switches($diff_switches); Gets or sets the value of the "diff_switches" attribute. reply_to my $reply_to = $notifier->reply_to; $notifier = $notifier->reply_to($reply_to); Gets or sets the value of the "reply_to" attribute. add_headers my $add_headers = $notifier->add_headers; $notifier = $notifier->add_headers({ 'X-Accept' => [qw(This That)], 'X-Reject' => 'Me!', }); Gets or sets the value of the "add_headers" attribute, which is a hash reference of the headers to be added to the email message. If one header needs to appear multiple times, simply pass the corresponding hash value as an array reference of each value for the header. Not to be confused with the "header" accessor, which gets and sets text to be included at the beginning of the body of the email message. subject_prefix my $subject_prefix = $notifier->subject_prefix; $notifier = $notifier->subject_prefix($subject_prefix); Gets or sets the value of the "subject_prefix" attribute. subject_cx my $subject_cx = $notifier->subject_cx; $notifier = $notifier->subject_cx($subject_cx); Gets or sets the value of the "subject_cx" attribute. strip_cx_regex my $strip_cx_regex = $notifier->strip_cx_regex; $notifier = $notifier->strip_cx_regex($strip_cx_regex); my @strip_cx_regexs = $notifier->strip_cx_regex; $notifier = $notifier->strip_cx_regex(@strip_cx_regexs); Gets or sets the list of values stored in the "strip_cx_regex" attribute. In a scalar context, it returns only the first value in the list; in list context, it of course returns the entire list. Pass in one or more values to set all of the values for the "strip_cx_regex" 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 "max_sub_length" attribute. max_diff_length my $max_diff_length = $notifier->max_diff_length; $notifier = $notifier->max_diff_length($max_diff_length); Gets or set the value of the "max_diff_length" attribute. author_url my $author_url = $notifier->author_url; $notifier = $notifier->author_url($author_url); Gets or sets the value of the "author_url" attribute. revision_url my $revision_url = $notifier->revision_url; $notifier = $notifier->revision_url($revision_url); Gets or sets the value of the "revision_url" attribute. svnweb_url Deprecated. Pleas use "revision_url()", instead. viewcvs_url Deprecated. Pleas use "revision_url()", instead. verbose my $verbose = $notifier->verbose; $notifier = $notifier->verbose($verbose); Gets or sets the value of the "verbose" attribute. boundary my $boundary = $notifier->boundary; $notifier = $notifier->boundary($boundary); Gets or sets the value of the "boundary" attribute. This string is normally set by a call to "output_headers()", but may be set ahead of time. user my $user = $notifier->user; $notifier = $notifier->user($user); Gets or sets the value of the "user" attribute, which is set to the value pulled in from svnlook by the call to "prepare_contents()". date my $date = $notifier->date; $notifier = $notifier->date($date); Gets or sets the value of the "date" attribute, which is set to the value pulled in from svnlook by the call to "prepare_contents()". message my $message = $notifier->message; $notifier = $notifier->message($message); Gets or sets the value of the "message" attribute, which is set to an array reference of strings by the call to "prepare_contents()". message_size my $message_size = $notifier->message_size; $notifier = $notifier->message_size($message_size); Gets or sets the value of the "message_size" attribute, which is set to the value pulled in from svnlook by the call to "prepare_contents()". subject my $subject = $notifier->subject; $notifier = $notifier->subject($subject); Gets or sets the value of the "subject" attribute, which is normally set by a call to "prepare_subject()", but may be set explicitly. files my $files = $notifier->files; $notifier = $notifier->files($files); Gets or sets the value of the "files" attribute, which is set to a hash reference of change type mapped to arrays of strings by the call to "prepare_files()". header my $header = $notifier->header; $notifier = $notifier->header($header); Gets or set the value of the "header" attribute. Not to be confused with the "add_headers" attribute, which manages headers to be inserted into the notification email message headers. footer my $footer = $notifier->footer; $notifier = $notifier->footer($footer); Gets or set the value of the "footer" attribute. Character Encoding SupportSVN::Notify has comprehensive support for character encodings, but since it cannot always know what encodings your system supports or in which your data is stored in Subversion, it needs your help. In plain English, here's what you need to know to make non-ASCII characters look right in SVN::Notify's messages:
This looks like a lot of information, and it is. But in most cases, if you exclusively use UTF-8 (or ASCII!) in your source code and log messages, and your OS defaults to a UTF-8 locale, things should just work. See Also
SupportThis module is stored in an open GitHub repository <http://github.com/theory/svn-notify/>. Yes, I'm aware of the irony. Nevertheless, feel free to fork and contribute!Please file bug reports via GitHub Issues <http://github.com/theory/svn-notify/issues/> or by sending mail to bug-SVN-Notify@rt.cpan.org <mailto:bug-SVN-Notify@rt.cpan.org>. AuthorDavid E. Wheeler <david@justatheory.com>Copyright and LicenseCopyright (c) 2004-2016 David E. Wheeler. Some Rights Reserved.This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Visit the GSP FreeBSD Man Page Interface. |