Hashar has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/75855


Change subject: git::userconfig to easily craft .gitconfig files
......................................................................

git::userconfig to easily craft .gitconfig files

The new module git contains a single define 'git::userconfig' 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.

No usage yet.

Change-Id: I49a03405fbe715269e396f6f1e0c956ba10a5f0a
---
A modules/git/Rakefile
A modules/git/manifests/userconfig.pp
A modules/git/spec/defines/userconfig_spec.rb
A modules/git/spec/fixtures/manifests/site.pp
A modules/git/spec/fixtures/modules/git/manifests
A modules/git/spec/fixtures/modules/git/templates
A modules/git/spec/spec_helper.rb
A modules/git/templates/gitconfig.erb
8 files changed, 93 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/55/75855/1

diff --git a/modules/git/Rakefile b/modules/git/Rakefile
new file mode 100644
index 0000000..e6443dc
--- /dev/null
+++ b/modules/git/Rakefile
@@ -0,0 +1,7 @@
+require 'rake'
+
+require 'rspec/core/rake_task'
+
+RSpec::Core::RakeTask.new(:spec) do |t|
+  t.pattern = 'spec/*/*_spec.rb'
+end
diff --git a/modules/git/manifests/userconfig.pp 
b/modules/git/manifests/userconfig.pp
new file mode 100644
index 0000000..4d2f36d
--- /dev/null
+++ b/modules/git/manifests/userconfig.pp
@@ -0,0 +1,33 @@
+# == git::userconfig
+#
+# 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:
+#
+# git::userconfig{ '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 git::userconfig($homedir, $settings) {
+
+  file { "${homedir}/.gitconfig":
+    ensure  => present,
+    owner   => 'root',
+    group   => 'root',
+    mode    => '0444',
+    content => template( 'git/gitconfig.erb' )
+  }
+
+}
diff --git a/modules/git/spec/defines/userconfig_spec.rb 
b/modules/git/spec/defines/userconfig_spec.rb
new file mode 100644
index 0000000..468ffba
--- /dev/null
+++ b/modules/git/spec/defines/userconfig_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 'git::userconfig', :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/git/spec/fixtures/manifests/site.pp 
b/modules/git/spec/fixtures/manifests/site.pp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/modules/git/spec/fixtures/manifests/site.pp
diff --git a/modules/git/spec/fixtures/modules/git/manifests 
b/modules/git/spec/fixtures/modules/git/manifests
new file mode 120000
index 0000000..373b992
--- /dev/null
+++ b/modules/git/spec/fixtures/modules/git/manifests
@@ -0,0 +1 @@
+../../../../manifests
\ No newline at end of file
diff --git a/modules/git/spec/fixtures/modules/git/templates 
b/modules/git/spec/fixtures/modules/git/templates
new file mode 120000
index 0000000..f8a06d1
--- /dev/null
+++ b/modules/git/spec/fixtures/modules/git/templates
@@ -0,0 +1 @@
+../../../../templates
\ No newline at end of file
diff --git a/modules/git/spec/spec_helper.rb b/modules/git/spec/spec_helper.rb
new file mode 100644
index 0000000..d3923f8
--- /dev/null
+++ b/modules/git/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/git/templates/gitconfig.erb 
b/modules/git/templates/gitconfig.erb
new file mode 100644
index 0000000..9191e68
--- /dev/null
+++ b/modules/git/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: newchange
Gerrit-Change-Id: I49a03405fbe715269e396f6f1e0c956ba10a5f0a
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Hashar <[email protected]>

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

Reply via email to