2015-08-18 19:28:38 -04:00
|
|
|
#!/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);
|
2017-06-06 14:56:15 -04:00
|
|
|
use Term::ReadKey;
|
|
|
|
use JIRA::REST;
|
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
|
|
|
|
2017-06-06 14:56:15 -04:00
|
|
|
sub getpass {
|
|
|
|
ReadMode( "noecho");
|
|
|
|
print "Password: ";
|
|
|
|
chomp (my $pwd = <STDIN>);
|
|
|
|
ReadMode ("original");
|
|
|
|
return $pwd;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub getfield {
|
|
|
|
my $prompt = shift;
|
|
|
|
my $default = shift;
|
|
|
|
|
|
|
|
print $prompt . ($default ? "[$default]: " : "");
|
|
|
|
chomp (my $data = <STDIN>);
|
|
|
|
|
|
|
|
if (!$data) {
|
|
|
|
$data = $default;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2015-08-18 19:46:21 -04:00
|
|
|
GetOptions(
|
|
|
|
'bug=s' => \$opts{bug},
|
2015-08-19 14:09:33 -04:00
|
|
|
'msg=s' => \$opts{msg},
|
2017-06-06 14:56:15 -04:00
|
|
|
'user=s' => \$opts{user},
|
|
|
|
'pass=s' => \$opts{pass},
|
2015-08-19 14:09:33 -04:00
|
|
|
'debug' => \$opts{debug},
|
2017-03-01 12:35:42 -05:00
|
|
|
'noresolve' => \$opts{noresolve},
|
2015-08-19 14:09:33 -04:00
|
|
|
'append=s' => \$opts{append},
|
2015-08-24 18:44:55 -04:00
|
|
|
'comment=s' => \$opts{comment},
|
2017-06-06 14:56:15 -04:00
|
|
|
'versions=s' => \$opts{versions},
|
|
|
|
'author=s' => \$opts{author},
|
|
|
|
'auth' => \$opts{auth}
|
|
|
|
) or die "Usage: $0 -bug <bug-id> [--auth] [-m [edit|<msg>]] [--append <msg>] [--debug] <files>\n";
|
2015-08-17 17:31:09 -04:00
|
|
|
|
2015-08-18 19:46:21 -04:00
|
|
|
|
2015-08-19 14:09:33 -04:00
|
|
|
$opts{bug} or $opts{bug} = shift;
|
|
|
|
|
2017-06-06 14:56:15 -04:00
|
|
|
if ($opts{versions}) {
|
|
|
|
$opts{auth} = 1;
|
|
|
|
$opts{versions_array} = [map {{name => $_}} split(" ", $opts{versions})];
|
|
|
|
}
|
|
|
|
|
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;
|
2017-03-01 12:35:42 -05:00
|
|
|
my $post = " \#resolve";
|
2017-06-07 19:00:50 -04:00
|
|
|
my $component;
|
|
|
|
my $summary;
|
2015-08-17 17:31:09 -04:00
|
|
|
|
|
|
|
chomp $prog;
|
|
|
|
|
2017-06-06 14:56:15 -04:00
|
|
|
if ($opts{auth}) {
|
|
|
|
if (!$opts{user}) {
|
|
|
|
$opts{user} = getfield("User: ");
|
|
|
|
}
|
|
|
|
|
2017-06-07 19:00:50 -04:00
|
|
|
if (!$opts{pass}) {
|
2017-06-06 14:56:15 -04:00
|
|
|
$opts{pass} = getpass();
|
|
|
|
print "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
$jira = JIRA::REST->new('https://freeswitch.org/jira', $opts{user}, $opts{pass}) or die "login incorrect:";
|
|
|
|
$issue = $jira->GET("/issue/FS-7985") or die "login incorrect:";
|
|
|
|
|
|
|
|
my $issue = $jira->GET("/issue/" . $opts{bug});
|
|
|
|
|
|
|
|
$component = join(",", map {$_->{name}} @{$issue->{fields}->{components}});
|
|
|
|
$summary = $issue->{fields}->{summary};
|
|
|
|
|
|
|
|
|
|
|
|
if ($opts{versions_array}) {
|
|
|
|
$input = {
|
|
|
|
|
|
|
|
update => {
|
|
|
|
fixVersions => [
|
|
|
|
{set => $opts{versions_array}}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$jira->PUT("/issue/" . $opts{bug}, undef, $input);
|
|
|
|
}
|
2015-08-17 17:31:09 -04:00
|
|
|
|
|
|
|
} else {
|
2017-06-06 14:56:15 -04:00
|
|
|
$prog || die "missing url fetch program, install curl or wget";
|
2015-08-17 17:31:09 -04:00
|
|
|
|
2017-06-06 14:56:15 -04:00
|
|
|
if ($prog =~ /wget/) {
|
|
|
|
$cmd = "$prog -O -";
|
|
|
|
} else {
|
|
|
|
$cmd = $prog;
|
|
|
|
}
|
2015-08-17 17:31:09 -04:00
|
|
|
|
2017-06-06 14:56:15 -04:00
|
|
|
my $xml = `$cmd $url 2>/dev/null`;
|
|
|
|
if ($opts{debug}) {
|
|
|
|
print "URL $url\n";
|
|
|
|
print $xml;
|
|
|
|
}
|
2015-08-17 17:31:09 -04:00
|
|
|
|
2017-06-06 14:56:15 -04:00
|
|
|
my $xs= new XML::Simple;
|
|
|
|
my $r = $xs->XMLin($xml);
|
2017-06-07 19:00:50 -04:00
|
|
|
$summary = $r->{channel}->{item}->{summary};
|
|
|
|
$summary =~ s/\"/\\"/g;
|
2015-08-17 17:31:09 -04:00
|
|
|
|
2017-06-07 19:00:50 -04:00
|
|
|
$component = $r->{channel}->{item}->{component};
|
2016-12-13 18:01:41 -05:00
|
|
|
|
2017-06-06 14:56:15 -04:00
|
|
|
if(ref($component) eq 'ARRAY') {
|
|
|
|
$component = join(",", @{$component});
|
|
|
|
}
|
|
|
|
|
|
|
|
$component =~ s/\"/\\"/g;
|
|
|
|
}
|
2016-12-13 18:01:41 -05:00
|
|
|
|
2017-03-01 12:35:42 -05:00
|
|
|
if ($opts{noresolve}) {
|
|
|
|
$post = "";
|
|
|
|
}
|
|
|
|
|
2017-06-06 14:56:15 -04:00
|
|
|
|
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";
|
2017-06-07 19:00:50 -04:00
|
|
|
print T "$opts{bug}${post} [$summary]\n\n---Cut this line to confirm commit.....";
|
2015-08-17 17:31:09 -04:00
|
|
|
close T;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $args = join(" ", @ARGV);
|
|
|
|
my $gitcmd;
|
|
|
|
|
2015-08-19 14:09:33 -04:00
|
|
|
if ($opts{append}) {
|
2017-04-12 13:42:06 -04:00
|
|
|
$opts{append} = " -- " . $opts{append};
|
2015-08-19 14:09:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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}) {
|
2017-06-07 19:00:50 -04:00
|
|
|
$opts{msg} =~ s/%s/$summary/;
|
2015-08-19 12:43:35 -04:00
|
|
|
$opts{msg} =~ s/%b/$opts{bug}/;
|
2016-12-13 18:01:41 -05:00
|
|
|
$opts{msg} =~ s/%c/$component/;
|
2015-08-19 14:09:33 -04:00
|
|
|
$gitcmd = "git commit $args -m \"$opts{msg}$opts{append}\"";
|
2015-08-18 19:46:21 -04:00
|
|
|
} else {
|
2017-06-07 19:00:50 -04:00
|
|
|
$gitcmd = "git commit $args -m \"$opts{bug}: [$component] ${summary}$opts{append}${post}\"";
|
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}\"";
|
|
|
|
}
|
|
|
|
|
2015-08-19 14:09:33 -04:00
|
|
|
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");
|