120 lines
5.1 KiB
Text
120 lines
5.1 KiB
Text
|
#!/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, $PAYMENT_NUMBER, $SVN_CMD, $ROUND, $TRAVEL_NOTICE_TICKET, $ACTIVATE_TICKET_CORRESPONDENCE_FILE);
|
||
|
|
||
|
our $RT_CMD;
|
||
|
our $VERBOSE;
|
||
|
require 'rt-helper.pl';
|
||
|
|
||
|
|
||
|
###############################################################################
|
||
|
|
||
|
GetOptions("verbose=i" => \$VERBOSE, "interactive" => \$INTERACTIVE,
|
||
|
"paymentNumber=i" => \$PAYMENT_NUMBER, "rtCommand=s" => \$RT_CMD,
|
||
|
"svnCommand=s" => \$SVN_CMD, "round=s" => \$ROUND,
|
||
|
"activateInstructions=s" => \$ACTIVATE_TICKET_CORRESPONDENCE_FILE,
|
||
|
'travelNoticeTicket=i' => \$TRAVEL_NOTICE_TICKET);
|
||
|
|
||
|
|
||
|
$RT_CMD = '/usr/bin/rt' unless defined $RT_CMD;
|
||
|
$SVN_CMD = '/usr/bin/svn' unless defined $SVN_CMD;
|
||
|
|
||
|
$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 $PAYMENT_NUMBER and $PAYMENT_NUMBER =~ /^[123]$/) {
|
||
|
print STDERR "usage: $0 --paymentNumber=<VALUE> option is required and must be 1, 2 or 3\n";
|
||
|
exit 1;
|
||
|
}
|
||
|
unless (defined $TRAVEL_NOTICE_TICKET) {
|
||
|
print STDERR "usage: $0 --travelNoticeTicket=<TICKET_NUMBER> option is required and must be an integer\n";
|
||
|
exit 1;
|
||
|
}
|
||
|
unless (-r $ACTIVATE_TICKET_CORRESPONDENCE_FILE and -f $ACTIVATE_TICKET_CORRESPONDENCE_FILE) {
|
||
|
print STDERR "usage: $0 --activateInstructions=<FILE> option is required and must be readible text file\n";
|
||
|
exit 1;
|
||
|
}
|
||
|
my @activateInstructions;
|
||
|
open (my $activateFH, "<", $ACTIVATE_TICKET_CORRESPONDENCE_FILE);
|
||
|
while (my $line = <$activateFH>) {
|
||
|
push(@activateInstructions, $line);
|
||
|
}
|
||
|
close $activateFH;
|
||
|
|
||
|
my @ticketSpecs = Outreachy_FindMainTicketsInRound($ROUND);
|
||
|
my $expectedCompletedInternshipField = '(payment-' . $PAYMENT_NUMBER . '-approved|unsuccessful)';
|
||
|
|
||
|
my(%noticeTicketLinks) = GetLinksForTicket("ticket/" . $TRAVEL_NOTICE_TICKET);
|
||
|
|
||
|
if ($VERBOSE > 5) {
|
||
|
use Data::Dumper;
|
||
|
print STDERR "Travel Notice Ticket links are: \n", Data::Dumper->Dump([\%noticeTicketLinks]);
|
||
|
}
|
||
|
foreach my $ticketSpec (@ticketSpecs) {
|
||
|
my(%links) = GetLinksForTicket($ticketSpec);
|
||
|
if ($VERBOSE > 5) {
|
||
|
use Data::Dumper;
|
||
|
print STDERR "$ticketSpec has links as follows: \n", Data::Dumper->Dump([\%links]);
|
||
|
}
|
||
|
my $reimbursementTicket = FindReimbursementTicketFromList($ROUND, @{$links{Members}});
|
||
|
if (not defined $reimbursementTicket) {
|
||
|
print STDERR "\"$ticketSpec\": Skipped: no reimbursement ticket found.\n";
|
||
|
next;
|
||
|
}
|
||
|
my $reimburseStatus = GetStatusFromTicket($reimbursementTicket);
|
||
|
|
||
|
my $completedInternshipField = GetCustomFieldForTicket($ticketSpec, "completed-internship");
|
||
|
if ($completedInternshipField =~ /unsuccessful/) {
|
||
|
# For unsuccessful, just verify that the ticket is unlinked from travel notice ticket
|
||
|
# and already in rejected status.
|
||
|
if ($reimburseStatus ne 'rejected') {
|
||
|
print STDERR "\"$ticketSpec\": \"$reimbursementTicket\": Skipped: reimbursement ticket in state of \"$reimburseStatus\" but should be rejected since intern was unsuccessful\n";
|
||
|
next;
|
||
|
}
|
||
|
if ($reimbursementTicket ~~ @{$noticeTicketLinks{DependedOnBy}}) {
|
||
|
print STDERR "\"$ticketSpec\": \"$reimbursementTicket\": Skipped: reimbursement ticket still linked to travel notice ticket of $TRAVEL_NOTICE_TICKET, but it should not be since intern was unsuccessful\n";
|
||
|
next;
|
||
|
}
|
||
|
} else {
|
||
|
# Otherwise, the intern hasn't failed yet, so check they've received $PAYMENT_NUMBER payment and activate notice.
|
||
|
my $date = PaymentDateByTicket($ticketSpec, $PAYMENT_NUMBER);
|
||
|
if (not defined $date) {
|
||
|
print STDERR "\"$ticketSpec\": \"$reimbursementTicket\": Skipped: Payment $PAYMENT_NUMBER appears to not have been completed, so not activating travel ticket.\n";
|
||
|
next;
|
||
|
}
|
||
|
if ("ticket/$reimbursementTicket" ~~ @{$noticeTicketLinks{DependedOnBy}}) {
|
||
|
open(my $rtCorrespondFH, "|-", $RT_CMD, 'correspond', $reimbursementTicket, '-m', '-');
|
||
|
foreach my $line (@activateInstructions) { print $rtCorrespondFH $line; }
|
||
|
close $rtCorrespondFH;
|
||
|
system($RT_CMD, "link", '-d', $reimbursementTicket, 'dependson', $TRAVEL_NOTICE_TICKET);
|
||
|
system($RT_CMD, "link", $TRAVEL_NOTICE_TICKET, 'refersto', $reimbursementTicket);
|
||
|
system($RT_CMD, "edit", $reimbursementTicket, 'set',
|
||
|
'Due=2019-05-14 18:00' , 'CF.{due-date-from}=budget-expiration', 'status=awaiting-request');
|
||
|
} elsif ("ticket/$reimbursementTicket" ~~ @{$noticeTicketLinks{RefersTo}}) {
|
||
|
print STDERR "\"$ticketSpec\": \"$reimbursementTicket\": Skipped: ALREADY PROCESSED.\n";
|
||
|
} else {
|
||
|
print STDERR "\"$ticketSpec\": \"$reimbursementTicket\": Skipped: $TRAVEL_NOTICE_TICKET does not include $reimbursementTicket in its list of DependedOnBy tickets, but that is only reason for skip .\n";
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
###############################################################################
|
||
|
#
|
||
|
# Local variables:
|
||
|
# compile-command: "perl -c rt-outreachy-activate-travel-tickets.plx"
|
||
|
# perl-indent-level: 2
|
||
|
# End:
|