FS-7988 add -askall and -noedit params

This commit is contained in:
Anthony Minessale 2015-08-19 14:49:10 -05:00
parent 283685844e
commit 7a81968eac
1 changed files with 92 additions and 43 deletions

View File

@ -1,11 +1,16 @@
#!/usr/bin/perl #!/usr/bin/perl
#use strict; #use strict;
use Getopt::Long qw(GetOptions); use Getopt::Long qw(GetOptions);
use Term::ReadKey; use Term::ReadKey;
use JIRA::REST; use JIRA::REST;
use Data::Dumper; use Data::Dumper;
my $editor = $ENV{"EDITOR"} || $ENV{"VISUAL"} || `which emacs` || `which vi`;
my $default_versions = "1.7";
my $default_components = "freeswitch-core";
sub getpass { sub getpass {
ReadMode( "noecho"); ReadMode( "noecho");
print "Password: "; print "Password: ";
@ -14,23 +19,35 @@ sub getpass {
return $pwd; return $pwd;
} }
sub getuser { sub getfield {
print "User: "; my $prompt = shift;
chomp (my $usr = <>); my $default = shift;
return $usr;
print $prompt . ($default ? "[$default]: " : "");
chomp (my $data = <>);
if (!$data) {
$data = $default;
}
return $data;
} }
sub get_text { sub get_text {
my $text = shift;
my @chars = ("A".."Z", "a".."z"); my @chars = ("A".."Z", "a".."z");
my $string; my $string;
$string .= $chars[rand @chars] for 1..8; $string .= $chars[rand @chars] for 1..8;
my $editor = $ENV{"EDITOR"} || $ENV{"VISUAL"} || `which emacs` || `which vi`; if ($text) {
open O, ">/tmp/TEXT.$string";
print O $text;
close O;
}
system("$editor /tmp/TEXT.$string"); system("$editor /tmp/TEXT.$string");
my $text = `cat /tmp/TEXT.$string`; my $newtext = `cat /tmp/TEXT.$string`;
unlink("/tmp/TEXT.$string"); unlink("/tmp/TEXT.$string");
return $text; return $newtext;
} }
my %opts; my %opts;
@ -47,24 +64,31 @@ GetOptions(
'user=s' => \$opts{user}, 'user=s' => \$opts{user},
'pass=s' => \$opts{pass}, 'pass=s' => \$opts{pass},
'type=s' => \$opts{type}, 'type=s' => \$opts{type},
'versions=s' => \$opts{versions},
'noedit' => \$opts{noedit},
'askall' => \$opts{askall},
'debug' => \$opts{debug}, 'debug' => \$opts{debug},
) or die "Usage: $0 -summary <summary> -desc <desc> [-debug] ....\n"; ) or die "Usage: $0 -summary <summary> -desc <desc> [-debug] ....\n";
$opts{project} or $opts{project} = "FS"; $opts{project} or $opts{project} = "FS";
if ($opts{versions}) {
$opts{versions_array} = [map {{name => $_}} split(" ", $opts{versions})];
} else {
$opts{versions_array} = [map {{name => $_}} ($default_versions)];
$opts{versions} = $default_versions;;
}
if ($opts{components}) { if ($opts{components}) {
$opts{components_array} = [map {{name => $_}} split(" ", $opts{components})]; $opts{components_array} = [map {{name => $_}} split(" ", $opts{components})];
} else { } else {
$opts{components_array} = [map {{name => $_}} qw(freeswitch-core)]; $opts{components_array} = [map {{name => $_}} ($default_components)];
$opts{components} = $default_components;
} }
#print Dumper \%opts;
#exit;
if (!$opts{user}) { if (!$opts{user}) {
$opts{user} = getuser(); $opts{user} = getfield("User: ");
} }
if (!$opts{pass} && !$opts{debug}) { if (!$opts{pass} && !$opts{debug}) {
@ -86,23 +110,47 @@ if (!$opts{type}) {
$opts{type} = "Bug"; $opts{type} = "Bug";
} }
if (!$opts{summary}) { if (!$opts{hash}) {
die "missing summary:"; $opts{hash} = $hash;
if (!$opts{hash}) {
$opts{hash} = "N/A";
}
}
if ($opts{askall}) {
$opts{project} = getfield("Project: ", $opts{project});
$opts{type} = getfield("Type: ", $opts{type});
$opts{versions} = getfield("Versions: ", $opts{versions});
$opts{versions_array} = [map {{name => $_}} split(" ", $opts{versions})];
$opts{summary} = getfield("Summary: ", $opts{summary});
$opts{components} = getfield("Components: ", $opts{components});
$opts{components_array} = [map {{name => $_}} split(" ", $opts{components})];
$opts{hash} = getfield("GIT Hash: ", $opts{hash});
if ($opts{noedit}) {
$opts{desc} = getfield("Description: ", $opts{desc});
} else {
$opts{desc} = get_text($opts{desc});
}
} }
if (!$opts{desc}) { if (!$opts{desc}) {
$opts{desc} = get_text(); if ($opts{noedit}) {
$opts{desc} = getfield("Description: ", $opts{desc});
} else {
$opts{desc} = get_text($opts{desc});
}
if (!$opts{desc}) { if (!$opts{desc}) {
die "missing desc:"; die "missing desc:";
} }
} }
if (!$opts{hash}) { if (!$opts{summary}) {
$opts{hash} = $hash; $opts{summary} = getfield("Summary: ", $opts{summary});
if (!$opts{summary}) {
if (!$opts{hash}) { die "Summary is mandatory.";
$opts{hash} = "N/A";
} }
} }
@ -114,7 +162,8 @@ my $input = {
description => $opts{desc}, description => $opts{desc},
customfield_10024 => $opts{hash}, customfield_10024 => $opts{hash},
customfield_10025 => $opts{hash}, customfield_10025 => $opts{hash},
components => $opts{components_array} components => $opts{components_array},
affectsVersion => $opts{versions_array}
}, },
}; };