Add --round CLI argument; use that round for search criterion.

This commit is contained in:
Bradley M. Kuhn 2018-07-22 19:25:49 -07:00
parent 8aa05bff6d
commit 5697b6beee

View file

@ -12,12 +12,13 @@ use File::Spec;
use Date::Manip qw(ParseDate UnixDate); use Date::Manip qw(ParseDate UnixDate);
my($PAYMENT_DIR, $VERBOSE, $INTERACTIVE, $PAYMENT_NUMBER, $RT_CMD, $INVOICE_LINE, $INTERN_SUCCESS_FILE, my($PAYMENT_DIR, $VERBOSE, $INTERACTIVE, $PAYMENT_NUMBER, $RT_CMD, $INVOICE_LINE, $INTERN_SUCCESS_FILE,
$INTERN_FAIL_FILE, $LEDGER_ENTRY_DATE, $SVN_CMD); $INTERN_FAIL_FILE, $LEDGER_ENTRY_DATE, $SVN_CMD, $ROUND);
############################################################################### ###############################################################################
sub FindUniqueTicket(@) { sub FindUniqueTicket(@) {
my @searchTerms = @_; my @searchTerms = @_;
open(my $rtLsFH, "-|", "$RT_CMD", "ls", "-i", 'Queue = outreachy-interns AND ' . open(my $rtLsFH, "-|", "$RT_CMD", "ls", "-i", 'Queue = outreachy-interns ' .
"AND Subject LIKE '" . $ROUND . "' AND" .
join(" AND ", @searchTerms)); join(" AND ", @searchTerms));
my $ticketSpec; my $ticketSpec;
while (my $lsLine = <$rtLsFH>) { while (my $lsLine = <$rtLsFH>) {
@ -117,7 +118,8 @@ sub FindReimbursementTicketFromList(@) {
foreach my $ticket (@_) { foreach my $ticket (@_) {
$ticket =~ s%\s*ticket/?\s*(\d+)\s*%$1%; $ticket =~ s%\s*ticket/?\s*(\d+)\s*%$1%;
open(my $rtReimburseFH, "-|", "$RT_CMD", "ls", "-i", 'Queue = accounts-payable AND ' . open(my $rtReimburseFH, "-|", "$RT_CMD", "ls", "-i", 'Queue = accounts-payable AND ' .
"(Subject LIKE 'reimbursement' OR Subject LIKE 'travel') and id = " . $ticket); "AND Subject LIKE '" . $ROUND .
"' AND (Subject LIKE 'reimbursement' OR Subject LIKE 'travel') and id = " . $ticket);
while (my $reimburseLine = <$rtReimburseFH>) { while (my $reimburseLine = <$rtReimburseFH>) {
if ($reimburseLine =~ m%\s*ticket\s*/?\s*(\d+)\s*$%) { if ($reimburseLine =~ m%\s*ticket\s*/?\s*(\d+)\s*$%) {
my $tt = $1; my $tt = $1;
@ -167,13 +169,17 @@ GetOptions("paymentDir=s" => \$PAYMENT_DIR, "verbose=i" => \$VERBOSE, "interacti
"paymentNumber=i" => \$PAYMENT_NUMBER, "rtCommand=s" => \$RT_CMD, "paymentNumber=i" => \$PAYMENT_NUMBER, "rtCommand=s" => \$RT_CMD,
"invoiceLine=s" => \$INVOICE_LINE, "internSuccessFile=s", \$INTERN_SUCCESS_FILE, "invoiceLine=s" => \$INVOICE_LINE, "internSuccessFile=s", \$INTERN_SUCCESS_FILE,
"internFailFile=s", \$INTERN_FAIL_FILE, 'ledgerEntryDate=s' => \$LEDGER_ENTRY_DATE, "internFailFile=s", \$INTERN_FAIL_FILE, 'ledgerEntryDate=s' => \$LEDGER_ENTRY_DATE,
"svnCommand=s" => \$SVN_CMD); "svnCommand=s" => \$SVN_CMD, "round=s" => \$ROUND);
$RT_CMD = '/usr/bin/rt' unless defined $RT_CMD; $RT_CMD = '/usr/bin/rt' unless defined $RT_CMD;
$SVN_CMD = '/usr/bin/svn' unless defined $SVN_CMD; $SVN_CMD = '/usr/bin/svn' unless defined $SVN_CMD;
$INTERACTIVE = 0 if not defined $INTERACTIVE; $INTERACTIVE = 0 if not defined $INTERACTIVE;
unless (defined $ROUND and $ROUND =~ /^[\d\-]+$/) {
print STDERR "usage: $0 --round=<YEAR-MONTH> option is required and must formated as YYYY-MM\n";
exit 1;
}
unless (defined $LEDGER_ENTRY_DATE and $LEDGER_ENTRY_DATE =~ /^[\d\-]+$/) { unless (defined $LEDGER_ENTRY_DATE and $LEDGER_ENTRY_DATE =~ /^[\d\-]+$/) {
print STDERR "usage: $0 --ledgerEntryDate=<DATE> option is required and must be in ISO 8601 format\n"; print STDERR "usage: $0 --ledgerEntryDate=<DATE> option is required and must be in ISO 8601 format\n";
exit 1; exit 1;