freeswitch/support-d/utils/fixbug.pl

64 lines
1.2 KiB
Perl
Raw Normal View History

#!/usr/bin/perl
2015-08-17 21:31:09 +00:00
use XML::Simple;
use Data::Dumper;
2015-08-18 23:46:21 +00:00
use Getopt::Long qw(GetOptions);
2015-08-17 21:31:09 +00:00
2015-08-18 23:46:21 +00:00
my %opts;
2015-08-17 21:31:09 +00:00
2015-08-18 23:46:21 +00:00
GetOptions(
'bug=s' => \$opts{bug},
'msg=s' => \$opts{msg}
) or die "Usage: $0 -bug <bug-id> [-m [edit|<msg>]] <files>\n";
2015-08-17 21:31:09 +00:00
2015-08-18 23:46:21 +00:00
$opts{bug} || die "missing bug";;
my $url = "https://freeswitch.org/jira/si/jira.issueviews:issue-xml/$opts{bug}/$opts{bug}.xml";
2015-08-17 21:31:09 +00: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 23:46:21 +00:00
if ($opts{msg} eq "edit") {
2015-08-17 21:31:09 +00:00
$auto = 0;
2015-08-18 23:46:21 +00:00
$opts{msg} = undef;
open T, ">/tmp/$opts{bug}.tmp";
print T "$opts{bug} #resolve [$sum]\n\n";
2015-08-17 21:31:09 +00:00
close T;
}
my $args = join(" ", @ARGV);
my $gitcmd;
if ($auto) {
2015-08-18 23:46:21 +00:00
if ($opts{msg}) {
$opts{msg} =~ s/%s/$sum/;
$opts{msg} =~ s/%b/$bug/;
$gitcmd = "git commit $args -m \"$opts{msg}\"";
} else {
$gitcmd = "git commit $args -m \"$opts{bug} #resolve [$sum]\"";
}
2015-08-17 21:31:09 +00:00
} else {
2015-08-18 23:46:21 +00:00
$gitcmd = "git commit $args -t /tmp/$opts{bug}.tmp";
2015-08-17 21:31:09 +00:00
}
system $gitcmd;
2015-08-18 23:46:21 +00:00
unlink("/tmp/$opts{bug}.tmp");