Andrew Bogott has submitted this change and it was merged.

Change subject: gitconfig::user to easily craft .gitconfig user files
......................................................................


gitconfig::user to easily craft .gitconfig user files

The new module git contains a single define 'gitconfig::user' which let
one craft a .gitconfig file using a hash defining its content.  Simple
example is provided in the class documentation and a very basic rspec
test is provided to check whether the expansion happens properly.

Example usage:

  gitconfig::user { 'gitconf for jenkins user':
    homedir => '/var/lib/jenkins',
    settings => {
      'user' => {  # '[user]'
         'name'  => 'Antoine Musso',  # 'name = Antoine Musso'
         'email' => '[email protected]', # 'email = [email protected]'
      },  # end of [user] section
    }
  }

Change-Id: I49a03405fbe715269e396f6f1e0c956ba10a5f0a
---
A modules/gitconfig/Rakefile
A modules/gitconfig/manifests/user.pp
A modules/gitconfig/spec/defines/user_spec.rb
A modules/gitconfig/spec/fixtures/modules/git/manifests
A modules/gitconfig/spec/fixtures/modules/git/templates
A modules/gitconfig/spec/fixtures/modules/gitconfig/manifests
A modules/gitconfig/spec/fixtures/modules/gitconfig/templates
A modules/gitconfig/spec/spec_helper.rb
A modules/gitconfig/templates/gitconfig.erb
9 files changed, 89 insertions(+), 0 deletions(-)

Approvals:
  Andrew Bogott: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/gitconfig/Rakefile b/modules/gitconfig/Rakefile
