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: 21633
Status: resolved
Priority: 0/
Queue: SVN-Notify

People
Owner: Nobody in particular
Requestors: martijn [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 2.63
Fixed in: 2.65



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 }
Subject: Re: [rt.cpan.org #21633] generalize issue tracking code
Date: Sat, 23 Sep 2006 11:54:08 -0700
To: bug-SVN-Notify [...] rt.cpan.org
From: "David E. Wheeler" <dwheeler [...] cpan.org>
Thanks for the patch! On Sep 23, 2006, at 06:53, Martijn van Beers via RT wrote: Show quoted text
> 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)
Yes, that's probably the right approach. I thought of doing it myself, but I just hadn't made it a priority. Thanks for jump- starting things. Show quoted text
> 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)
Yes. Show quoted text
> 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)
Comments below. Show quoted text
> If you like my patch, please tell me where your svn is, so I can diff > against that.
https://svn.kineticode.com/SVN-Notify/trunk/ Show quoted text
> --- 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'; > + }
I'm thinking that this would be cleaner as a loop: unless ($params{ticket_url}) { for my $spec ( [ rt_url => '/\b(?:(?:rt|(?:rt-)?ticket:?)\s*#?\s*(\d +))\b' ], [ bugzilla_url => '\b(?:bug\s*#?\s*(\d+))\b' ], [ jira_url => '\b([A-Z]+-\d+)\b' ], [ gnats_url => '\b(?:PR\s*(\d+))\b' ], ) { next unless defined $params{ $spec->[0] }; $params{ticket_url} = delete $params{ $spec->[0] }; $params{ticket_regex} = $spec->[1]; last; } } Then it's easier to add new ones in the future. It's easier to read, too, I think. Show quoted text
> # 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},
These should be combined with the existing ticket-url option, so that it continues to work. Show quoted text
> '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 }
Yeah, lots of removed stuff, I like that. :-) So yes, this looks good. Let me know if you have any problems with the Subversion repository (and note the new regex for RT tickets!). Best, David
Subject: Re: [rt.cpan.org #21633] generalize issue tracking code
Date: Sat, 23 Sep 2006 12:01:01 -0700
To: bug-SVN-Notify [...] rt.cpan.org
From: "David E. Wheeler" <dwheeler [...] cpan.org>
On Sep 23, 2006, at 11:54, David E. Wheeler wrote: Show quoted text
>> + 'rt-url|T|bugzilla-url|B|jira-url' . >> + '|J|gnats-url|G||ticket-url=s' => \$opts->{ticket_url},
> > These should be combined with the existing ticket-url option, so > that it continues to work.
Bah, you did. Sorry, missed. that. Best, David
Show quoted text
> So yes, this looks good. Let me know if you have any problems with > the Subversion repository (and note the new regex for RT tickets!).
Hmm, so I found a gotcha when trying to update the tests. You can't have more than one bug database at a time. This shouldn't be a problem in real life, should it? Martijn
Subject: Re: [rt.cpan.org #21633] generalize issue tracking code
Date: Sat, 23 Sep 2006 15:27:00 -0700
To: bug-SVN-Notify [...] rt.cpan.org
From: "David E. Wheeler" <dwheeler [...] cpan.org>
On Sep 23, 2006, at 13:34, Martijn van Beers via RT wrote: Show quoted text
> Hmm, so I found a gotcha when trying to update the tests. You can't > have more than one bug database at a time. This shouldn't be a problem > in real life, should it?
I wouldn't think so. That was my assumption with the SVN Web links, as well: You'd only have one. Best, David
On Sat Sep 23 18:27:15 2006, DWHEELER wrote: Show quoted text
> On Sep 23, 2006, at 13:34, Martijn van Beers via RT wrote: >
> > Hmm, so I found a gotcha when trying to update the tests. You can't > > have more than one bug database at a time. This shouldn't be a problem > > in real life, should it?
> > I wouldn't think so. That was my assumption with the SVN Web links, > as well: You'd only have one.
phew :) Here's a complete patch, against svn. I had to redo the pattern matching code in Notify.pm again, so we can use the same pattern for both html and text output (the html ones had two subpatterns, now both do) Not sure if I did the tests completely right, but at least they all pass now. Martijn
duh. this is almost exactly like email it seems. I forget the attachments here too.

Message body is not shown because it is too large.

Subject: Re: [rt.cpan.org #21633] generalize issue tracking code
Date: Mon, 25 Sep 2006 11:11:19 -0700
To: bug-SVN-Notify [...] rt.cpan.org
From: "David E. Wheeler" <david [...] kineticode.com>
On Sep 24, 2006, at 04:51, Martijn van Beers via RT wrote: Show quoted text
> duh. this is almost exactly like email it seems. I forget the > attachments here too.
Thanks. In looking over the patch, I realized that disallowing more than one ticket url option breaks backwards compatibility. Erg. I didn't realize that when you asked yesterday, and now I'm not so sure that it makes sense to commit this patch as implemented. I don't want to break that backwards compatibility. We can still do this, I think. We just have to allow ticket-url and ticket-regex to be array references. And now that I think about it, it was stupid to have ticket-url and ticket-regex be separate items. They should be a single one, as a hash: --ticket-map '\[?#\s*(\d+)\s*\]?=http://ticket.example.com/ tik.html?id=%s' But whatever. I'll have to think about this some to decide what makes the most sense. And in the meantime, I don't want to make you do any more work than you already have, just because I'm being contrary and picky! I appreciate what you've done, and how it is leading to a simplification of SVN::Notify. Thanks, David
Here's the extra method I talked about on irc, to make SVN::Notify take care of the looping over the various entries in the ticket_map.
Index: lib/SVN/Notify.pm =================================================================== --- lib/SVN/Notify.pm (revision 3247) +++ lib/SVN/Notify.pm (working copy) @@ -1341,16 +1341,19 @@ # Make ticketing system links. if (my $map = $self->ticket_map) { my $has_header = 0; - while (my ($regex, $url) = each %$map) { - $regex = $_ticket_regexen{ $regex } || $regex; - while ($msg =~ /$regex/ig) { - unless ($has_header) { - print $out "\nTicket Links:\n:-----------\n"; - $has_header = 1; - } - printf $out " $url\n", $2 || $1; - } - } + $self->run_ticket_map ( + sub { + my ($regex, $url) = @_; + + while ($msg =~ /$regex/ig) { + unless ($has_header) { + print $out "\nTicket Links:\n:-----------\n"; + $has_header = 1; + } + printf $out " $url\n", $2 || $1; + } + } + ); } return $self; @@ -1358,9 +1361,33 @@ ############################################################################## +=head3 run_ticket_map + + $notifier->run_ticket_map($callback, @params); + +This will loop over the ticket systems you have defined, and call +the &$callback function for each one, with the regex, the url and the +@params you specified as its parameters. + +=cut + +sub run_ticket_map { + my ($self, $callback, @params) = @_; + + # Make ticketing system links. + if (my $map = $self->ticket_map) { + my $has_header = 0; + while (my ($regex, $url) = each %$map) { + $regex = $_ticket_regexen{ $regex } || $regex; + $callback->($regex, $url, @params); + } + } +} +############################################################################## + =head3 output_file_lists - $notifier->output_log_message($file_handle); + $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 Index: lib/SVN/Notify/HTML.pm =================================================================== --- lib/SVN/Notify/HTML.pm (revision 3247) +++ lib/SVN/Notify/HTML.pm (working copy) @@ -324,11 +324,13 @@ # Make ticketing system links. if (my $map = $self->ticket_map) { - while (my ($regex, $url) = each %$map) { - $regex = $SVN::Notify::_ticket_regexen{$regex} || $regex; - $url = encode_entities($url, '<>&"'); - $msg =~ s{$regex}{ sprintf qq{<a href="$url">$1</a>}, $2 || $1 }ige; - } + $self->run_ticket_map ( + sub { + my ($regex, $url) = @_; + $url = encode_entities($url, '<>&"'); + $msg =~ s{$regex}{ sprintf qq{<a href="$url">$1</a>}, $2 || $1 }ige; + } + ); } # Print it out and return.
Subject: Re: [rt.cpan.org #21633] generalize issue tracking code
Date: Mon, 26 Mar 2007 18:26:29 -0700
To: bug-SVN-Notify [...] rt.cpan.org
From: "David E. Wheeler" <david [...] kineticode.com>
On Oct 12, 2006, at 10:40, Martijn van Beers via RT wrote: Show quoted text
> Here's the extra method I talked about on irc, to make SVN::Notify > take care of the looping over the various entries in the ticket_map.
Finally applied in r3280. Look for a new release in the next day or two; I'm clearing out a number of tickets for SVN::Notify this week. Best, David