http://www.perlmonks.org?node_id=889642

kmartin has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I am trying to take a log from Subversion and extract all the JIRA issue tags in the commit messages. I would have thought this would be a common task but I can't seem to find anyone else who's done this. I've got something that works for one issue, but it's where there are multiples that I'm stuck. Here is what I have so far

my @logs = `svn log $url -r $oldRev:$currRev`; my @tickets; foreach $log(@logs) { chomp $log; print "$log\n"; $log =~ /([A-Z]+-\d+)/; push(@tickets, $1); } my %hash = map{$_, 1} @tickets; my @master_tickets = keys %hash; my @sorted = sort @master_tickets; foreach $ticket(@sorted) { print ("$ticket\n"); }
But that doesn't get the 2nd or more when they're in the same line. ie. BACKLOG-123, BACKLOG-124, BACKLOG-125 only returns the first result. Thanks in advance.

Replies are listed 'Best First'.
Re: Grepping SVN log for JIRA issues
by toolic (Bishop) on Feb 22, 2011 at 18:49 UTC
    You could use a while loop with //g (perlre):
    use warnings; use strict; use Data::Dumper; my $log = 'BACKLOG-123, BACKLOG-124, BACKLOG-125'; my @tickets; while ($log =~ /([A-Z]+-\d+)/g) { push @tickets, $1; } print Dumper(\@tickets); __END__ $VAR1 = [ 'BACKLOG-123', 'BACKLOG-124', 'BACKLOG-125' ];
      That works! Thanks for your help.
      push @tickets, $log =~ /([A-Z]+-\d+)/g;
Re: Grepping SVN log for JIRA issues
by Fletch (Bishop) on Feb 22, 2011 at 19:35 UTC

    Somewhat tangental to your actual question, but the svn log command has an --xml option which will make its output XML instead of hyooman formatted text. You can then use something like XML::Twig to pull things apart rather than trying to parse the text output. (Granted you'd still have to grobble through the same way to find your issue tags in the message text).

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: Grepping SVN log for JIRA issues
by dHarry (Abbot) on Feb 23, 2011 at 13:24 UTC

    As an alternative, can't you use a plugin for JIRA to do this? There is one for SVN integration e.g. Subversion JIRA plugin. It seems the information that you want is in the JIRA database.

    Cheers

    Harry