Create rt-helper.pl and move one function to it.
Move function to rt-helper.pl that might be used in other Perl scripts.
This commit is contained in:
parent
c9c3b8b01e
commit
34e00ca5f0
2 changed files with 35 additions and 22 deletions
31
scripts/rt-helper.pl
Normal file
31
scripts/rt-helper.pl
Normal file
|
@ -0,0 +1,31 @@
|
|||
# -*- Perl -*-
|
||||
# Copyright © 2018, Bradley M. Kuhn
|
||||
# License: AGPL-3.0-or-later
|
||||
###############################################################################
|
||||
sub Outreachy_FindUniqueTicket(@) {
|
||||
my @searchTerms = @_;
|
||||
open(my $rtLsFH, "-|", "$RT_CMD", "ls", "-i", 'Queue = outreachy-interns ' .
|
||||
"AND Subject LIKE '" . $ROUND . "' AND" .
|
||||
join(" AND ", @searchTerms));
|
||||
my $ticketSpec;
|
||||
while (my $lsLine = <$rtLsFH>) {
|
||||
chomp $lsLine;
|
||||
if ($lsLine =~ /ticket/) {
|
||||
if (defined $ticketSpec) {
|
||||
$ticketSpec = undef;
|
||||
last;
|
||||
}
|
||||
$ticketSpec = $lsLine;
|
||||
}
|
||||
}
|
||||
close $rtLsFH;
|
||||
return $ticketSpec;
|
||||
}
|
||||
###############################################################################
|
||||
1;
|
||||
###############################################################################
|
||||
#
|
||||
# Local variables:
|
||||
# compile-command: "perl -c rt-helper.pl"
|
||||
# perl-indent-level: 2
|
||||
# End:
|
|
@ -11,29 +11,11 @@ use Getopt::Long;
|
|||
use File::Spec;
|
||||
use Date::Manip qw(ParseDate UnixDate);
|
||||
|
||||
require 'rt-helper.pl';
|
||||
|
||||
my($PAYMENT_DIR, $VERBOSE, $INTERACTIVE, $PAYMENT_NUMBER, $RT_CMD, $INVOICE_LINE, $INTERN_SUCCESS_FILE,
|
||||
$INTERN_FAIL_FILE, $LEDGER_ENTRY_DATE, $SVN_CMD, $ROUND, $TRAVEL_NOTICE_TICKET);
|
||||
|
||||
###############################################################################
|
||||
sub FindUniqueTicket(@) {
|
||||
my @searchTerms = @_;
|
||||
open(my $rtLsFH, "-|", "$RT_CMD", "ls", "-i", 'Queue = outreachy-interns ' .
|
||||
"AND Subject LIKE '" . $ROUND . "' AND" .
|
||||
join(" AND ", @searchTerms));
|
||||
my $ticketSpec;
|
||||
while (my $lsLine = <$rtLsFH>) {
|
||||
chomp $lsLine;
|
||||
if ($lsLine =~ /ticket/) {
|
||||
if (defined $ticketSpec) {
|
||||
$ticketSpec = undef;
|
||||
last;
|
||||
}
|
||||
$ticketSpec = $lsLine;
|
||||
}
|
||||
}
|
||||
close $rtLsFH;
|
||||
return $ticketSpec;
|
||||
}
|
||||
###############################################################################
|
||||
sub PaymentDateByTicket($$) {
|
||||
my($ticketSpec, $paymentNumber) = @_;
|
||||
|
@ -252,10 +234,10 @@ while (my $file = readdir $dh) {
|
|||
push(@searchTerms, 'Subject LIKE "' . $name . '"');
|
||||
}
|
||||
# Find the ticket number for this intern.
|
||||
my $ticket = FindUniqueTicket(@searchTerms);
|
||||
my $ticket = Outreachy_FindUniqueTicket(@searchTerms);
|
||||
if (not defined $ticket) {
|
||||
foreach my $term (@searchTerms) {
|
||||
$ticket = FindUniqueTicket(($term));
|
||||
$ticket = Outreachy_FindUniqueTicket(($term));
|
||||
last if (defined $ticket);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue