From 62f5c62dd1e36805a9a947b382e16dc767a3cf80 Mon Sep 17 00:00:00 2001 From: Andrew Chilton Date: Sun, 24 Jan 2010 00:47:11 +1300 Subject: [PATCH] cil-d05969b6: Can now read a few things from ~/.cilrc (other settings can be added when needed) --- issues/i_d05969b6.cil | 4 ++-- lib/CIL.pm | 28 ++++++++++------------------ 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/issues/i_d05969b6.cil b/issues/i_d05969b6.cil index e7fdaaf..34186d9 100644 --- a/issues/i_d05969b6.cil +++ b/issues/i_d05969b6.cil @@ -1,10 +1,10 @@ Summary: Make cil read from a ~/.cilrc file for local settings -Status: New +Status: Finished CreatedBy: Andrew Chilton AssignedTo: Andrew Chilton 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 diff --git a/lib/CIL.pm b/lib/CIL.pm index d6360b5..e5065e2 100644 --- a/lib/CIL.pm +++ b/lib/CIL.pm @@ -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; ## ---------------------------------------------------------------------------- -- 2.39.5