[Rt-commit] r3072 - in RT-Action-ExtractSubjectTag: . etc lib/RT/Action t

robert at bestpractical.com robert at bestpractical.com
Sat Jun 4 23:50:49 EDT 2005


Author: robert
Date: Sat Jun  4 23:50:49 2005
New Revision: 3072

Added:
   RT-Action-ExtractSubjectTag/lib/RT/Action/ExtractSubjectTag.pm
   RT-Action-ExtractSubjectTag/t/
   RT-Action-ExtractSubjectTag/t/TESTS-TO-WRITE
Removed:
   RT-Action-ExtractSubjectTag/lib/RT/Action/ExtractRTNames.pm
Modified:
   RT-Action-ExtractSubjectTag/   (props changed)
   RT-Action-ExtractSubjectTag/MANIFEST
   RT-Action-ExtractSubjectTag/Makefile.PL
   RT-Action-ExtractSubjectTag/README
   RT-Action-ExtractSubjectTag/etc/initialdata
Log:
 r3092 at bear:  rspier | 2005-06-05T02:08:24.927198Z
 local branch
 
 r3093 at bear:  rspier | 2005-06-05T02:32:43.545323Z
 - rename to ExtractSubjectTag
 - remove default Scrip generation (and document)
 
 r3094 at bear:  rspier | 2005-06-05T02:40:32.244979Z
 - Actually remove the default Scrip creation.
 
 r3095 at bear:  rspier | 2005-06-05T02:51:17.212785Z
 - update ScripAction description strings
 - start to generalize the subject extraction stuff
 
 r3096 at bear:  rspier | 2005-06-05T02:59:31.751405Z
 Update README with information about configuration directives.
 
 r3097 at bear:  rspier | 2005-06-05T03:03:50.851408Z
 Extra parens
 
 r3098 at bear:  rspier | 2005-06-05T03:13:29.606936Z
 tests to write
 
 r3099 at bear:  rspier | 2005-06-05T03:47:18.194243Z
 make it actually work.
 
 r3100 at bear:  rspier | 2005-06-05T03:50:25.226408Z
 README tweaks.
 


Modified: RT-Action-ExtractSubjectTag/MANIFEST
==============================================================================
--- RT-Action-ExtractSubjectTag/MANIFEST	(original)
+++ RT-Action-ExtractSubjectTag/MANIFEST	Sat Jun  4 23:50:49 2005
@@ -9,6 +9,7 @@
 inc/Module/Install/RTx/Factory.pm
 inc/Module/Install/Win32.pm
 inc/Module/Install/WriteAll.pm
-lib/RT/Action/ExtractRTNames.pm
+lib/RT/Action/ExtractSubjectTag.pm
 Makefile.PL
 MANIFEST			This list of files
+README

Modified: RT-Action-ExtractSubjectTag/Makefile.PL
==============================================================================
--- RT-Action-ExtractSubjectTag/Makefile.PL	(original)
+++ RT-Action-ExtractSubjectTag/Makefile.PL	Sat Jun  4 23:50:49 2005
@@ -1,4 +1,4 @@
 use inc::Module::Install;
-RTx('RT-Action-ExtractRTNames');
-version_from('lib/RT/Action/ExtractRTNames.pm');
+RTx('RT-Action-ExtractSubjectTag');
+version_from('lib/RT/Action/ExtractSubjectTag.pm');
 &WriteAll;

Modified: RT-Action-ExtractSubjectTag/README
==============================================================================
--- RT-Action-ExtractSubjectTag/README	(original)
+++ RT-Action-ExtractSubjectTag/README	Sat Jun  4 23:50:49 2005
@@ -1,16 +1,18 @@
 
 SUMMARY ---
 
-RT-Action-ExtractRTNames is an extension for use when you have
-multiple RT systems talking to each other.
+RT-Action-ExtractSubjectTag is an extension for use when you have
+multiple RT systems (or other automated systems) talking to each
+other.  All the systems need to use some sort of subject based tag to
+track things.
 
 RT figures out which ticket a message is associated with by looking
