]> git.mjollnir.org Git - cil.git/commitdiff
cil-d05969b6: Can now read a few things from ~/.cilrc (other settings can be added...
authorAndrew Chilton <andychilton@gmail.com>
Sat, 23 Jan 2010 11:47:11 +0000 (00:47 +1300)
committerAndrew Chilton <andychilton@gmail.com>
Sat, 23 Jan 2010 11:47:11 +0000 (00:47 +1300)
issues/i_d05969b6.cil
lib/CIL.pm

index e7fdaaf3b9b2af6519aa1e30411f224b0c10c99e..34186d91d355644fe5417ff3a3a6759221d802b7 100644 (file)
@@ -1,10 +1,10 @@
 Summary: Make cil read from a ~/.cilrc file for local settings
-Status: New
+Status: Finished
 CreatedBy: Andrew Chilton <andychilton@gmail.com>
 AssignedTo: Andrew Chilton <andychilton@gmail.com>
 Label: Milestone-v0.06
 Inserted: 2010-01-23T11:22:40
-Updated: 2010-01-23T11:24:57
+Updated: 2010-01-23T11:46:20
 
 To do things like auto-assigning to yourself, and to override CreatedBy fields,
 cil should read from a ~/.cilrc file, rather than trying to figure it out from
index d6360b538cf2d7e6bfc302dae1b008f753fd7aef..e5065e296e9dedefbcb6d87df4cd5c69b47ad7a5 100644 (file)
@@ -25,11 +25,13 @@ use strict;
 use warnings;
 use Carp qw(croak confess);
 use File::Glob qw(:glob);
+use File::HomeDir;
+use Git;
 
 use vars qw( $VERSION );
 $VERSION = '0.5.1';
 
-use Module::Pluggable 
+use Module::Pluggable
         sub_name    => 'commands',
         search_path => [ 'CIL::Command' ],
         require     => 1;
@@ -43,6 +45,8 @@ __PACKAGE__->mk_accessors(qw(
     LabelStrict LabelAllowed
     DefaultNewStatus
     VCS
+    UserName UserEmail
+    AutoAssignSelf
     vcs hook
     vcs_revision
 ));
@@ -58,8 +62,9 @@ my $defaults = {
 my @config_hashes = qw(StatusAllowed StatusOpen StatusClosed LabelAllowed);
 
 my $defaults_user = {
-    UserName  => 'Name',
-    UserEmail => 'me@example.com',
+    UserName       => eval { Git->repository->config( 'user.name' ) } || 'UserName',
+    UserEmail      => eval { Git->repository->config( 'user.email' ) } || 'username@example.org',
+    AutoAssignSelf => 0,
 };
 
 my $allowed = {
@@ -227,7 +232,7 @@ sub get_attachments_for {
 sub read_config_user {
     my ($self) = @_;
 
-    my $filename = "$ENV{HOME}/.cilrc";
+    my $filename = File::HomeDir->my_home() . '/.cilrc';
 
     my $cfg;
     if ( -f $filename ) {
@@ -235,7 +240,7 @@ sub read_config_user {
     }
 
     # set each config to be either the user defined one or the default
-    foreach ( qw() ) { # nothing yet
+    foreach ( qw(UserName UserEmail AutoAssignSelf) ) {
         $self->$_( $cfg->{$_} || $defaults_user->{$_} );
     }
 }
@@ -376,19 +381,6 @@ sub save {
     }
 }
 
-## ----------------------------------------------------------------------------
-# simple delegates to elsewhere
-
-sub UserName {
-    my ($self) = @_;
-    return $self->vcs->UserName
-}
-
-sub UserEmail {
-    my ($self) = @_;
-    return $self->vcs->UserEmail
-}
-
 ## ----------------------------------------------------------------------------
 1;
 ## ----------------------------------------------------------------------------