Make Query String a CLI option; leave defaults of interest.
This commit is contained in:
parent
4775799a99
commit
01decbbd55
1 changed files with 32 additions and 6 deletions
|
@ -11,13 +11,24 @@ use Getopt::Long;
|
|||
use File::Spec;
|
||||
use Date::Manip qw(ParseDate UnixDate);
|
||||
|
||||
my($VERBOSE, $INTERACTIVE, $RT_CMD, $SVN_CMD);
|
||||
my($VERBOSE, $INTERACTIVE, $RT_CMD, $SVN_CMD, %AMOUNTS, $SHOW_AMOUNTS, $QUERY_STRING);
|
||||
|
||||
###############################################################################
|
||||
sub TicketIDsReadyForPayment () {
|
||||
my @ticketSpecs;
|
||||
open(my $rtLsFH, "-|", "$RT_CMD", "ls", "-i", "Status = 'ready-for-payment'");
|
||||
my $queryString = $QUERY_STRING;
|
||||
|
||||
if (not defined $queryString or $queryString =~ /^\s*$/) {
|
||||
$queryString = "Status = 'ready-for-payment' and Owner = 'bkuhn' and Queue = 'outreachy-interns' and Subject like '%2019-12%'";
|
||||
$queryString = "Status = 'ready-for-payment' and Owner = 'bkuhn' and Due < '2020-04-30'";
|
||||
$queryString = "Status = 'ready-for-payment'";
|
||||
$queryString = "Status = 'ready-for-payment' and 'CF.{payment-method}' = 'USD PayPal'";
|
||||
$queryString = "Status = 'ready-for-payment'";
|
||||
}
|
||||
print "Using $queryString\n";
|
||||
open(my $rtLsFH, "-|", "$RT_CMD", "ls", "-i", $queryString);
|
||||
print "Running: rt ls -i Status=ready-for-payment\n" if ($VERBOSE >= 10);
|
||||
|
||||
while (my $lsLine = <$rtLsFH>) {
|
||||
print "rt ls line from Ready for payment search: $lsLine" if ($VERBOSE >= 10);
|
||||
chomp $lsLine;
|
||||
|
@ -33,20 +44,35 @@ sub FindMostRecentPaymentMethodForTicket ($) {
|
|||
my($ticketSpec) = @_;
|
||||
my $paymentMethod;
|
||||
$ticketSpec =~ s%^\s*ticket\s*/\s*%%;
|
||||
open(my $rtShowFH, "-|", "$RT_CMD", "show", $ticketSpec);
|
||||
open(my $rtShowFH, "-|", "$RT_CMD", "show", '-t', 'ticket', '-f', 'CF.{payment-method}', $ticketSpec);
|
||||
my($ticketDataAgain, $value) = <$rtShowFH>;
|
||||
|
||||
close $rtShowFH;
|
||||
|
||||
chomp $value; $value =~ s/^\s*cf.{payment-method}\s*:\s+(.*)$/$1/i
|
||||
or warn "$ticketSpec: Unknown value for payment-method of \"$value\"";
|
||||
if (not defined $value or $value =~ /^\s*$/) {
|
||||
$value = "NO-CF-SET";
|
||||
} elsif ($value ne 'FX Wire') {
|
||||
return $value unless $SHOW_AMOUNTS;
|
||||
}
|
||||
$ticketSpec =~ s%^\s*ticket\s*/\s*%%;
|
||||
open($rtShowFH, "-|", "$RT_CMD", "show", $ticketSpec);
|
||||
while (my $showLine = <$rtShowFH>) {
|
||||
print STDERR "rt show line for $ticketSpec: $showLine" if ($VERBOSE >= 10);
|
||||
$paymentMethod = lc($1)
|
||||
if ($showLine =~ /^\s*PAYMENT\s+METHOD\s*:\s*(.*?)\s*$/);
|
||||
# don't 'last' when found as we want the last one.
|
||||
$AMOUNTS{$ticketSpec} = $1
|
||||
if ($showLine =~ /^\s*(?:TOTAL|AMOUNT)(?:\s*TO\s*PAY)?\s*:\s*(.*?)\s*$/i);
|
||||
}
|
||||
close $rtShowFH;
|
||||
return $paymentMethod;
|
||||
return ($value eq 'FX Wire' or $value eq 'NO-CF-SET') ? "$value: $paymentMethod" : $value;
|
||||
}
|
||||
###############################################################################
|
||||
|
||||
GetOptions("verbose=i" => \$VERBOSE, "interactive" => \$INTERACTIVE,
|
||||
"rtCommand=s" => \$RT_CMD, "svnCommand=s" => \$SVN_CMD);
|
||||
GetOptions("verbose=i" => \$VERBOSE, "interactive" => \$INTERACTIVE, 'showAmounts' => \$SHOW_AMOUNTS,
|
||||
"rtCommand=s" => \$RT_CMD, "svnCommand=s" => \$SVN_CMD, 'queryString=s' => \$QUERY_STRING);
|
||||
|
||||
$RT_CMD = '/usr/bin/rt' unless defined $RT_CMD;
|
||||
$SVN_CMD = '/usr/bin/svn' unless defined $SVN_CMD;
|
||||
|
|
Loading…
Reference in a new issue