freeswitch/support-d/utils/filebug.pl

266 lines
5.8 KiB
Perl
Raw Normal View History

#!/usr/bin/perl
#use strict;
use Getopt::Long qw(GetOptions);
use Term::ReadKey;
use JIRA::REST;
use Data::Dumper;
2015-08-19 15:49:10 -04:00
my $editor = $ENV{"EDITOR"} || $ENV{"VISUAL"} || `which emacs` || `which vi`;
2016-09-27 18:34:07 -04:00
my $default_versions = "1.9 1.8";
2015-08-19 15:49:10 -04:00
my $default_components = "freeswitch-core";
my $desc_head = "; Enter the description lines beginning with a ; will be ignored.\n";
2015-08-19 15:49:10 -04:00
chomp($editor);
2015-08-19 15:49:10 -04:00
sub getpass {
ReadMode( "noecho");
print "Password: ";
2015-08-19 17:09:08 -04:00
chomp (my $pwd = <STDIN>);
ReadMode ("original");
return $pwd;
}
2015-08-19 15:49:10 -04:00
sub getfield {
my $prompt = shift;
my $default = shift;
print $prompt . ($default ? "[$default]: " : "");
2015-08-19 17:09:08 -04:00
chomp (my $data = <STDIN>);
2015-08-19 15:49:10 -04:00
if (!$data) {
$data = $default;
}
2015-08-19 17:09:08 -04:00
2015-08-19 15:49:10 -04:00
return $data;
}
sub get_text {
2015-08-19 15:49:10 -04:00
my $text = shift;
my $notes = shift;
2015-08-19 15:49:10 -04:00
my @chars = ("A".."Z", "a".."z");
my $string;
$string .= $chars[rand @chars] for 1..8;
if ($text || $notes) {
2015-08-19 15:49:10 -04:00
open O, ">/tmp/TEXT.$string";
if ($notes) {
print O $notes;
}
if ($text) {
print O $text;
}
2015-08-19 15:49:10 -04:00
close O;
}
system("$editor /tmp/TEXT.$string");
my $newtext = `cat /tmp/TEXT.$string | grep -v "^\\;"`;
2015-08-19 15:49:10 -04:00
unlink("/tmp/TEXT.$string");
return $newtext;
}
my %opts;
my $hashtxt = `git log -1 --oneline 2>/dev/null`;
my ($hash) = split(" ", $hashtxt);
GetOptions(
2015-08-19 17:09:08 -04:00
'bug=s' => \$opts{bug},
'attach' => \$opts{attach},
'comment=s' => \$opts{comment},
2015-08-19 15:49:10 -04:00
'project=s' => \$opts{project},
'summary=s' => \$opts{summary},
'desc=s' => \$opts{desc},
'components=s' => \$opts{components},
'hash=s' => \$opts{hash},
'user=s' => \$opts{user},
'pass=s' => \$opts{pass},
'type=s' => \$opts{type},
'versions=s' => \$opts{versions},
'noedit' => \$opts{noedit},
'terse' => \$opts{terse},
2015-08-19 15:49:10 -04:00
'debug' => \$opts{debug},
) or die "Usage: $0 -summary <summary> -desc <desc> [-debug] ....\n";
$opts{project} or $opts{project} = "FS";
2015-08-19 15:49:10 -04:00
if ($opts{versions}) {
$opts{versions_array} = [map {{name => $_}} split(" ", $opts{versions})];
} else {
2015-08-19 15:49:10 -04:00
$opts{versions_array} = [map {{name => $_}} ($default_versions)];
$opts{versions} = $default_versions;;
}
2015-08-19 15:49:10 -04:00
if ($opts{components}) {
if ($opts{components} =~ /,/) {
$opts{components_array} = [map {{name => $_}} split(" ", $opts{components})];
} else {
$opts{components_array} = [map {{name => $_}} split(" ", $opts{components})];
}
2015-08-19 15:49:10 -04:00
} else {
$opts{components_array} = [map {{name => $_}} ($default_components)];
$opts{components} = $default_components;
}
if (!$opts{user}) {
2015-08-19 17:09:08 -04:00
$opts{user} = getfield("User: ");
}
if (!$opts{pass} && !$opts{debug}) {
2015-08-19 17:09:08 -04:00
$opts{pass} = getpass();
print "\n";
}
my $jira;
my $issue;
if (!$opts{debug}) {
$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:";
}
2015-08-19 17:09:08 -04:00
if ($opts{bug}) {
if ($opts{comment}) {
if ($opts{comment} eq "edit") {
$opts{comment} = get_text();
}
my $input = {
update => {
comment =>
[{
add => {
body => $opts{comment}
}
}
]
}
};
$jira->PUT("/issue/" . $opts{bug}, undef, $input);
print "Comment Posted.\n";
}
if ($opts{attach}) {
$jira->attach_files($opts{bug}, @ARGV);
printf "%d file%s attached.\n", scalar @ARGV, scalar @ARGV == 1 ? "" : "s";
}
if ($opts{versions_array}) {
$input = {
update => {
fixVersions => [
{set => $opts{versions_array}}
]
}
};
$jira->PUT("/issue/" . $opts{bug}, undef, $input);
}
2015-08-19 17:09:08 -04:00
exit;
}
#print $issue->{key};
#exit;
if (!$opts{type}) {
$opts{type} = "Bug";
}
2015-08-19 15:49:10 -04:00
if (!$opts{hash}) {
$opts{hash} = $hash;
2015-08-19 15:49:10 -04:00
if (!$opts{hash}) {
$opts{hash} = "N/A";
}
}
if (!$opts{terse}) {
2015-08-19 15:49:10 -04:00
$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});
if ($opts{components} =~ /,/) {
$opts{components_array} = [map {{name => $_}} split(",", $opts{components})];
} else {
$opts{components_array} = [map {{name => $_}} split(" ", $opts{components})];
}
2015-08-19 15:49:10 -04:00
$opts{hash} = getfield("GIT Hash: ", $opts{hash});
if ($opts{noedit}) {
$opts{desc} = getfield("Description: ", $opts{desc}, $desc_head);
2015-08-19 15:49:10 -04:00
} else {
$opts{desc} = get_text($opts{desc}, $desc_head);
2015-08-19 15:49:10 -04:00
}
}
2015-08-19 15:49:10 -04:00
if (!$opts{desc}) {
if ($opts{noedit}) {
$opts{desc} = getfield("Description: ", $opts{desc});
} else {
$opts{desc} = get_text($opts{desc}, $desc_head);
2015-08-19 15:49:10 -04:00
}
if (!$opts{desc}) {
die "missing desc:";
}
}
2015-08-19 15:49:10 -04:00
if (!$opts{summary}) {
$opts{summary} = getfield("Summary: ", $opts{summary});
if (!$opts{summary}) {
die "Summary is mandatory.";
}
}
my $input = {
fields => {
project => { key => $opts{project} },
issuetype => { name => $opts{type} },
summary => $opts{summary},
description => $opts{desc},
customfield_10024 => $opts{hash},
customfield_10025 => $opts{hash},
2015-08-19 15:49:10 -04:00
components => $opts{components_array},
2015-08-19 15:58:05 -04:00
versions => $opts{versions_array}
},
};
if ($opts{debug}) {
print Dumper \%opts;
print Dumper $input;
} else {
$issue = $jira->POST('/issue', undef, $input) or die "Issue was not created:";
print "Issue Posted: " . $issue->{key} . "\n";
2015-08-19 17:09:08 -04:00
if ($opts{versions_array}) {
$input = {
update => {
fixVersions => [
{set => $opts{versions_array}}
]
}
};
$jira->PUT("/issue/" . $issue->{key}, undef, $input);
print "Fix versions updated for issue " . $issue->{key} . "\n";
}
2015-08-19 17:09:08 -04:00
if ($opts{attach}) {
$jira->attach_files($issue->{key}, @ARGV);
printf "%d file%s attached.\n", scalar @ARGV, scalar @ARGV == 1 ? "" : "s";
}
}