Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the SVN-Notify CPAN distribution.

Report information
The Basics
Id: 14455
Status: resolved
Worked: 2 hours (120 min)
Priority: 0/
Queue: SVN-Notify

People
Owner: Nobody in particular
Requestors: andrewo [...] oriel.com.au
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 2.47
Fixed in: (no value)



Subject: New Feature: custom-ticket-url and custom-ticket-regex options
Hi David, Great module! Saved me much time. We use an in-house ticketing system for both bug- and job-tracking and I needed a way to add customisable linkification for both textual and HTML output. Attached is a patch against 2.47 that: * adds custom-ticket-url and custom-ticket-regex options * handles both text and HTML output * documents them * updates t/options.t While it does put some onus on the user to come up with the right regexes (and should probably have some better examples) this is necessary to handle all the "other" bug and ticket systems out there without having to add an option for each and every one. You might want to allow array inputs if there are multiple custom urls/regexes but this does the job for me. This could have been done with a handler subclass but I needed it for both normal textual output and HTML::ColorDiff so it went in the core. Cheers, Andrew
diff -rBbu SVN-Notify-2.47.orig/lib/SVN/Notify/HTML.pm SVN-Notify-2.47/lib/SVN/Notify/HTML.pm --- SVN-Notify-2.47.orig/lib/SVN/Notify/HTML.pm 2005-09-04 04:57:42.000000000 +1000 +++ SVN-Notify-2.47/lib/SVN/Notify/HTML.pm 2005-09-05 12:37:21.000000000 +1000 @@ -207,6 +207,12 @@ Message" in C<< <h3> >> tags. If the C<bugzilla_url> attribute is set, then any strings like "Bug 2" or "bug # 567" will be turned into links. +If the C<custom_ticket_url> and C<custom_ticket_regex> attributes are +set then the parts of the message matching the regex will be turned +into links. The regex should match I<two> things: the first is the +text to linkify (ie the link text itself) and the second is the ID +string to interpolate into C<custom_ticket_url>. + =cut sub output_log_message { @@ -261,6 +267,14 @@ $msg =~ s|\b(PR\s*(\d+))\b|sprintf qq{<a href="$url">$1</a>}, $2|ge; } + # Make custom ticketing system links. + if (my $url = $self->custom_ticket_url) { + $url = encode_entities($url); + if (my $regex = $self->custom_ticket_regex) { + $msg =~ s|$regex|sprintf qq{<a href="$url">$1</a>}, $2|ige; + } + } + # Print it out and return. print $out "<h3>Log Message</h3>\n<pre>$msg</pre>\n\n"; return $self; diff -rBbu SVN-Notify-2.47.orig/lib/SVN/Notify.pm SVN-Notify-2.47/lib/SVN/Notify.pm --- SVN-Notify-2.47.orig/lib/SVN/Notify.pm 2005-09-04 04:57:42.000000000 +1000 +++ SVN-Notify-2.47/lib/SVN/Notify.pm 2005-09-05 12:40:15.000000000 +1000 @@ -363,6 +363,31 @@ the GnatsWeb server. The URL must have the "%s" format where the GNATS PR number should be put into the URL. +=item custom_ticket_url + + svnnotify --custom-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 C<custom_ticket_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. + +=item custom_ticket_regex + + svnnotify --custom-ticket-regex '\[?#\s*(\d+)\s*\]?' + +The regex to match a ticket tag of a custom ticket system. This should +return a single match which is interpolated into the +C<custom-ticket-url> as above. 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. + +NOTE: The number of matches required to be returned by this regex +changes when using any of the C<HTML> handlers. Please see +L<SVN::Notifiy::HTML> in the C<output_log_message> section for more +details. + =item verbose svnnotify --verbose -V @@ -536,6 +561,8 @@ "bugzilla-url|B=s" => \$opts->{bugzilla_url}, "jira-url|J=s" => \$opts->{jira_url}, "gnats-url|G=s" => \$opts->{gnats_url}, + "custom-ticket-url=s" => \$opts->{custom_ticket_url}, + "custom-ticket-regex=s" => \$opts->{custom_ticket_regex}, "verbose|V+" => \$opts->{verbose}, "help|h" => \$opts->{help}, "man|m" => \$opts->{man}, @@ -1082,6 +1109,16 @@ } } + # Make custom ticketing system links. + if (my $url = $self->custom_ticket_url) { + if (my $regex = $self->custom_ticket_regex) { + if (my @matches = $msg =~ /$regex/ig) { + print $out "\nTicket Links:\n-----------\n"; + printf $out " $url\n", $_ for @matches; + } + } + } + return $self; } @@ -1216,7 +1253,8 @@ user_domain svnlook sendmail charset language with_diff attach_diff reply_to subject_prefix subject_cx max_sub_length viewcvs_url svnweb_url - rt_url bugzilla_url jira_url gnats_url verbose + rt_url bugzilla_url jira_url gnats_url + custom_ticket_url custom_ticket_regex verbose boundary user date message message_size subject files)); diff -rBbu SVN-Notify-2.47.orig/t/options.t SVN-Notify-2.47/t/options.t --- SVN-Notify-2.47.orig/t/options.t 2005-09-04 04:57:42.000000000 +1000 +++ SVN-Notify-2.47/t/options.t 2005-09-05 12:37:21.000000000 +1000 @@ -36,6 +36,8 @@ bugzilla_url => undef, gnats_url => undef, jira_url => undef, + custom_ticket_url => undef, + custom_ticket_regex => undef, verbose => undef, help => undef, man => undef,
From: David Wheeler <david [...] kineticode.com>
Subject: Re: [cpan #14455] New Feature: custom-ticket-url and custom-ticket-regex options
Date: Thu, 29 Sep 2005 10:32:37 -0700
To: bug-SVN-Notify [...] rt.cpan.org
RT-Send-Cc:
On Sep 4, 2005, at 8:05 PM, Guest via RT wrote: Show quoted text
> This could have been done with a handler subclass but I needed it > for both normal textual output and HTML::ColorDiff so it went in > the core.
I've put it on my list to look at this, but FWIW, I suspect that you could have added it to both HTML and text support by using multiple inheritance. More work, I admit, and your patch is generally useful, so I'll probably work it in one of these days, tuits permitting. Cheers, David
I integrated your patch into the new 2.50 release. The only difference, really, is that the options are "ticket-url" and "ticket-regex" instead of "custom-ticket-url" and "custom-ticket-regex". I also added tests and documented the new options in bin/svnnotify. Enjoy!