First draft of the bulk-prep-pay script.
This commit is contained in:
		
							parent
							
								
									052d32fc5e
								
							
						
					
					
						commit
						7ec2c7a291
					
				
					 1 changed files with 68 additions and 0 deletions
				
			
		
							
								
								
									
										68
									
								
								scripts/rt-bulk-prep-pay.plx
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								scripts/rt-bulk-prep-pay.plx
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,68 @@ | |||
| #!/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, $RT_CMD, $SVN_CMD); | ||||
| 
 | ||||
| ############################################################################### | ||||
| sub TicketIDsReadyForPayment () { | ||||
|   my @ticketSpecs; | ||||
|   open(my $rtLsFH, "-|", "$RT_CMD", "ls", "-i", "Status = 'ready-for-payment'"); | ||||
|   while (my $lsLine = <$rtLsFH>) { | ||||
|     chomp $lsLine; | ||||
|     push(@ticketSpecs, $lsLine); | ||||
|   } | ||||
|   close $rtLsFH; | ||||
|   return @ticketSpecs; | ||||
| } | ||||
| ############################################################################### | ||||
| sub FindMostRecentPaymentMethodForTicket ($) { | ||||
|   my($ticketSpec) = @_; | ||||
|   my $paymentMethod; | ||||
| 
 | ||||
|   open(my $rtShowFH, "-|", "$RT_CMD", "ls", "-i", "Status = 'ready-for-payment'"); | ||||
|   while (my $showLine = <$rtShowFH>) { | ||||
|     $paymentMethod = $1 | ||||
|       if ($showLine =~ /\s+PAYMENT\s+METHOD\s*:\s*(.*?)\s*$/); | ||||
|     # don't 'last' when found as we want the last one. | ||||
|   } | ||||
|   close $rtShowFH; | ||||
|   return $paymentMethod; | ||||
| } | ||||
| ############################################################################### | ||||
| 
 | ||||
| GetOptions("verbose=i" => \$VERBOSE, "interactive" => \$INTERACTIVE, | ||||
|            "rtCommand=s" => \$RT_CMD, "svnCommand=s" => \$SVN_CMD); | ||||
| 
 | ||||
| $RT_CMD = '/usr/bin/rt' unless defined $RT_CMD; | ||||
| $SVN_CMD = '/usr/bin/svn' unless defined $SVN_CMD; | ||||
| 
 | ||||
| $INTERACTIVE = 0 if not defined $INTERACTIVE; | ||||
| 
 | ||||
| my @ticketSpecs = TicketIDsReadyForPayment(); | ||||
| 
 | ||||
| my %payments; | ||||
| foreach my $ticketSpec (@ticketSpec) { | ||||
|   my $paymentMethod = FindMostRecentPaymentMethodForTicket($ticketSpec); | ||||
|   die "Cannot find payment method for ticket, $ticketSpec" unless defined $paymentMethod; | ||||
|   push(@{$payments{$paymentMethod}}, $ticketSpec); | ||||
| } | ||||
| foreach my $paymentMethod (sort { $a cmp $b } keys %payments) { | ||||
|   print "$paymentMethod: Count: ", scalar(@{$payments{$paymentMethod}}), "\n"; | ||||
|   print "     Tickets: ", join(", ", map { s%^\s*ticket\s*/\s*%%; } @{$payments{$paymentMethod}}); | ||||
| } | ||||
| ############################################################################### | ||||
| # | ||||
| # Local variables: | ||||
| # compile-command: "perl -c rt-bulk-prep-pay.plx" | ||||
| # perl-indent-level: 2 | ||||
| # End: | ||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Bradley M. Kuhn
						Bradley M. Kuhn