+0.6.0 (Unreleased)
+
+ * New hook infrastructure, currently only 'issue_post_save' is allowed
+
0.5.1 (2008-07-05)
* New release minus all the cruft
$cil->read_config_user();
$cil->read_config_file();
+ # add any hooks we want
+ # none yet
+
&{"cmd_$command"}($cil, $args, @ARGV);
}
my $unique_str = time . $issue->Inserted . $issue->Summary . $issue->Description;
$issue->set_name( substr(md5_hex($unique_str), 0, 8) );
$issue->save($cil);
+
+ # should probably be run from with $cil
+ $cil->run_hook('issue_post_save', $issue);
+
display_issue($cil, $issue);
return $issue;
}
}
+## ----------------------------------------------------------------------------
+# hooks
+
+# none yet
+
## ----------------------------------------------------------------------------
# input/output
--- /dev/null
+Issue: 41b351fc
+CreatedBy: Andrew Chilton <andychilton@gmail.com>
+Inserted: 2008-07-13T10:29:22
+Updated: 2008-07-13T10:30:58
+
+Added the initial go at the hook system. It seems to work but until we actually
+do some, it'll just be a framework for the time being.
Summary: Add some sort of hook system
-Status: New
+Status: Finished
CreatedBy: Andrew Chilton <andychilton@gmail.com>
AssignedTo: Andrew Chilton <andychilton@gmail.com>
Label: Milestone-v0.5
Label: Type-Enhancement
+Comment: 7b75b82c
Inserted: 2008-07-13T05:08:27
-Updated: 2008-07-13T10:28:36
+Updated: 2008-07-13T10:34:43
-For example, when you add an issue, you might want to do the followin things:
+For example, when you add an issue, you might want to do the following things:
* reindex all the issues (for faster search - #98203ce8)
* generate an issues/index.html file (for poor man's cilweb - #0e004cde)
use strict;
use warnings;
+use Carp;
use File::Glob qw(:glob);
+use CIL::VCS::Factory;
+
use base qw(Class::Accessor);
__PACKAGE__->mk_accessors(qw(
IssueDir
LabelStrict LabelAllowed
VCS
UserName UserEmail
+ vcs hook
));
my $defaults = {
UserEmail => 'me@example.com',
};
+my $allowed = {
+ vcs => {
+ 'Git' => 1,
+ },
+ hook => {
+ 'issue_post_save' => 1,
+ },
+};
+
## ----------------------------------------------------------------------------
sub new {
$self->LabelStrict( $cfg->{LabelStrict} );
$self->LabelAllowed( $cfg->{LabelAllowed} );
- $self->VCS( $cfg->{VCS} );
+ # if we are allowed this VCS, create the hook instance
+ if ( exists $allowed->{vcs}{$cfg->{VCS}} ) {
+ $self->VCS( $cfg->{VCS} );
+ my $vcs = CIL::VCS::Factory->new( $cfg->{VCS} );
+ $self->vcs( $vcs );
+ }
+}
+
+sub register_hook {
+ my ($self, $hook_name, $code) = @_;
+
+ unless ( defined $allowed->{hook}{$hook_name} ) {
+ croak "hook '$hook_name' not allowed";
+ }
+
+ push @{$self->{hook}{$hook_name}}, $code;
+}
+
+sub run_hook {
+ my ($self, $hook_name, @rest) = @_;
+
+ print "s=$self, hn=$hook_name, r=@rest\n";
+
+ unless ( defined $allowed->{hook}{$hook_name} ) {
+ croak "hook '$hook_name' not allowed";
+ }
+
+ # call all the hooks with all the args
+ foreach my $code ( @{$self->hook->{$hook_name}} ) {
+ &$code( $self, @rest );
+ }
}
## ----------------------------------------------------------------------------
--- /dev/null
+## ----------------------------------------------------------------------------
+# cil is a Command line Issue List
+# Copyright (C) 2008 Andrew Chilton
+#
+# This file is part of 'cil'.
+#
+# cil is free software: you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <http://www.gnu.org/licenses/>.
+#
+## ----------------------------------------------------------------------------
+
+package CIL::VCS::Factory;
+
+use strict;
+use warnings;
+use Carp;
+
+use base qw( Class::Factory );
+
+__PACKAGE__->register_factory_type( Git => 'CIL::VCS::Git' );
+
+foreach my $method_name ( qw(post_add) ) {
+ my $method = sub {
+ my ($self) = @_;
+ my $class = ref $self || $self;
+ die "Method '$method_name' not overriden in derived class '$class'";
+ };
+
+ no strict 'refs';
+ *{$method_name} = $method;
+}
+
+## ----------------------------------------------------------------------------
+1;
+## ----------------------------------------------------------------------------
--- /dev/null
+## ----------------------------------------------------------------------------
+# cil is a Command line Issue List
+# Copyright (C) 2008 Andrew Chilton
+#
+# This file is part of 'cil'.
+#
+# cil is free software: you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <http://www.gnu.org/licenses/>.
+#
+## ----------------------------------------------------------------------------
+
+package CIL::VCS::Git;
+
+use strict;
+use warnings;
+use Carp;
+
+use base qw(CIL::VCS::Factory);
+
+sub post_add {
+ my ($self, $issue) = @_;
+
+ my $issue_dir = $issue->cil->IssueDir();
+ my @files;
+ push @files, "$issue_dir/i_" . $issue->name . '.cil';
+ push @files, map { "$issue_dir/c_${_}.cil" } @{ $issue->CommentList };
+ push @files, map { "$issue_dir/a_${_}.cil" } @{ $issue->AttachmentList };
+
+ return [ "git add @files" ];
+}
+
+## ----------------------------------------------------------------------------
+1;
+## ----------------------------------------------------------------------------
--- /dev/null
+## ----------------------------------------------------------------------------
+# cil is a Command line Issue List
+# Copyright (C) 2008 Andrew Chilton
+#
+# This file is part of 'cil'.
+#
+# cil is free software: you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <http://www.gnu.org/licenses/>.
+#
+## ----------------------------------------------------------------------------
+
+package CIL::VCS::Null;
+
+use strict;
+use warnings;
+use Carp;
+
+foreach my $method_name ( qw(post_add) ) {
+ no strict 'refs';
+ *{"${class}::$method_name"} = sub {};
+}
+
+## ----------------------------------------------------------------------------
+1;
+## ----------------------------------------------------------------------------