summaryrefslogtreecommitdiff
path: root/lib/CIL.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/CIL.pm')
-rw-r--r--lib/CIL.pm67
1 files changed, 60 insertions, 7 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;