Subject: | generalize issue tracking code |
I noticed svnweb and viewcvs options existed, but were deprecated, and
was wondering why the same hadn't happened for rt/bugzilla/etc. links.
Thinking about it, I realized that they were different, as they need
regexen to find the relevant text, and providing these for common
systems is too convenient to remove. So then I just generalized the
code to check for these by putting the pre-supplied regex into
ticket_regex in new() (and copying the rt_url to ticket_url)
This way, I don't have to do anything special for different issue
tracking systems in my SVN::Notify subclass (and SVN::Notify::HTML
can be simpler too)
I attached a partial patch to show you what I did. It doesn't yet
change SVN::Notify::HTML, or the tests, because I wanted you to
comment on how I'm doing things before doing the niggly bits (in
case you think it should be done differently (or not at all)
If you like my patch, please tell me where your svn is, so I can diff
against that.
Subject: | svn-notify-2.diff |
--- Notify.pm.orig 2006-09-23 14:41:11.000000000 +0200
+++ Notify.pm 2006-09-23 15:09:12.000000000 +0200
@@ -603,6 +603,21 @@
$params{revision_url} .= '/revision/?rev=%s&view=rev'
}
+ # set up the issue tracking links
+ if (defined $params{rt_url}) {
+ $params{ticket_url} = delete $params{rt_url};
+ $params{ticket_regex} = '\b(?:(?:rt-)?ticket:?\s*#?\s*(\d+))\b';
+ } elsif (defined $params{bugzilla_url}) {
+ $params{ticket_url} = delete $params{bugzilla_url};
+ $params{ticket_regex} = '\b(?:bug\s*#?\s*(\d+))\b';
+ } elsif (defined $params{jira_url}) {
+ $params{ticket_url} = delete $params{jira_url};
+ $params{ticket_regex} = '\b([A-Z]+-\d+)\b';
+ } elsif (defined $params{gnats_url}) {
+ $params{ticket_url} = delete $params{gnats_url};
+ $params{ticket_regex} = '\b(?:PR\s*(\d+))\b';
+ }
+
# Make it so!
$class->_dbpnt( "Instantiating $class object") if $params{verbose};
return bless \%params, $class;
@@ -712,11 +727,6 @@
'max-diff-length|e=i' => \$opts->{max_diff_length},
'handler|H=s' => \$opts->{handler},
'author-url|A=s' => \$opts->{author_url},
- 'rt-url|T=s' => \$opts->{rt_url},
- 'bugzilla-url|B=s' => \$opts->{bugzilla_url},
- 'jira-url|J=s' => \$opts->{jira_url},
- 'gnats-url|G=s' => \$opts->{gnats_url},
- 'ticket-url=s' => \$opts->{ticket_url},
'ticket-regex=s' => \$opts->{ticket_regex},
'verbose|V+' => \$opts->{verbose},
'help|h' => \$opts->{help},
@@ -730,6 +740,8 @@
'add-header=s%' => sub {
shift; push @{ $opts->{add_headers}{+shift} }, shift
},
+ 'rt-url|T|bugzilla-url|B|jira-url' .
+ '|J|gnats-url|G||ticket-url=s' => \$opts->{ticket_url},
'revision-url|U|svnweb-url|S|viewcvs-url=s' => \$opts->{revision_url},
) or return;
@@ -1294,39 +1306,7 @@
}
}
- # Make Bugzilla links.
- if (my $url = $self->bugzilla_url) {
- if (my @matches = $msg =~ /\b(?:bug\s*#?\s*(\d+))\b/ig) {
- print $out "\nBugzilla Links:\n--------------\n";
- printf $out " $url\n", $_ for @matches;
- }
- }
-
- # Make RT links.
- if (my $url = $self->rt_url) {
- if (my @matches = $msg =~ /\b(?:(?:rt-)?ticket:?\s*#?\s*(\d+))\b/ig) {
- print $out "\nRT Links:\n--------\n";
- printf $out " $url\n", $_ for @matches;
- }
- }
-
- # Make JIRA links.
- if (my $url = $self->jira_url) {
- if (my @matches = $msg =~ /\b([A-Z]+-\d+)\b/g) {
- print $out "\nJIRA Links:\n----------\n";
- printf $out " $url\n", $_ for @matches;
- }
- }
-
- # Make GNATS links.
- if (my $url = $self->gnats_url) {
- if (my @matches = $msg =~ /\b(?:PR\s*(\d+))\b/ig) {
- print $out "\nGNATS Links:\n-----------\n";
- printf $out " $url\n", $_ for @matches;
- }
- }
-
- # Make custom ticketing system links.
+ # Make ticketing system links.
if (my $url = $self->ticket_url) {
my $regex = $self->ticket_regex
or die q{Missing "ticket_regex" parameter to accompany }