Outreachy Payment Next script for RT
The Outreachy tickets have to move in some semi-automated fashion when Conservancy receives approval from the Outreachy PLC that mentors have approved Outreachy payments. This script will likely be too specific that it can't be used outside of Conservancy, but the details of what it does might be useful to learn how to glue together RT operations from the RT CLI. This first pass simply finds the tickets via the file names of the approval files as sent by Outreachy PLC.
This commit is contained in:
		
							parent
							
								
									3c4bf92c5f
								
							
						
					
					
						commit
						5ca9c0c0b3
					
				
					 1 changed files with 73 additions and 0 deletions
				
			
		
							
								
								
									
										73
									
								
								scripts/rt-outreachy-payment-next.plx
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										73
									
								
								scripts/rt-outreachy-payment-next.plx
									
										
									
									
									
										Executable file
									
								
							|  | @ -0,0 +1,73 @@ | |||
| #!/usr/bin/perl | ||||
| # Copyright © 2018, Bradley M. Kuhn | ||||
| #   License: AGPL-3.0-or-later | ||||
| 
 | ||||
| use strict; | ||||
| use warnings; | ||||
| 
 | ||||
| use autodie qw(open close opendir); | ||||
| 
 | ||||
| use Getopt::Long; | ||||
| use File::Spec; | ||||
| use Date::Manip qw(ParseDate UnixDate); | ||||
| 
 | ||||
| sub FindUniqueTicket(@) { | ||||
|   my @searchTerms = @_; | ||||
|   open(my $rtLsFH, "-|", "rt", "ls", "-i", 'Queue = outreachy-interns 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; | ||||
| } | ||||
| my($PAYMENT_DIR, $VERBOSE); | ||||
| 
 | ||||
| GetOptions("paymentDir=s", \$PAYMENT_DIR, "verbose=i", \$VERBOSE); | ||||
| 
 | ||||
| unless (defined $PAYMENT_DIR and -d $PAYMENT_DIR) { | ||||
|   print STDERR "usage: $0 --paymentDir=<DIRECTORY>   option is required and directory must exist\n"; | ||||
|   exit 1; | ||||
| } | ||||
| $VERBOSE = 0 unless defined $VERBOSE; | ||||
| 
 | ||||
| opendir(my $dh, $PAYMENT_DIR); | ||||
| 
 | ||||
| while (my $file = readdir $dh) { | ||||
|   unless ($file =~ /^\s*(success|faile?d?)-(\S+)\.txt\s*$/i) { | ||||
|     print STDERR "Skipping $file which does not match proper format...\n" if ($VERBOSE >= 2); | ||||
|     next; | ||||
|   } | ||||
|   my($pass, $name) = ($1, $2); | ||||
|   open(my $fh, "<", File::Spec->catfile($PAYMENT_DIR, $file)); | ||||
|   my $date; | ||||
|   while (my $line = <$fh> ) { | ||||
|     if ($line =~ /^\s*Date\s*:\s*(.+)\s*$/) { | ||||
|       $date = UnixDate(ParseDate($1),  "%Y-%m-%d"); | ||||
|       next; | ||||
|     } | ||||
|   } | ||||
|   die "Inside $file there is no valid Date:" if (not defined $date); | ||||
| 
 | ||||
|   my(@nameComponents) = split(/\s*-\s*/, $name); | ||||
|   my(@searchTerms); | ||||
|   foreach my $name (@nameComponents) { | ||||
|     push(@searchTerms, 'Subject LIKE "' . $name . '"'); | ||||
|   } | ||||
|   my $ticket = FindUniqueTicket(@searchTerms); | ||||
|   if (not defined $ticket) { | ||||
|     foreach my $term (@searchTerms) { | ||||
|       $ticket = FindUniqueTicket(($term)); | ||||
|       last if (defined $ticket); | ||||
|     } | ||||
|   } | ||||
| } | ||||
| 
 | ||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Bradley M. Kuhn
						Bradley M. Kuhn