-for a [rtname #1234] tag in the Subject line.  If multiple RT
-instances are sharing a ticket, it needs to contain a tag for each RT
-system.
+for a [rtname #1234] or similar tag in the Subject line.  If multiple
+RT instances are sharing a ticket, it needs to contain a tag for each
+RT system.
 
 This extension looks at incoming messages and modifies the subject of
-the ticket to include any appropriate rtnames from other systems.
+the ticket to include any appropriate rtnames (or other tags) from other systems.
 
 INSTALLATION ---
 
@@ -24,18 +26,37 @@
 $ make
 $ make install
 
-As part of the installation process, your RT instance will be
-configured with a new global scrip which will run the action.
+Before the Scrip will actually work, you must add a new Global Scrip,
+with the following parameters:  (Go to "Configuration.. Global.. Scrips")
 
+  Condition: On Transaction
+  Action: ExtractSubjectTag
+  Template: Blank
+  Stage: TransactionCreate
+  
 CONFIGURATION ---
 
-(not implemented yet)
+ExtractSubjectTag supports two configuration directives.
 
-whitelist (or whiteregexp)
+$ExtractSubjectTagMatch - a regular expression that describes what
+tags shouuld be extracted from the subject line.  
 
-TODO ---
+Defaults to: /\[.+? #\d+\]/ which will match any RT system.
+
+Other examples:
+
+  Set($ExtractSubjectTagMatch, qr/\#\d+/ );
+  Match a # followed by a number.
+
+  Set($ExtractSubjectTagMatch, qr/\[(?:pizza|fred|noodle) #\d+\]/  
+  Match tickets from systems with rtnames pizza, fred, or noodle.
+
+$ExtractSubjectTagNoMatch - a regular expression that describes tags
+that might match $ExtractSubjectTagMatch, but shouldn't be included.
+The rtname of the current system is an example of this.  Defaults to:
+qr/\[(?:${RT::EmailSubjectTagRegex}) #\d+\]/;  You only want to change
+this if you add something to your ExtractSubjectTagMatch that you
+don't want to get added to your subject.
 
-- generalize this to extracting arbitrary subject tags
-- allow that to be configured via a regex
 
 

Modified: RT-Action-ExtractSubjectTag/etc/initialdata
==============================================================================
--- RT-Action-ExtractSubjectTag/etc/initialdata	(original)
+++ RT-Action-ExtractSubjectTag/etc/initialdata	Sat Jun  4 23:50:49 2005
@@ -1,17 +1,8 @@
 # -*- perl -*-
 
 @ScripActions = (
- { Name        => 'ExtractRTNames',
-   Description => 'extract other RT Names from a message and add them to the ticket',
-   ExecModule  => 'ExtractRTNames',
- },
-);
-
-
- at Scrips = (
- { Description => 'On any transaction, make sure any RTnames are transfered to the Ticket Subject',
-   ScripCondition => 'On Transaction',
-   ScripAction => 'ExtractRTNames',
-   Template => 'Blank',
+ { Name        => 'ExtractSubjectTag',
+   Description => 'Extract tags from a Transaction\'s subject and add them to the Ticket\'s subject.',
+   ExecModule  => 'ExtractSubjectTag',
  },
 );

Added: RT-Action-ExtractSubjectTag/lib/RT/Action/ExtractSubjectTag.pm
==============================================================================
--- (empty file)
+++ RT-Action-ExtractSubjectTag/lib/RT/Action/ExtractSubjectTag.pm	Sat Jun  4 23:50:49 2005
@@ -0,0 +1,49 @@
+package RT::Action::ExtractSubjectTag;
+require RT::Action::Generic;
+
+use strict;
+use vars qw/@ISA/;
+ at ISA=qw(RT::Action::Generic);
+
+our $VERSION = "0.01";
+
+our $ExtractSubjectTagMatch = $RT::ExtractSubjectTagMatch || qr/\[.+? #\d+\]/;
+our $ExtractSubjectTagNoMatch = $RT::ExtractSubjectTagNoMatch
+  || ( ${RT::EmailSubjectTagRegex}
+       ? qr/\[(?:${RT::EmailSubjectTagRegex}) #\d+\]/
+       : qr/\[\Q$RT::rtname\E #\d+\]/);
+
+sub Describe  {
+  my $self = shift;
+  return (ref $self);
+}
+
+sub Prepare {
+  return (1);
+}
+
+sub Commit {
+  my $self = shift;
+  my $Transaction = $self->TransactionObj;
+  my $FirstAttachment = $Transaction->Attachments->First;
+  return 1 unless ( $FirstAttachment );
+
+  my $Ticket = $self->TicketObj;
+
+  my $TicketSubject = $self->TicketObj->Subject;
+  my $origTicketSubject = $TicketSubject;
+  my $TransactionSubject = $FirstAttachment->Subject;
+
+  while ( $TransactionSubject =~ /($ExtractSubjectTagMatch)/g ) {
+    my $tag = $1;
+    next if $tag =~ /$ExtractSubjectTagNoMatch/;
+    $TicketSubject .= " $tag" unless ($TicketSubject =~ /\Q$tag\E/);
+  }
+
+  $self->TicketObj->SetSubject( $TicketSubject )
+    if ($TicketSubject ne $origTicketSubject);
+
+  return(1);
+}
+
+1;

Added: RT-Action-ExtractSubjectTag/t/TESTS-TO-WRITE
==============================================================================
--- (empty file)
+++ RT-Action-ExtractSubjectTag/t/TESTS-TO-WRITE	Sat Jun  4 23:50:49 2005
@@ -0,0 +1,5 @@
+- can we extract basic (RT) subject tags?
+- can we extract non RT subject tags?
+- can we extract multiple tags from the same subject line?
+- can we have a complex NoMatch directive?
+- is the ScripAction added properly?


More information about the Rt-commit mailing list