Tester, Intrepid made changes - Today 2:22 PM
Status Open [ 1 ] Open [ 1 ]
Test Case State In Progress { "state":"Can't Test","tp":"","tpStart":"false"}
####
Tester, Intrepid made changes - Today 2:38 PM
Status Open [ 1 ] Open [ 1 ]
Test Case State In Progress Can't Test
##
##
$jira->progress_workflow_action_safely( $s_vetted_key, 'Change Test Case State', {custom_fields => { 'customfield_10213' => { '0' => $s_target_state}}}) ;
##
##
#!/usr/bin/perl -w
# Sample Perl client accessing JIRA via SOAP using the CPAN
# JIRA::Client module, to update a test case
#
use strict;
use warnings;
use Data::Dumper;
use DateTime;
use JIRA::Client;
use Term::ReadKey;
$|++;
my $ra_states = { a => 'Passed', b =>'Failed', c =>'In Progress', d => q{Can't Test}, q => 'quit'};
my $s_jira_url = 'https://jira.thankless_employer.com';
my $s_jirauser;
my $s_passwd;
print "\nCorp. login?:\t";
$s_jirauser = ReadLine(0);
chomp $s_jirauser;
ReadMode(2);
print "\nCorp. passwd?:\t";
$s_passwd = ReadLine(0);
chomp $s_passwd;
ReadMode(0);
print "\nThanks...\nNow connecting to $s_jira_url.\n";
my $jira = eval{JIRA::Client->new($s_jira_url, $s_jirauser, $s_passwd)} or die("Could not log into $s_jira_url. Here's the problem: $@");
print "Connected.\n";
my $s_target_state = &choose_state($ra_states);
my $command = ".";
if ($s_target_state ne "quit")
{
print "\nEnter a liat of test subcase id's (or \"help\", if you need help, or \"state\" if you want to change the target state):\n\n";
}
else
{
exit;
}
my $rh_test_subcases_to_update = {};
while( $command && $command !~ /^N(o|eg|yet|ein|icht)?|Q(uit)?/i )
{
print "\n$s_target_state >> ";
$command = ;
chop $command;
if ( $command =~ /^help/i)
{
help();
}
elsif ( $command =~ /\bstate\b/i)
{
$s_target_state = &choose_state($ra_states);
}
elsif ( $command && $command !~ /^N(o|eg|yet|ein|icht)?|Q(uit)?/i)
{
my $s_raw_id;
my @a_raw_ids = split /(?:\s+|\s*?,\s*|\s*?;\s*)/, $command;
foreach $s_raw_id (@a_raw_ids)
{
my $issue;
my @a_errors;
if ($s_raw_id !~ s/^((DS)?-)?(\d+)$/DS-$3/i)
{
push @a_errors, "$s_raw_id does not look like an issue Key."
}
else
{
unless ($issue = eval{ $jira->getIssue($s_raw_id)})
{
push @a_errors, "issue $s_raw_id could not be found in $s_jira_url: $?";
}
else
{
#unless ( $issue->{type} eq 'Test Subcase' )
#{
# push @a_errors, "issue $s_raw_id is not a 'Test Subcase', but a '" . $issue->{type} . "'.";
#}
unless ( $issue->{type} == 14 )
{
push @a_errors, "issue $s_raw_id is not a '14', but a '" . $issue->{type} . "'.";
}
unless ( $issue->{assignee} eq $s_jirauser )
{
push @a_errors, "issue $s_raw_id is not assigned to '$s_jirauser', but to '" . $issue->{assignee} . "'.";
}
}
}
if ( scalar @a_errors == 0 )
{
if (not exists $rh_test_subcases_to_update->{$s_target_state})
{
$rh_test_subcases_to_update->{$s_target_state} = [];
}
push @{$rh_test_subcases_to_update->{$s_target_state}}, $s_raw_id;
}
else
{
print "\nI cannot set the state of $s_raw_id to $s_target_state for the following " . (scalar @a_errors > 1 ? "reasons" : "reason") . ":\n";
print "\n" . join "\n", @a_errors;
print "\n";
}
}
print "Alright. Any more?\n";
}
}
print "\n$s_jirauser has ended the list.\n";
foreach $s_target_state (keys %{$rh_test_subcases_to_update} )
{
foreach my $s_vetted_key ( @{$rh_test_subcases_to_update->{$s_target_state}} )
{
$jira->progress_workflow_action_safely( $s_vetted_key, 'Change Test Case State', {custom_fields => { 'customfield_10213' => { '0' => $s_target_state}}}) ;
print "\nChanged test subcase '$s_vetted_key' to '$s_target_state'.";
}
}
exit;
sub choose_state
{
my $ra_states = shift;
my ($raw_entry, $s_key, $s_state_choice);
$s_key = '';
while( not (exists $ra_states->{$s_key}) )
{
print "\nPlease choose a target state (by letter) from the following list:\n\n";
foreach $s_key (sort keys %{$ra_states})
{
print sprintf "%s.\t%s\n", $s_key, $ra_states->{$s_key};
}
print "\n";
$raw_entry = ;
chop $raw_entry;
$raw_entry = lc($raw_entry);
if ( $raw_entry =~ /^help/i)
{
help();
}
elsif ( exists $ra_states->{$raw_entry} )
{
$s_key = $raw_entry;
$s_state_choice = $ra_states->{$s_key};
print "\n$s_jirauser chose $s_key: $s_state_choice...\n\n";
}
else
{
print "\nSorry, I did not understand your choice: $raw_entry\n";
}
}
exit if $s_state_choice eq 'quit';
return $s_state_choice;
}
sub help
{
print "\nThis is a utility to do small bulk updates from the command line on jira test subcases.\n";
print "\nFirst, choose the state you want to change the current group of test subcases to.\n";
print "\nThen, enter the test subcase IDs, either in one long list, or pressing \"Enter\" after each one.\n";
print "\nYou can change state for assignment at any time, and subsequently entered test subcase id's will be set to that state.\n";
print "\nTo prevent errors, this utility checks that the requested issue exists, is a test subcase, and is assigned to you before";
print "\nit actually makes the change. If for some reason it finds a problem, it alerts you to the problem so you can correct the";
print "\nchoice.";
print "\npress [Enter] to continue...\n";
my $nothing = ;
}