From 118e7bce9ca822f4e3cf4da492f8a98ab9175bd7 Mon Sep 17 00:00:00 2001 From: Andrew Chilton Date: Sat, 28 Jun 2008 01:24:03 +1200 Subject: [PATCH] Add the --created-by and --assigned-to filters. --- bin/cil | 18 ++++++++++++++++-- debian-etch/control | 2 +- debian-lenny/control | 2 +- etc/bash_completion.d/cil | 2 +- issues/c_02a9bb68.cil | 13 +++++++++++++ issues/i_85eceee9.cil | 3 ++- lib/CIL/Issue.pm | 12 ++++++++++++ lib/CIL/Utils.pm | 16 ++++++++++++++++ 8 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 issues/c_02a9bb68.cil diff --git a/bin/cil b/bin/cil index 53d7bf2..4bc39fe 100755 --- a/bin/cil +++ b/bin/cil @@ -48,10 +48,14 @@ my @IN_OPTS = ( 'status>s', # for 'summary', 'list' 'l=s', # l = label 'label>l', # for 'summary, 'list' + 'c=s', # c = created-by + 'created-by>c', # for 'summary', 'list' + 'a=s', # a = assigned_to + 'assigned-to>a',# for 'summary', 'list' # booleans - 'is-open', - 'is-closed', + 'is-open', # for 'summary', 'list' + 'is-closed', # for 'summary', 'list' 'help', 'version', ); @@ -463,6 +467,16 @@ sub filter_issues { @new_issues = grep { $_->is_closed($cil) } @new_issues; } + # filter out 'created by' + if ( defined $args->{c} ) { + @new_issues = grep { $args->{c} eq $_->created_by_email } @new_issues; + } + + # filter out 'assigned to' + if ( defined $args->{a} ) { + @new_issues = grep { $args->{a} eq $_->assigned_to_email } @new_issues; + } + return \@new_issues; } diff --git a/debian-etch/control b/debian-etch/control index ebac134..ded0c34 100644 --- a/debian-etch/control +++ b/debian-etch/control @@ -11,7 +11,7 @@ Package: cil Section: perl Priority: optional Architecture: all -Depends: ${perl:Depends}, libgetopt-mixed-perl, libfile-touch-perl, libfile-slurp-perl, libclass-accessor-perl, libdatetime-perl +Depends: ${perl:Depends}, libgetopt-mixed-perl, libfile-touch-perl, libfile-slurp-perl, libclass-accessor-perl, libdatetime-perl, libemail-find-perl Description: command line issue tracker 'cil' allows easy command-line creation of an issue tracker. It saves each issue locally and in plain text. Commands are given such that these issues can diff --git a/debian-lenny/control b/debian-lenny/control index ebac134..ded0c34 100644 --- a/debian-lenny/control +++ b/debian-lenny/control @@ -11,7 +11,7 @@ Package: cil Section: perl Priority: optional Architecture: all -Depends: ${perl:Depends}, libgetopt-mixed-perl, libfile-touch-perl, libfile-slurp-perl, libclass-accessor-perl, libdatetime-perl +Depends: ${perl:Depends}, libgetopt-mixed-perl, libfile-touch-perl, libfile-slurp-perl, libclass-accessor-perl, libdatetime-perl, libemail-find-perl Description: command line issue tracker 'cil' allows easy command-line creation of an issue tracker. It saves each issue locally and in plain text. Commands are given such that these issues can diff --git a/etc/bash_completion.d/cil b/etc/bash_completion.d/cil index 3ead8a6..3a57087 100644 --- a/etc/bash_completion.d/cil +++ b/etc/bash_completion.d/cil @@ -37,7 +37,7 @@ _cil() local cur prev opts # constants - opts="--help --version --path --status --label --filename --is-open --is-closed" + opts="--help --version --path --status --label --filename --is-open --is-closed --assigned-to --created-by" commands="init add summary list show status edit comment attach extract" COMPREPLY=() diff --git a/issues/c_02a9bb68.cil b/issues/c_02a9bb68.cil new file mode 100644 index 0000000..554d4a3 --- /dev/null +++ b/issues/c_02a9bb68.cil @@ -0,0 +1,13 @@ +Issue: 85eceee9 +CreatedBy: Andrew Chilton +Inserted: 2008-06-27T13:18:47 +Updated: 2008-06-27T13:20:01 + +Added the --created-by and --assigned-to filters. + +These work just on the email address and not the whole field. E.g. + + $ cil list --created-by=andy@example.com + $ cil list --assigned-to=andy@example.org + +The short options for these are -c and -a. diff --git a/issues/i_85eceee9.cil b/issues/i_85eceee9.cil index 8f82740..1ea9c2a 100644 --- a/issues/i_85eceee9.cil +++ b/issues/i_85eceee9.cil @@ -5,10 +5,11 @@ AssignedTo: Andrew Chilton Label: Milestone-v0.3 Label: Release-v0.2.0 Label: Type-Enhancement +Comment: 02a9bb68 Comment: 4b71d0c3 Comment: 7eb313cd Inserted: 2008-06-23T12:05:33 -Updated: 2008-06-27T12:40:51 +Updated: 2008-06-27T13:20:01 The ability to filter on various things would be nice. For example using these list commands, though summary should work the same way: diff --git a/lib/CIL/Issue.pm b/lib/CIL/Issue.pm index 6b0bc0e..904a93b 100644 --- a/lib/CIL/Issue.pm +++ b/lib/CIL/Issue.pm @@ -186,6 +186,18 @@ sub is_closed { return exists $closed->{$self->Status}; } +sub assigned_to_email { + my ($self) = @_; + + return CIL::Utils->extract_email_address( $self->AssignedTo ); +} + +sub created_by_email { + my ($self) = @_; + + return CIL::Utils->extract_email_address( $self->CreatedBy ); +} + ## ---------------------------------------------------------------------------- 1; ## ---------------------------------------------------------------------------- diff --git a/lib/CIL/Utils.pm b/lib/CIL/Utils.pm index fa43d2e..e9611cf 100644 --- a/lib/CIL/Utils.pm +++ b/lib/CIL/Utils.pm @@ -26,6 +26,7 @@ use warnings; use Carp; use File::Slurp; use File::Temp qw(tempfile); +use Email::Find; use POSIX qw(getpgrp tcgetpgrp); use Fcntl qw(:DEFAULT :flock); @@ -182,6 +183,21 @@ sub ensure_interactive { return; } +sub extract_email_address { + my ($class, $text) = @_; + + my $email_address; + my $num_found = find_emails( + $text, + sub { + my ($mail_address, $text_email) = @_; + $email_address = $text_email; + } + ); + + return $email_address; +} + ## ---------------------------------------------------------------------------- 1; ## ---------------------------------------------------------------------------- -- 2.39.5