2018-07-25 16:40:30 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# Copyright © 2018, Bradley M. Kuhn
|
|
|
|
# License: AGPL-3.0-or-later
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use autodie qw(:all);
|
|
|
|
|
|
|
|
use Getopt::Long;
|
|
|
|
use File::Spec;
|
|
|
|
use Date::Manip qw(ParseDate UnixDate);
|
|
|
|
|
|
|
|
my($VERBOSE, $INTERACTIVE, $RT_CMD, $SVN_CMD);
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
sub TicketIDsReadyForPayment () {
|
|
|
|
my @ticketSpecs;
|
|
|
|
open(my $rtLsFH, "-|", "$RT_CMD", "ls", "-i", "Status = 'ready-for-payment'");
|
2018-08-23 20:53:13 +00:00
|
|
|
print "Running: rt ls -i Status=ready-for-payment\n" if ($VERBOSE >= 10);
|
2018-07-25 16:40:30 +00:00
|
|
|
while (my $lsLine = <$rtLsFH>) {
|
2018-08-23 20:53:13 +00:00
|
|
|
print "rt ls line from Ready for payment search: $lsLine" if ($VERBOSE >= 10);
|
2018-07-25 16:40:30 +00:00
|
|
|
chomp $lsLine;
|
2018-08-23 20:53:13 +00:00
|
|
|
next if $lsLine =~ /^\s*$/; # There are sometimes blank lines in the rt ls -i output,
|
|
|
|
push(@ticketSpecs, $lsLine); # particularly with 0 results, and no empty strings go on this list
|
2018-07-25 16:40:30 +00:00
|
|
|
}
|
2018-08-23 20:53:13 +00:00
|
|
|
print "Done: rt ls -i Status=ready-for-payment\n" if ($VERBOSE >= 10);
|
2018-07-25 16:40:30 +00:00
|
|
|
close $rtLsFH;
|
|
|
|
return @ticketSpecs;
|
|
|
|
}
|
|
|
|
###############################################################################
|
|
|
|
sub FindMostRecentPaymentMethodForTicket ($) {
|
|
|
|
my($ticketSpec) = @_;
|
|
|
|
my $paymentMethod;
|
2018-07-25 16:44:19 +00:00
|
|
|
$ticketSpec =~ s%^\s*ticket\s*/\s*%%;
|
|
|
|
open(my $rtShowFH, "-|", "$RT_CMD", "show", $ticketSpec);
|
2018-07-25 16:40:30 +00:00
|
|
|
while (my $showLine = <$rtShowFH>) {
|
2018-07-25 16:44:19 +00:00
|
|
|
print STDERR "rt show line for $ticketSpec: $showLine" if ($VERBOSE >= 10);
|
2018-07-25 20:57:27 +00:00
|
|
|
$paymentMethod = lc($1)
|
2018-07-25 16:49:34 +00:00
|
|
|
if ($showLine =~ /^\s*PAYMENT\s+METHOD\s*:\s*(.*?)\s*$/);
|
2018-07-25 16:40:30 +00:00
|
|
|
# don't 'last' when found as we want the last one.
|
|
|
|
}
|
|
|
|
close $rtShowFH;
|
|
|
|
return $paymentMethod;
|
|
|
|
}
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
GetOptions("verbose=i" => \$VERBOSE, "interactive" => \$INTERACTIVE,
|
|
|
|
"rtCommand=s" => \$RT_CMD, "svnCommand=s" => \$SVN_CMD);
|
|
|
|
|
|
|
|
$RT_CMD = '/usr/bin/rt' unless defined $RT_CMD;
|
|
|
|
$SVN_CMD = '/usr/bin/svn' unless defined $SVN_CMD;
|
|
|
|
|
|
|
|
$INTERACTIVE = 0 if not defined $INTERACTIVE;
|
|
|
|
|
|
|
|
my @ticketSpecs = TicketIDsReadyForPayment();
|
|
|
|
|
2018-08-23 20:53:32 +00:00
|
|
|
if (@ticketSpecs <= 0) {
|
|
|
|
print "No tickets found that are ready for payment at this time\n";
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
|
2018-07-25 16:40:30 +00:00
|
|
|
my %payments;
|
2018-07-25 16:44:14 +00:00
|
|
|
foreach my $ticketSpec (@ticketSpecs) {
|
2018-07-25 16:40:30 +00:00
|
|
|
my $paymentMethod = FindMostRecentPaymentMethodForTicket($ticketSpec);
|
2018-08-07 17:32:09 +00:00
|
|
|
print STDERR "$ticketSpec has payment method of $paymentMethod\n" if ($VERBOSE > 6);
|
|
|
|
if (not defined $paymentMethod) {
|
|
|
|
warn "Cannot find payment method for ticket, $ticketSpec";
|
|
|
|
$paymentMethod = "UNKNOWN PAYMENT METHOD";
|
|
|
|
}
|
2018-07-25 16:40:30 +00:00
|
|
|
push(@{$payments{$paymentMethod}}, $ticketSpec);
|
|
|
|
}
|
|
|
|
foreach my $paymentMethod (sort { $a cmp $b } keys %payments) {
|
|
|
|
print "$paymentMethod: Count: ", scalar(@{$payments{$paymentMethod}}), "\n";
|
2018-07-25 16:49:50 +00:00
|
|
|
print " Tickets: ", join(", ", map { s%^\s*ticket\s*/\s*%%; $_; } @{$payments{$paymentMethod}}), "\n";
|
2018-07-25 16:40:30 +00:00
|
|
|
}
|
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# Local variables:
|
|
|
|
# compile-command: "perl -c rt-bulk-prep-pay.plx"
|
|
|
|
# perl-indent-level: 2
|
|
|
|
# End:
|