136 lines
4 KiB
Perl
136 lines
4 KiB
Perl
# -*- Perl -*-
|
|
# Copyright © 2018, Bradley M. Kuhn
|
|
# License: AGPL-3.0-or-later
|
|
use strict;
|
|
use warnings;
|
|
|
|
use autodie qw(:all);
|
|
our $RT_CMD;
|
|
|
|
###############################################################################
|
|
sub Outreachy_FindUniqueTicket($@) {
|
|
my($round, @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 Outreachy_FindMainTicketsInRound($) {
|
|
my($round) = @_;
|
|
open(my $rtLsFH, "-|",
|
|
$RT_CMD, "ls", "-i", 'Queue = outreachy-interns ' .
|
|
"AND Subject LIKE '" . $round . "'");
|
|
my @ticketSpecs;
|
|
while (my $lsLine = <$rtLsFH>) {
|
|
chomp $lsLine;
|
|
if ($lsLine =~ /ticket/) {
|
|
push(@ticketSpecs, $lsLine);
|
|
}
|
|
}
|
|
close $rtLsFH;
|
|
return @ticketSpecs;
|
|
}
|
|
###############################################################################
|
|
sub GetLinksForTicket($) {
|
|
my($ticketSpec) = @_;
|
|
my %linked;
|
|
open(my $rtLinksFH, "-|", "$RT_CMD", "show", $ticketSpec . '/links');
|
|
my $type = 'NONE';
|
|
while (my $linksLine = <$rtLinksFH>) {
|
|
if ($linksLine =~ m%\s*([^:]+)\s:%) {
|
|
$type = $1;
|
|
}
|
|
if ($linksLine =~ m%rt.*(ticket/\d+)\s*,?\s*$%) {
|
|
push(@{$linked{$type}}, $1) if $type !~ /(NONE|id)/i;
|
|
}
|
|
}
|
|
close $rtLinksFH;
|
|
return %linked;
|
|
}
|
|
###############################################################################
|
|
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;
|
|
}
|
|
###############################################################################
|
|
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;
|
|
}
|
|
###############################################################################
|
|
sub FindReimbursementTicketFromList(@) {
|
|
my $reimbursementTicket;
|
|
foreach my $ticket (@_) {
|
|
$ticket =~ s%\s*ticket/?\s*(\d+)\s*%$1%;
|
|
open(my $rtReimburseFH, "-|", "$RT_CMD", "ls", "-i", 'Queue = accounts-payable AND ' .
|
|
"AND Subject LIKE '" . $ROUND .
|
|
"' 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;
|
|
}
|
|
}
|
|
}
|
|
close $rtReimburseFH;
|
|
last if defined $reimbursementTicket;
|
|
}
|
|
return $reimbursementTicket;
|
|
}
|
|
###############################################################################
|
|
1;
|
|
###############################################################################
|
|
#
|
|
# Local variables:
|
|
# compile-command: "perl -c rt-helper.pl"
|
|
# perl-indent-level: 2
|
|
# End:
|