freeswitch/support-d/utils/fixbug.pl

85 lines
1.7 KiB
Perl
Raw Normal View History

#!/usr/bin/perl
2015-08-17 17:31:09 -04:00
use XML::Simple;
use Data::Dumper;
2015-08-18 19:46:21 -04:00
use Getopt::Long qw(GetOptions);
2015-08-17 17:31:09 -04:00
2015-08-18 19:46:21 -04:00
my %opts;
2015-08-17 17:31:09 -04:00
2015-08-18 19:46:21 -04:00
GetOptions(
'bug=s' => \$opts{bug},
'msg=s' => \$opts{msg},
'debug' => \$opts{debug},
'append=s' => \$opts{append},
2015-08-24 18:44:55 -04:00
'comment=s' => \$opts{comment},
'author=s' => \$opts{author}
) or die "Usage: $0 -bug <bug-id> [-m [edit|<msg>]] [-append <msg>] [-debug] <files>\n";
2015-08-17 17:31:09 -04:00
2015-08-18 19:46:21 -04:00
$opts{bug} or $opts{bug} = shift;
2015-08-18 19:46:21 -04:00
my $url = "https://freeswitch.org/jira/si/jira.issueviews:issue-xml/$opts{bug}/$opts{bug}.xml";
2015-08-17 17:31:09 -04:00
my $cmd;
my $prog = `which curl` || `which wget`;
my $auto = 1;
chomp $prog;
$prog || die "missing url fetch program, install curl or wget";
if ($prog =~ /wget/) {
$cmd = "$prog -O -";
} else {
$cmd = $prog;
}
my $xml = `$cmd $url 2>/dev/null`;
my $xs= new XML::Simple;
my $r = $xs->XMLin($xml);
my $sum = $r->{channel}->{item}->{summary};
2015-08-18 19:46:21 -04:00
if ($opts{msg} eq "edit") {
2015-08-17 17:31:09 -04:00
$auto = 0;
2015-08-18 19:46:21 -04:00
$opts{msg} = undef;
open T, ">/tmp/$opts{bug}.tmp";
print T "$opts{bug} #resolve [$sum]\n\n---Cut this line to confirm commit.....";
2015-08-17 17:31:09 -04:00
close T;
}
my $args = join(" ", @ARGV);
my $gitcmd;
if ($opts{append}) {
$opts{append} = " " . $opts{append};
}
if ($opts{comment}) {
$opts{append} .= " #comment " . $opts{comment};
}
2015-08-17 17:31:09 -04:00
if ($auto) {
2015-08-18 19:46:21 -04:00
if ($opts{msg}) {
$opts{msg} =~ s/%s/$sum/;
2015-08-19 12:43:35 -04:00
$opts{msg} =~ s/%b/$opts{bug}/;
$gitcmd = "git commit $args -m \"$opts{msg}$opts{append}\"";
2015-08-18 19:46:21 -04:00
} else {
$gitcmd = "git commit $args -m \"$opts{bug} #resolve [$sum]$opts{append}\"";
2015-08-18 19:46:21 -04:00
}
2015-08-17 17:31:09 -04:00
} else {
2015-08-18 19:46:21 -04:00
$gitcmd = "git commit $args -t /tmp/$opts{bug}.tmp";
2015-08-17 17:31:09 -04:00
}
2015-08-24 18:44:55 -04:00
if ($opts{author}) {
$gitcmd .= " --author \"$opts{author}\"";
}
if ($opts{debug}) {
print "CMD: $gitcmd\n";
} else {
system $gitcmd;
}
2015-08-17 17:31:09 -04:00
2015-08-18 19:46:21 -04:00
unlink("/tmp/$opts{bug}.tmp");