]> git.mjollnir.org Git - cil.git/commitdiff
Added re-editing of issues/comments and checking against config (#6baa8555).
authorAndrew Chilton <andychilton@gmail.com>
Thu, 26 Jun 2008 12:17:00 +0000 (00:17 +1200)
committerAndrew Chilton <andychilton@gmail.com>
Thu, 26 Jun 2008 12:17:00 +0000 (00:17 +1200)
17 files changed:
.cil
bin/cil
issues/c_4edba98c.cil [new file with mode: 0644]
issues/i_02ee35bd.cil
issues/i_5c88cb30.cil
issues/i_6baa8555.cil
issues/i_85eceee9.cil
issues/i_98203ce8.cil
issues/i_99d9dd74.cil
issues/i_b19d5ada.cil
issues/i_cbb43db9.cil
issues/i_fb79b2e8.cil
lib/CIL.pm
lib/CIL/Base.pm
lib/CIL/Comment.pm
lib/CIL/Issue.pm
lib/CIL/Utils.pm

diff --git a/.cil b/.cil
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..c1fef1fb20e427b2448dd2e5cf59c65af73f1d9c 100644 (file)
--- a/.cil
+++ b/.cil
@@ -0,0 +1,30 @@
+StatusStrict: 1
+StatusAllowedList: New
+StatusAllowedList: InProgress
+StatusAllowedList: Fixed
+StatusAllowedList: OnHold
+StatusAllowedList: Duplicate
+StatusAllowedList: Finished
+StatusOpenList: New
+StatusOpenList: InProgress
+StatusOpenList: Fixed
+StatusClosedList: OnHold
+StatusClosedList: Duplicate
+StatusClosedList: Finished
+LabelStrict: 1
+LabelAllowedList: Release-v0.1.0
+LabelAllowedList: Release-v0.2.0
+LabelAllowedList: Release-v0.2.1
+LabelAllowedList: Type-Enhancement
+LabelAllowedList: Type-Defect
+LabelAllowedList: Type-Task
+LabelAllowedList: Type-Patch
+LabelAllowedList: Type-Other
+LabelAllowedList: Milestone-v0.1
+LabelAllowedList: Milestone-v0.2
+LabelAllowedList: Milestone-v0.3
+LabelAllowedList: Milestone-Future
+LabelAllowedList: Priority-Critical
+LabelAllowedList: Priority-High
+LabelAllowedList: Priority-Medium
+LabelAllowedList: Priority-Low
diff --git a/bin/cil b/bin/cil
index c8f9bacc19c171da6b0bc9c0e288d953e79644e5..eb063856ddf8f789e7559ba5abee67f14481f1ac 100755 (executable)
--- a/bin/cil
+++ b/bin/cil
@@ -34,6 +34,8 @@ use CIL::Attachment;
 ## ----------------------------------------------------------------------------
 # constants
 
+my $y = 'y';
+
 use constant VERSION => '0.2.1';
 
 my @IN_OPTS = (
@@ -58,22 +60,6 @@ my %BOOLEAN_ARGS = (
 my $gan = $ENV{GIT_AUTHOR_NAME} || 'Your Name';
 my $gae = $ENV{GIT_AUTHOR_EMAIL} || 'you@example.org';
 
-my $new_issue_text = <<"EOF";
-Summary     : 
-Status      : New
-CreatedBy   : $gan <$gae>
-AssignedTo  : $gan <$gae>
-Label       : 
-
-Description...
-EOF
-
-my $add_comment_text = <<"EOF";
-CreatedBy   : $gan <$gae>
-
-Description...
-EOF
-
 ## ----------------------------------------------------------------------------
 # main program
 
@@ -102,6 +88,7 @@ EOF
     }
 
     my $cil = CIL->new();
+    $cil->read_config_file( '.cil' );
 
     &{"cmd_$command"}($cil, $args, @ARGV);
 }
@@ -229,11 +216,37 @@ sub cmd_status {
 sub cmd_add {
     my ($cil, undef, $issue_name) = @_;
 
-    # read in the new issue text
     CIL::Utils->ensure_interactive();
-    my $fh = CIL::Utils->solicit( $new_issue_text );
 
-    my $issue = CIL::Issue->new_from_fh( 'tmp', $fh );
+    my $issue = CIL::Issue->new('tmpname');
+    $issue->Status('New');
+    $issue->CreatedBy("$gan <$gae>");
+    $issue->AssignedTo("$gan <$gae>");
+    $issue->Description("Description ...");
+
+    my $edit = $y;
+
+    # keep going until we get a valid issue or we want to quit
+    while ( $edit eq $y ) {
+        # read in the new issue text
+        my $fh = CIL::Utils->solicit( $issue->as_output );
+        $issue = CIL::Issue->new_from_fh( 'tmp', $fh );
+
+        # check if the issue is valid
+        if ( $issue->is_valid($cil) ) {
+            $edit = 'n';
+        }
+        else {
+            print $issue->error(), "\n";
+            print 'Would you like to re-edit (y/n): ';
+            $edit = <STDIN>;
+            chomp $edit;
+            print "\n";
+        }
+    }
+
+    # if the issue is still invalid, they quit without correcting it
+    return unless $issue->is_valid( $cil );
 
     # we've got the issue, so let's name it
     my $unique_str = $issue->Inserted . $issue->Summary . $issue->Description;
@@ -250,20 +263,35 @@ sub cmd_edit {
         fatal("Couldn't load issue '$issue_name'");
     }
 
-    # create the ini file, then edit it
-    my $edit_issue_text = $issue->as_output;
-
-    # read in the new issue text
     CIL::Utils->ensure_interactive();
-    my $fh = CIL::Utils->solicit( join('', @$edit_issue_text) );
 
-    my $issue_edited = CIL::Issue->new_from_fh( $issue->name, $fh );
-    unless ( defined $issue_edited ) {
-        fatal("couldn't create issue (program error)");
+    my $edit = $y;
+
+    # keep going until we get a valid issue or we want to quit
+    while ( $edit eq $y ) {
+        # read in the new issue text
+        my $fh = CIL::Utils->solicit( $issue->as_output );
+        $issue = CIL::Issue->new_from_fh( $issue->name, $fh );
+
+        # check if the issue is valid
+        if ( $issue->is_valid($cil) ) {
+            $edit = 'n';
+        }
+        else {
+            print $issue->error(), "\n";
+            print 'Would you like to re-edit (y/n): ';
+            $edit = <STDIN>;
+            chomp $edit;
+            print "\n";
+        }
     }
 
-    $issue_edited->save($cil);
-    display_issue($cil, $issue_edited);
+    # if the issue is still invalid, they quit without correcting it
+    return unless $issue->is_valid( $cil );
+
+    # save it
+    $issue->save($cil);
+    display_issue($cil, $issue);
 }
 
 sub cmd_comment {
@@ -274,21 +302,43 @@ sub cmd_comment {
         fatal("couldn't load issue '$issue_name'");
     }
 
-    # read in the new issue text
     CIL::Utils->ensure_interactive();
-    my $fh = CIL::Utils->solicit( $add_comment_text );
 
-    my $comment = CIL::Comment->new_from_fh( 'tmp', $fh );
-    unless ( defined $comment ) {
-        fatal("could not create new comment");
+    # create the new comment
+    my $comment = CIL::Comment->new('tmpname');
+    $comment->Issue( $issue->name );
+    $comment->CreatedBy("$gan <$gae>");
+    $comment->Description("Description ...");
+
+    my $edit = $y;
+
+    # keep going until we get a valid issue or we want to quit
+    while ( $edit eq $y ) {
+        # read in the new comment text
+        my $fh = CIL::Utils->solicit( $comment->as_output );
+        $comment = CIL::Comment->new_from_fh( 'tmp', $fh );
+
+        # check if the comment is valid
+        if ( $comment->is_valid($cil) ) {
+            $edit = 'n';
+        }
+        else {
+            print $comment->error(), "\n";
+            print 'Would you like to re-edit (y/n): ';
+            $edit = <STDIN>;
+            chomp $edit;
+            print "\n";
+        }
     }
 
+    # if the comment is still invalid, they quit without correcting it
+    return unless $comment->is_valid( $cil );
+
     # we've got the comment, so let's name it
     my $unique_str = $comment->Inserted . $issue->Description;
     $comment->set_name( substr(md5_hex($unique_str), 0, 8) );
 
-    # finally, tell it who it's parent is and then save
-    $comment->Issue( $issue->name );
+    # finally, save it
     $comment->save($cil);
 
     # add the comment to the issue, update it's timestamp and save it out
@@ -368,8 +418,8 @@ sub check_paths {
     my ($cil) = @_;
 
     # make sure an issue directory is available
-    unless ( -d $cil->issue_dir ) {
-        fatal("couldn't find '" . $cil->issue_dir . "' directory");
+    unless ( -d $cil->IssueDir ) {
+        fatal("couldn't find '" . $cil->IssueDir . "' directory");
     }
 }
 
diff --git a/issues/c_4edba98c.cil b/issues/c_4edba98c.cil
new file mode 100644 (file)
index 0000000..c58c7ed
--- /dev/null
@@ -0,0 +1,16 @@
+Issue: 6baa8555
+CreatedBy: Andrew Chilton <andychilton@gmail.com>
+Inserted: 2008-06-26T12:11:09
+Updated: 2008-06-26T12:12:41
+
+Added the following options:
+
+* StatusStrict
+* StatusAllowedList
+* StatusOpenList
+* StatusClosedList
+
+* LabelStrict
+* LabelAllowedList
+
+The lists are only checked if the strict variables are on.
index 21546ec49f8ae3ddc0c9eb1752d59b8f02127d45..85596e3641b3b69e8a81dc7756d40eed68d70d71 100644 (file)
@@ -2,11 +2,11 @@ Summary: Labels should be allowed to have a 'required' set
 Status: New
 CreatedBy: Andrew Chilton <andychilton@gmail.com>
 AssignedTo: Andrew Chilton <andychilton@gmail.com>
-Label: Release-v0.1
 Label: Priority-Medium
+Label: Release-v0.1.0
 Label: Type-Enhancement
 Inserted: 2008-05-05T12:53:38
-Updated: 2008-06-21T10:50:05
+Updated: 2008-06-26T11:53:27
 
 In the .cil config file, there should a field which determines a
 'required' set of labels.
index b9707c296752a29cabc8420099ea84005ccf1179..a5b26708fc3850a8754552088e80609eeecee978 100644 (file)
@@ -1,15 +1,15 @@
 Summary: Options for issues names needs to be added
-Status: WontFix
+Status: OnHold
 CreatedBy: Andrew Chilton <andychilton@gmail.com>
 AssignedTo: Andrew Chilton <andychilton@gmail.com>
 Label: Milestone-v0.2
 Label: Priority-Low
-Label: Release-v0.1
+Label: Release-v0.1.0
 Label: Type-Enhancement
 Comment: d8dd779f
 Comment: feb65ae7
 Inserted: 2008-05-05T12:33:19
-Updated: 2008-06-23T12:36:04
+Updated: 2008-06-26T12:10:32
 
 When issues are created, they are given the epoch as it's name.
 Instead of just using the epoch, the user should be able to configure
index 5352e9327ead858658570a0809b421a36483cbd6..701e18eedc7f6823180eee4d3070d0ab780b31d5 100644 (file)
@@ -1,12 +1,13 @@
 Summary: Do checking on input fields after adding or editing issue
-Status: New
+Status: InProgress
 CreatedBy: Andrew Chilton <andychilton@gmail.com>
 AssignedTo: Andrew Chilton <andychilton@gmail.com>
 Label: Priority-Medium
-Label: Release-v0.1
+Label: Release-v0.1.0
 Label: Type-Enhancement
+Comment: 4edba98c
 Inserted: 2008-05-05T12:46:58
-Updated: 2008-06-21T10:59:52
+Updated: 2008-06-26T12:12:41
 
 For example, if there is a config item in .cil called
 'allowed_statuses', all input values in the 'Status' field should be
index 22b72126d79db9f2b7a40904392fca7d9b2aff6a..6c9d53af0485f54d319c1396e9c3ace172cd551b 100644 (file)
@@ -3,11 +3,11 @@ Status: InProgress
 CreatedBy: Andrew Chilton <andychilton@gmail.com>
 AssignedTo: Andrew Chilton <andychilton@gmail.com>
 Label: Milestone-v0.3
-Label: Release-v0.2
+Label: Release-v0.2.0
 Label: Type-Enhancement
 Comment: 7eb313cd
 Inserted: 2008-06-23T12:05:33
-Updated: 2008-06-23T12:08:05
+Updated: 2008-06-26T11:54:29
 
 The ability to filter on various things would be nice. For example using these
 list commands, though summary should work the same way:
index 5e34f51b94312c15ec362087b09946446b5bc223..f913c1fa4aa7c60c2c8cb0fae0fa9929c48bbb5c 100644 (file)
@@ -6,7 +6,7 @@ Label: Milestone-Future
 Label: Release-v0.2.1
 Label: Type-Enhancement
 Inserted: 2008-06-23T12:20:45
-Updated: 2008-06-23T12:20:45
+Updated: 2008-06-26T11:54:39
 
 Some sort of indexing and search should be added to cil so that it is easier to
 find issues in amongst a long list of them.
index c793311d8886e8c9481179f5d356ca33ca832932..b1ece8e8d9363207302881693273bf65af7697cd 100644 (file)
@@ -2,11 +2,11 @@ Summary: Add a filter '--grep=regex'
 Status: New
 CreatedBy: Andrew Chilton <andychilton@gmail.com>
 AssignedTo: Andrew Chilton <andychilton@gmail.com>
-Label: Milestone-v0.3.0
+Label: Milestone-v0.3
 Label: Release-v0.2.1
 Label: Type-Enhancement
 Inserted: 2008-06-24T12:16:57
-Updated: 2008-06-24T12:16:57
+Updated: 2008-06-26T11:54:57
 
 Having a 'grep' filter would be quite powerful. It could be used in the 'list'
 and 'summary' commands. It would be good if it accepts Perl regexes and might
index 22de0b0ff4faa08289c76cb60b7206034892868b..b1bf2ea8452cd324872fb3d8287f363f349b140e 100644 (file)
@@ -2,11 +2,11 @@ Summary: Add a 'cil check-in-git' command
 Status: New
 CreatedBy: Andrew Chilton <andychilton@gmail.com>
 AssignedTo: Andrew Chilton <andychilton@gmail.com>
-Label: Mileston-v0.3.0
+Label: Milestone-v0.3
 Label: Release-v0.2.1
 Label: Type-Enhancement
 Inserted: 2008-06-24T03:24:14
-Updated: 2008-06-24T03:24:14
+Updated: 2008-06-26T11:55:28
 
 The ability to check whether issues/comments/attachments are tracked by Git is
 important. Or indeed any VCS system.
index 34901997f45aebfbc2d108a7a85caa7abebb9621..61123ef83902a2de1e99fa703da2f114e68cf06f 100644 (file)
@@ -3,11 +3,11 @@ Status: Finished
 CreatedBy: Andrew Chilton <andychilton@gmail.com>
 AssignedTo: Andrew Chilton <andychilton@gmail.com>
 Label: Priority-Medium
-Label: Release-v0.1
+Label: Release-v0.1.0
 Label: Type-Enhancement
 Comment: 2b92ef13
 Inserted: 2008-05-05T12:20:28
-Updated: 2008-06-22T03:54:13
+Updated: 2008-06-26T11:55:42
 
 'cil' currently has no way of adding attachments to issues.
 
index b218517cd36ef43ab2faca5055b3c54f66e275a1..e865d07c050ae602687563cae7d03a6850c07ea3 100644 (file)
@@ -2,12 +2,12 @@ Summary: Ability to set Issue Status' from the command line
 Status: Finished
 CreatedBy: Andrew Chilton <andychilton@gmail.com>
 AssignedTo: Andrew Chilton <andychilton@gmail.com>
-Label: Mileston-v0.2
-Label: Release-v0.1
+Label: Milestone-v0.2
+Label: Release-v0.1.0
 Label: Type-Enhancement
 Comment: 792a4acf
 Inserted: 2008-06-22T04:00:20
-Updated: 2008-06-22T04:02:46
+Updated: 2008-06-26T11:56:03
 
 The ability to do something like the following would be good.
 
index b85f2fb506f051eea77fd8e21865893a86ee78d6..2a4f9d5822056738b05787165008a3d0fd6a3757 100644 (file)
@@ -26,12 +26,20 @@ use warnings;
 use File::Glob qw(:glob);
 
 use base qw(Class::Accessor);
-__PACKAGE__->mk_accessors(qw(issue_dir));
+__PACKAGE__->mk_accessors(qw(
+    IssueDir
+    StatusStrict StatusAllowed StatusOpen StatusClosed
+    LabelStrict LabelAllowed
+));
 
 my $defaults = {
-    issue_dir => 'issues',
+    IssueDir     => 'issues', # the dir to save the issues in
+    StatusStrict => 0,        # whether to complain if a status is invalid
+    LabelStrict  => 0,        # whether to complain if a label is invalid
 };
 
+my @config_hashes = qw(StatusAllowed StatusOpen StatusClosed LabelAllowed);
+
 ## ----------------------------------------------------------------------------
 
 sub new {
@@ -53,7 +61,7 @@ sub new {
 sub list_issues {
     my ($self) = @_;
 
-    my $globpath = $self->issue_dir . "/i_*.cil";
+    my $globpath = $self->IssueDir . "/i_*.cil";
     my @filenames = bsd_glob($globpath);
 
     my @issues;
@@ -109,6 +117,38 @@ sub get_attachments_for {
     return \@attachments;
 }
 
+sub read_config_file {
+    my ( $self, $filename ) = @_;
+
+    my $cfg = CIL::Utils->parse_cil_file( $filename );
+
+    # set some defaults if we don't have any of these
+    foreach my $key ( keys %$defaults ) {
+        $cfg->{$key} ||= $defaults->{$key};
+    }
+
+    # for some things, make a hash out of them
+    foreach my $hash_name ( @config_hashes ) {
+        my $h = {};
+        foreach my $thing ( @{$cfg->{"${hash_name}List"}} ) {
+            $h->{$thing} = 1;
+        }
+        $cfg->{$hash_name} = $h;
+        undef $cfg->{"${hash_name}List"};
+    }
+
+    # set each config item
+    $self->IssueDir( $cfg->{IssueDir} );
+
+    $self->StatusStrict( $cfg->{StatusStrict} );
+    $self->StatusAllowed( $cfg->{StatusAllowed} );
+    $self->StatusOpen( $cfg->{StatusOpen} );
+    $self->StatusClosed( $cfg->{StatusClosed} );
+
+    $self->LabelStrict( $cfg->{LabelStrict} );
+    $self->LabelAllowed( $cfg->{LabelAllowed} );
+}
+
 ## ----------------------------------------------------------------------------
 1;
 ## ----------------------------------------------------------------------------
index feb7dfc0ec9b01cdb2a17e19af389d2ca57b10e2..681a544ed028faa1fd504b009ddd6d716c00f6c5 100644 (file)
@@ -25,6 +25,7 @@ use strict;
 use warnings;
 use Carp;
 use DateTime;
+use CIL::Utils;
 
 use base qw(Class::Accessor);
 __PACKAGE__->mk_accessors(qw(CreatedBy Inserted Updated));
@@ -87,6 +88,30 @@ sub new_from_fh {
     return $class->new_from_data( $name, $data );
 }
 
+sub set_data {
+    my ($self, $data) = @_;
+
+    # loop through all the allowed fields
+    my $fields = $self->fields();
+    my $array_fields = $self->array_fields();
+
+    # save each field
+    foreach my $field ( @$fields ) {
+        next unless defined $data->{$field};
+
+        # make it an array if it should be one
+        if ( exists $array_fields->{$field} and ref $data->{$field} ne 'ARRAY' ) {
+            $data->{$field} = [ $data->{$field} ];
+        }
+
+        # modify the data directly, otherwise Updated will kick in
+        $self->set_no_update($field, $data->{$field});
+    }
+    $self->set_no_update('Changed', 1);
+
+    $self->{data} = $data;
+}
+
 sub save {
     my ($self, $cil) = @_;
 
@@ -96,12 +121,18 @@ sub save {
     CIL::Utils->write_cil_file( $filename, $self->{data}, @$fields );
 }
 
+sub as_output {
+    my ($self) = @_;
+    my $fields = $self->fields();
+    return CIL::Utils->format_data_as_output( $self->{data}, @$fields );
+}
+
 sub create_filename {
     my ($class, $cil, $name) = @_;
 
     # create the filename from it's parts
     my $prefix    = $class->prefix();
-    my $issue_dir = $cil->issue_dir;
+    my $issue_dir = $cil->IssueDir;
     my $filename  = "${issue_dir}/${prefix}_${name}.cil";
 
     return $filename;
@@ -184,6 +215,14 @@ sub name {
     return $self->{name};
 }
 
+sub error {
+    my $self = shift;
+    if( @_ ) {
+        $self->{error} = $_[0];
+    }
+    return $self->{error};
+}
+
 ## ----------------------------------------------------------------------------
 1;
 ## ----------------------------------------------------------------------------
index 9d0398c3d00cdf3a8dc08f89310ec0894a50e13b..362f0940038a8aa8df742965e844291773a1bee2 100644 (file)
@@ -75,6 +75,14 @@ sub last_field {
     return 'Description';
 }
 
+sub is_valid {
+    # ToDo:
+    # * check that the issue is valid
+    # * Inserted and Updated are valid
+    # * Description has something in it
+    return 1;
+}
+
 ## ----------------------------------------------------------------------------
 1;
 ## ----------------------------------------------------------------------------
index 13f34355719671e6a176988c8c93c09f5d1ef0cb..6683860fbf628ac769c053b9ca86413b91b9762c 100644 (file)
@@ -90,6 +90,37 @@ sub last_field {
     return 'Description';
 }
 
+sub is_valid {
+    my ($self, $cil) = @_;
+
+    # issues should have a Summary
+    unless ( defined defined $self->Summary and length $self->Summary ) {
+        $self->error( 'You must provide a summary.' );
+        return;
+    }
+
+    # see if we only allow certain Statuses
+    if ( $cil->StatusStrict ) {
+        unless ( exists $cil->StatusAllowed()->{$self->Status} ) {
+            $self->error( "You have 'StatusStrict' turned on but this status (" . $self->Status . ") is not in the 'StatusAllowedList'" );
+            return;
+        }
+    }
+
+    # see if we only allow certain Labels
+    if ( $cil->LabelStrict ) {
+        my @labels = @{$self->Labels};
+        foreach my $label ( @labels ) {
+            unless ( exists $cil->LabelAllowed()->{$label} ) {
+                $self->error( "You have 'LabelStrict' turned on but this label ($label) is not in the 'LabelAllowedList'" );
+                return;
+            }
+        }
+    }
+
+    return 1;
+}
+
 sub add_label {
     my ($self, $label) = @_;
 
@@ -124,11 +155,6 @@ sub add_attachment {
     $self->flag_as_updated();
 }
 
-sub as_output {
-    my ($self) = @_;
-    return CIL::Utils->format_data_as_output( $self->{data}, @FIELDS );
-}
-
 sub Labels {
     my ($self) = @_;
     return $self->{data}{Label};
index a0e165ccf598311c341fdbdd71a903370e34105d..fa43d2e8c14e8cb03acc298457cbbcc6cc25a025 100644 (file)
@@ -76,8 +76,9 @@ sub parse_from_lines {
         }
     }
     
-    # now read everything that's left into the $last_field field
-    $data->{$last_field} = join("\n", @lines);
+    # now read everything that's left into the $last_field field (if there is one)
+    $data->{$last_field} = join("\n", @lines)
+        if defined $last_field;
 
     return $data;
 }
@@ -128,6 +129,8 @@ sub write_cil_file {
 sub solicit {
     my ($class, $message) = @_;
 
+    $message = join('', @$message) if ref $message eq 'ARRAY';
+
     # when calling this, assume we're already interactive
 
     File::Temp->safe_level(File::Temp::HIGH);