Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Grepping SVN log for JIRA issues

by kmartin (Initiate)
on Feb 22, 2011 at 18:33 UTC ( #889642=perlquestion: print w/ replies, xml ) Need Help??
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.

Comment on Grepping SVN log for JIRA issues
Download Code
Re: Grepping SVN log for JIRA issues
by toolic (Chancellor) 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 (Chancellor) 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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://889642]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2014-10-25 22:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (149 votes), past polls