summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Chilton <andychilton@gmail.com>2008-07-04 16:17:33 +1200
committerAndrew Chilton <andychilton@gmail.com>2008-07-04 16:17:33 +1200
commitf6649a52ff5610af925818cddd720fa5945bd6b3 (patch)
treeaed0ee63e5d460343749789a1ebe2836bcf00470 /lib
parent03a60521d41962fb3d36e8e8002e9bba51796ff6 (diff)
Imported Upstream version v0.4.2upstream/v0.4.2
Diffstat (limited to 'lib')
-rw-r--r--lib/CIL.pm67
-rw-r--r--lib/CIL/Issue.pm46
2 files changed, 100 insertions, 13 deletions
diff --git a/lib/CIL.pm b/lib/CIL.pm
index e2be890..ee85064 100644
--- a/lib/CIL.pm
+++ b/lib/CIL.pm
@@ -30,6 +30,7 @@ __PACKAGE__->mk_accessors(qw(
IssueDir
StatusStrict StatusAllowed StatusOpen StatusClosed
LabelStrict LabelAllowed
+ UserName UserEmail
));
my $defaults = {
@@ -40,6 +41,11 @@ my $defaults = {
my @config_hashes = qw(StatusAllowed StatusOpen StatusClosed LabelAllowed);
+my $defaults_user = {
+ UserName => 'Name',
+ UserEmail => 'me@example.com',
+};
+
## ----------------------------------------------------------------------------
sub new {
@@ -59,9 +65,11 @@ sub new {
}
sub list_entities {
- my ($self, $prefix) = @_;
+ my ($self, $prefix, $base) = @_;
+
+ $base = '' unless defined $base;
- my $globpath = $self->IssueDir . "/${prefix}_*.cil";
+ my $globpath = $self->IssueDir . "/${prefix}_${base}*.cil";
my @filenames = bsd_glob($globpath);
my @entities;
@@ -93,6 +101,24 @@ sub list_attachments {
return $self->list_entities('a');
}
+sub list_issues_fuzzy {
+ my ($self, $partial_name) = @_;
+
+ return $self->list_entities('i', $partial_name);
+}
+
+sub list_comments_fuzzy {
+ my ($self, $partial_name) = @_;
+
+ return $self->list_entities('c', $partial_name);
+}
+
+sub list_attachments_fuzzy {
+ my ($self, $partial_name) = @_;
+
+ return $self->list_entities('a', $partial_name);
+}
+
sub get_issues {
my ($self) = @_;
@@ -133,7 +159,7 @@ sub get_comments_for {
my ($self, $issue) = @_;
my @comments;
- foreach my $comment_name ( @{$issue->Comments} ) {
+ foreach my $comment_name ( @{$issue->CommentList} ) {
my $comment = CIL::Comment->new_from_name( $self, $comment_name );
push @comments, $comment;
}
@@ -148,7 +174,7 @@ sub get_attachments_for {
my ($self, $issue) = @_;
my @attachments;
- foreach my $attachment_name ( @{$issue->Attachments} ) {
+ foreach my $attachment_name ( @{$issue->AttachmentList} ) {
my $attachment = CIL::Attachment->new_from_name( $self, $attachment_name );
push @attachments, $attachment;
}
@@ -159,10 +185,36 @@ sub get_attachments_for {
return \@attachments;
}
+sub read_config_user {
+ my ($self) = @_;
+
+ my $filename = "$ENV{HOME}/.cilrc";
+
+ my $cfg;
+ if ( -f $filename ) {
+ $cfg = CIL::Utils->parse_cil_file( $filename );
+ }
+
+ # set each config to be either the user defined one or the default
+ foreach ( qw(UserName UserEmail) ) {
+ $self->$_( $cfg->{$_} || $defaults_user->{$_} );
+ }
+}
+
sub read_config_file {
- my ( $self, $filename ) = @_;
+ my ( $self ) = @_;
+
+ my $filename = '.cil';
- my $cfg = CIL::Utils->parse_cil_file( $filename );
+ # since we might not have a '.cil' file yet (in the case where we're calling 'init',
+ # then we should just return whatever the defaults are
+ my $cfg;
+ if ( -f $filename ) {
+ $cfg = CIL::Utils->parse_cil_file( $filename );
+ }
+ else {
+ $cfg = $defaults;
+ }
# set some defaults if we don't have any of these
foreach my $key ( keys %$defaults ) {
@@ -172,7 +224,8 @@ sub read_config_file {
# for some things, make a hash out of them
foreach my $hash_name ( @config_hashes ) {
my $h = {};
- foreach my $thing ( @{$cfg->{"${hash_name}List"}} ) {
+ my @list = ref $cfg->{"${hash_name}List"} eq 'ARRAY' ? @{$cfg->{"${hash_name}List"}} : $cfg->{"${hash_name}List"};
+ foreach my $thing ( @list ) {
$h->{$thing} = 1;
}
$cfg->{$hash_name} = $h;
diff --git a/lib/CIL/Issue.pm b/lib/CIL/Issue.pm
index d44626e..eff317f 100644
--- a/lib/CIL/Issue.pm
+++ b/lib/CIL/Issue.pm
@@ -31,14 +31,16 @@ use CIL::Utils;
use base qw(CIL::Base);
# fields specific to Issue
-__PACKAGE__->mk_accessors(qw(Summary Status AssignedTo Label Comment Attachment Description));
+__PACKAGE__->mk_accessors(qw(Summary Status AssignedTo DependsOn Precedes Label Comment Attachment Description));
-my @FIELDS = ( qw(Summary Status CreatedBy AssignedTo Label Comment Attachment Inserted Updated Description) );
+my @FIELDS = ( qw(Summary Status CreatedBy AssignedTo DependsOn Precedes Label Comment Attachment Inserted Updated Description) );
my $cfg = {
array => {
Label => 1,
Comment => 1,
Attachment => 1,
+ DependsOn => 1,
+ Precedes => 1,
},
};
@@ -65,6 +67,8 @@ sub new {
Label => [],
Comment => [],
Attachment => [],
+ DependsOn => [],
+ Precedes => [],
Description => '',
};
$self->{Changed} = 0;
@@ -109,7 +113,7 @@ sub is_valid {
# see if we only allow certain Labels
if ( $cil->LabelStrict ) {
- my @labels = @{$self->Labels};
+ my @labels = @{$self->LabelList};
foreach my $label ( @labels ) {
unless ( exists $cil->LabelAllowed()->{$label} ) {
push @errors, "LabelStrict is turned on but this issue has an invalid label '$label'";
@@ -155,21 +159,51 @@ sub add_attachment {
$self->flag_as_updated();
}
-sub Labels {
+sub add_depends_on {
+ my ($self, $depends) = @_;
+
+ croak 'provide an issue name when adding a depends'
+ unless defined $depends;
+
+ push @{$self->{data}{DependsOn}}, $depends;
+ $self->flag_as_updated();
+}
+
+sub add_precedes {
+ my ($self, $precedes) = @_;
+
+ croak 'provide an issue name when adding a precedes'
+ unless defined $precedes;
+
+ push @{$self->{data}{Precedes}}, $precedes;
+ $self->flag_as_updated();
+}
+
+sub LabelList {
my ($self) = @_;
return $self->{data}{Label};
}
-sub Comments {
+sub CommentList {
my ($self) = @_;
return $self->{data}{Comment};
}
-sub Attachments {
+sub AttachmentList {
my ($self) = @_;
return $self->{data}{Attachment};
}
+sub DependsOnList {
+ my ($self) = @_;
+ return $self->{data}{DependsOn};
+}
+
+sub PrecedesList {
+ my ($self) = @_;
+ return $self->{data}{Precedes};
+}
+
sub is_open {
my ($self, $cil) = @_;