new file mode 100644
index 0000000..cd3d379
--- /dev/null
+++ b/modules/gitconfig/Rakefile
@@ -0,0 +1 @@
+require 'puppetlabs_spec_helper/rake_tasks'
diff --git a/modules/gitconfig/manifests/user.pp 
b/modules/gitconfig/manifests/user.pp
new file mode 100644
index 0000000..51ea2bf
--- /dev/null
+++ b/modules/gitconfig/manifests/user.pp
@@ -0,0 +1,33 @@
+# == gitconfig::user
+#
+# Generate a .gitconfig in $homedir based on a hash of gitconfig values.
+# The file will be owned by root since it is fully managed by puppet.
+#
+# Parameters:
+#  [*homedir*] - user home dir where .gitconfig will be written
+#  [*settings*] - hash of gitconfig section name, each should be in turn a hash
+#  of configuration name => value.
+#
+# Example usage:
+#
+# gitconfig::user{ 'gitconf for jenkins user':
+#   homedir => '/var/lib/jenkins',
+#   settings => {
+#     'user' => {  # '[user]'
+#        'name'  => 'Antoine Musso',  # 'name = Antoine Musso'
+#        'email' => '[email protected]', # 'email = [email protected]'
+#     },  # end of [user] section
+#   }
+# }
+#
+define gitconfig::user($homedir, $settings) {
+
+  file { "${homedir}/.gitconfig":
+    ensure  => present,
+    owner   => 'root',
+    group   => 'root',
+    mode    => '0444',
+    content => template( 'gitconfig/gitconfig.erb' )
+  }
+
+}
diff --git a/modules/gitconfig/spec/defines/user_spec.rb 
b/modules/gitconfig/spec/defines/user_spec.rb
new file mode 100644
index 0000000..dec88ab
--- /dev/null
+++ b/modules/gitconfig/spec/defines/user_spec.rb
@@ -0,0 +1,30 @@
+# Lame test for git::userconfig, making sure the expanded gitconfig.erb expands
+# to a somehow valid .gitconfig file
+#
+# Copyright 2013 Antoine "hashar" Musso
+# Copyright 2013 Wikimedia Foundation Inc.
+
+require 'spec_helper'
+
+describe 'gitconfig::user', :type => :define do
+
+       let(:title) { 'gitconfig' }
+
+       context "Setting up user name and email" do
+               let(:params) { {
+                       :homedir => '/tmp/foo',
+                       :settings => {
+                       'user' => {
+                               'name' => 'Antoine Musso',
+                               'email' => '[email protected]',
+                       }
+               } }
+               }
+               it { should contain_file('/tmp/foo/.gitconfig') \
+                       .with_content(/[user]\n/) \
+                       .with_content(/name = Antoine Musso\n/) \
+                       .with_content(/email = [email protected]\n/)
+               }
+       end
+
+end
diff --git a/modules/gitconfig/spec/fixtures/modules/git/manifests 
b/modules/gitconfig/spec/fixtures/modules/git/manifests
new file mode 120000
index 0000000..373b992
--- /dev/null
+++ b/modules/gitconfig/spec/fixtures/modules/git/manifests
@@ -0,0 +1 @@
+../../../../manifests
\ No newline at end of file
diff --git a/modules/gitconfig/spec/fixtures/modules/git/templates 
b/modules/gitconfig/spec/fixtures/modules/git/templates
new file mode 120000
index 0000000..f8a06d1
--- /dev/null
+++ b/modules/gitconfig/spec/fixtures/modules/git/templates
@@ -0,0 +1 @@
+../../../../templates
\ No newline at end of file
diff --git a/modules/gitconfig/spec/fixtures/modules/gitconfig/manifests 
b/modules/gitconfig/spec/fixtures/modules/gitconfig/manifests
new file mode 120000
index 0000000..373b992
--- /dev/null
+++ b/modules/gitconfig/spec/fixtures/modules/gitconfig/manifests
@@ -0,0 +1 @@
+../../../../manifests
\ No newline at end of file
diff --git a/modules/gitconfig/spec/fixtures/modules/gitconfig/templates 
b/modules/gitconfig/spec/fixtures/modules/gitconfig/templates
new file mode 120000
index 0000000..f8a06d1
--- /dev/null
+++ b/modules/gitconfig/spec/fixtures/modules/gitconfig/templates
@@ -0,0 +1 @@
+../../../../templates
\ No newline at end of file
diff --git a/modules/gitconfig/spec/spec_helper.rb 
b/modules/gitconfig/spec/spec_helper.rb
new file mode 100644
index 0000000..d3923f8
--- /dev/null
+++ b/modules/gitconfig/spec/spec_helper.rb
@@ -0,0 +1,8 @@
+require 'rspec-puppet'
+
+fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))
+
+RSpec.configure do |c|
+  c.module_path = File.join(fixture_path, 'modules')
+  c.manifest_dir = File.join(fixture_path, 'manifests')
+end
diff --git a/modules/gitconfig/templates/gitconfig.erb 
b/modules/gitconfig/templates/gitconfig.erb
new file mode 100644
index 0000000..9191e68
--- /dev/null
+++ b/modules/gitconfig/templates/gitconfig.erb
@@ -0,0 +1,13 @@
+# vim: set ts=4 sw=4 et:
+# This file is managed by Puppet!
+# puppet:://modules/git/gitconfig.erb
+# git::userconfig for '<%= name %>'
+
+<% settings.sort.each do |section, content|      -%>
+[<%= section %>]
+<%   content.sort.each do |key, values|          -%>
+<%     [values].flatten.sort.each do |value|     -%>
+<%= key -%> = <%= value %>
+<%     end
+  end
+end -%>

-- 
To view, visit https://gerrit.wikimedia.org/r/75855
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I49a03405fbe715269e396f6f1e0c956ba10a5f0a
Gerrit-PatchSet: 3
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Hashar <[email protected]>
Gerrit-Reviewer: Akosiaris <[email protected]>
Gerrit-Reviewer: Andrew Bogott <[email protected]>
Gerrit-Reviewer: Faidon <[email protected]>
Gerrit-Reviewer: Hashar <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to