2018-07-25 20:57:02 +00:00
|
|
|
# -*- Perl -*-
|
|
|
|
# Copyright © 2018, Bradley M. Kuhn
|
|
|
|
# License: AGPL-3.0-or-later
|
2018-07-25 21:32:05 +00:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use autodie qw(:all);
|
|
|
|
our $RT_CMD;
|
2018-08-06 02:54:13 +00:00
|
|
|
our $VERBOSE;
|
2018-07-25 21:32:05 +00:00
|
|
|
|
2018-07-25 20:57:02 +00:00
|
|
|
###############################################################################
|
2018-07-25 21:32:05 +00:00
|
|
|
sub Outreachy_FindUniqueTicket($@) {
|
|
|
|
my($round, @searchTerms) = @_;
|
2018-07-25 20:57:02 +00:00
|
|
|
open(my $rtLsFH, "-|", "$RT_CMD", "ls", "-i", 'Queue = outreachy-interns ' .
|
2018-07-25 21:32:05 +00:00
|
|
|
"AND Subject LIKE '" . $round . "' AND" .
|
2018-07-25 20:57:02 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
###############################################################################
|
2018-07-25 21:01:36 +00:00
|
|
|
sub Outreachy_FindMainTicketsInRound($) {
|
|
|
|
my($round) = @_;
|
2018-07-25 21:32:05 +00:00
|
|
|
open(my $rtLsFH, "-|",
|
|
|
|
$RT_CMD, "ls", "-i", 'Queue = outreachy-interns ' .
|
|
|
|
"AND Subject LIKE '" . $round . "'");
|
2018-07-25 21:01:36 +00:00
|
|
|
my @ticketSpecs;
|
|
|
|
while (my $lsLine = <$rtLsFH>) {
|
|
|
|
chomp $lsLine;
|
|
|
|
if ($lsLine =~ /ticket/) {
|
|
|
|
push(@ticketSpecs, $lsLine);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close $rtLsFH;
|
|
|
|
return @ticketSpecs;
|
|
|
|
}
|
|
|
|
###############################################################################
|
2018-08-06 02:15:51 +00:00
|
|
|
sub GetLinksForTicket($) {
|
|
|
|
my($ticketSpec) = @_;
|
|
|
|
my %linked;
|
|
|
|
open(my $rtLinksFH, "-|", "$RT_CMD", "show", $ticketSpec . '/links');
|
|
|
|
my $type = 'NONE';
|
2020-07-21 20:50:27 +00:00
|
|
|
print STDERR "rt-helper: GetLinksForTicket: starting\n" if ($VERBOSE > 9);
|
2018-08-06 02:15:51 +00:00
|
|
|
while (my $linksLine = <$rtLinksFH>) {
|
2018-08-06 02:54:13 +00:00
|
|
|
print STDERR "rt-helper: GetLinksForTicket: processing line: $linksLine\n" if ($VERBOSE > 9);
|
|
|
|
if ($linksLine =~ m%^([^:\s]+)\s*:%) {
|
2018-08-06 02:15:51 +00:00
|
|
|
$type = $1;
|
2018-08-06 02:54:13 +00:00
|
|
|
print STDERR "rt-helper: GetLinksForTicket: type is now $type\n" if ($VERBOSE > 7);
|
2018-08-06 02:15:51 +00:00
|
|
|
}
|
2018-08-06 02:54:13 +00:00
|
|
|
if ($type !~ /(NONE|id)/i and $linksLine =~ m%rt.*(ticket/\d+)\s*,?\s*$%) {
|
|
|
|
my $val = $1;
|
|
|
|
push(@{$linked{$type}}, $val);
|
|
|
|
print STDERR "rt-helper: GetLinksForTicket: add link of $val for $type\n" if ($VERBOSE > 7);
|
2018-08-06 02:15:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
close $rtLinksFH;
|
|
|
|
return %linked;
|
|
|
|
}
|
|
|
|
###############################################################################
|
2018-07-25 21:02:12 +00:00
|
|
|
sub PaymentDateByTicket($$) {
|
|
|
|
my($ticketSpec, $paymentNumber) = @_;
|
|
|
|
open(my $rtPayFH, "-|", "$RT_CMD", "show", "-f", 'CF.{payment-' . $paymentNumber . '-sent}', $ticketSpec);
|
|
|
|
my $date;
|
|
|
|
while (my $payLine = <$rtPayFH>) {
|
|
|
|
chomp $payLine;
|
|
|
|
if ($payLine =~ /^\s*CF\s*.\s*{payment-$paymentNumber-sent}\s*:\s*[\d\-]+\s*$/) {
|
|
|
|
$date = $payLine;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close $rtPayFH;
|
|
|
|
return $date;
|
|
|
|
}
|
|
|
|
###############################################################################
|
2018-07-25 20:58:44 +00:00
|
|
|
sub GetStatusFromTicket($) {
|
|
|
|
my($ticketSpec) = @_;
|
|
|
|
my $status;
|
|
|
|
open(my $statusFH, "-|", "$RT_CMD", "show", "-f", 'Status', $ticketSpec);
|
|
|
|
while (my $statusLine = <$statusFH>) {
|
|
|
|
if ($statusLine =~ /\s*Status\s*:\s*(\S+)\s*$/) {
|
|
|
|
$status = $1;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close $statusFH;
|
|
|
|
return $status;
|
|
|
|
}
|
|
|
|
###############################################################################
|
|
|
|
sub GetCustomFieldForTicket($$) {
|
|
|
|
my($ticketSpec, $customField) = @_;
|
|
|
|
open(my $rtCustomFH, "-|", "$RT_CMD", "show", "-f", 'CF.{' . $customField .'}', $ticketSpec);
|
|
|
|
my $val;
|
|
|
|
while (my $customFieldLine = <$rtCustomFH>) {
|
|
|
|
chomp $customFieldLine;
|
|
|
|
if ($customFieldLine =~ /^\s*CF\s*.\s*{$customField}\s*:\s*(\S+)\s*$/) {
|
|
|
|
$val = $1;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close $rtCustomFH;
|
|
|
|
return $val;
|
|
|
|
}
|
|
|
|
###############################################################################
|
2018-08-06 02:28:04 +00:00
|
|
|
sub FindReimbursementTicketFromList($@) {
|
|
|
|
my($round, @ticketList) = @_;
|
2018-08-06 02:27:11 +00:00
|
|
|
my $reimbursementTicket;
|
2018-08-06 02:28:04 +00:00
|
|
|
foreach my $ticket (@ticketList) {
|
2018-08-06 02:27:11 +00:00
|
|
|
$ticket =~ s%\s*ticket/?\s*(\d+)\s*%$1%;
|
|
|
|
open(my $rtReimburseFH, "-|", "$RT_CMD", "ls", "-i", 'Queue = accounts-payable AND ' .
|
2018-08-06 02:28:04 +00:00
|
|
|
"AND Subject LIKE '" . $round .
|
2018-08-06 02:27:11 +00:00
|
|
|
"' AND (Subject LIKE 'reimbursement' OR Subject LIKE 'travel') and id = " . $ticket);
|
|
|
|
while (my $reimburseLine = <$rtReimburseFH>) {
|
|
|
|
if ($reimburseLine =~ m%\s*ticket\s*/?\s*(\d+)\s*$%) {
|
|
|
|
my $tt = $1;
|
|
|
|
if ($tt == $ticket) {
|
|
|
|
$reimbursementTicket = $ticket;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-21 20:50:14 +00:00
|
|
|
{ no autodie qw(:all);
|
|
|
|
close $rtReimburseFH;
|
|
|
|
}
|
2018-08-06 02:27:11 +00:00
|
|
|
last if defined $reimbursementTicket;
|
|
|
|
}
|
|
|
|
return $reimbursementTicket;
|
|
|
|
}
|
|
|
|
###############################################################################
|
2018-07-25 20:57:02 +00:00
|
|
|
1;
|
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# Local variables:
|
|
|
|
# compile-command: "perl -c rt-helper.pl"
|
|
|
|
# perl-indent-level: 2
|
|
|
|
# End:
|