[SCM] ci-tooling packaging branch, master, updated. 7cf28908dd7737a5e9eb8a10b6d7f63a3c767d94

Harald Sitter apachelogger-guest at moszumanska.debian.org
Sun Jan 18 21:42:13 UTC 2015


Gitweb-URL: http://git.debian.org/?p=pkg-kde/ci-tooling.git;a=commitdiff;h=7cf2890

The following commit has been merged in the master branch:
commit 7cf28908dd7737a5e9eb8a10b6d7f63a3c767d94
Author: Harald Sitter <sitter at kde.org>
Date:   Sun Jan 18 22:41:17 2015 +0100

    jenkins: stop having a dangling method to construct jenkinses
    
    - new module AutoConfigJenkinsClient providing an init that pulls in
      config data from file
    - said module is prepended onto the existing client class allowing one
      to do JenkinsApi::Client.new and it will work like previous new_jenkins
    - additionally there's module Jenkins which provides a glorified
      singleton access method to client and job and plugin_manager as the
      entire lib is really stateless and there is no point in having to
      construct things a new all the time
    - new_jenkins method is still there but now throws warnings about being
      deprecated
---
 lib/jenkins.rb | 51 +++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 47 insertions(+), 4 deletions(-)

diff --git a/lib/jenkins.rb b/lib/jenkins.rb
index 70a7612..374ddcc 100644
--- a/lib/jenkins.rb
+++ b/lib/jenkins.rb
@@ -4,18 +4,61 @@ if Process.uid == '0'
     exit 1 unless system("gem install jenkins_api_client")
 end
 
-require 'rubygems'
 require 'jenkins_api_client'
 
-def new_jenkins(args = {})
+# Monkey patch for Client to fold in our config data.
+# This is entirely and only necessary because the silly default client
+# doesn't allow setting default values on the module or class.
+module AutoConfigJenkinsClient
+  # Monkey patched initialize. Merges the passed args with the data read
+  # from the config file and then calls the proper initialize.
+  def initialize(args = {})
     config_file = "#{ENV['HOME']}/.config/pangea-jenkins.json"
     config_data = {}
     if File.exist?(config_file)
-        config_data = JSON::parse(File.read(config_file), :symbolize_names => true)
+      config_data = JSON.parse(File.read(config_file), symbolize_names: true)
     end
     config_data[:server_ip] ||= 'kci.pangea.pub'
     config_data[:server_port] ||= '80'
     config_data[:log_level] ||= Logger::FATAL
     config_data.merge!(args)
-    return JenkinsApi::Client.new(config_data)
+    super(config_data)
+  end
+end
+
+module JenkinsApi
+  # Standard client with prepended config supremacy. See
+  # {AutoConfigJenkinsClient}.
+  class Client
+    prepend AutoConfigJenkinsClient
+  end
+end
+
+# Convenience wrapper around JenkinsApi::Client providing a singular instance.
+module Jenkins
+  module_function
+
+  # @return a singleton instance of {JenkinsApi::Client}
+  def client
+    @client ||= JenkinsApi::Client.new
+  end
+
+  # Convenience method wrapping {#client.job}.
+  # @return a singleton instance of {JenkinsApi::Job}
+  def job
+    @job ||= client.job
+  end
+
+  # Convenience method wrapping {#client.plugin}.
+  # @return a singleton instance of {JenkinsApi::PluginManager}
+  def plugin_manager
+    @plugin_manager ||= client.plugin
+  end
+end
+
+# @deprecated Use {Jenkins.client}.
+def new_jenkins(args = {})
+  warn 'warning: calling new_jenkins is deprecated'
+  warn 'warning: arguments passed to new_jenkins are not passed along' if args
+  Jenkins.client
 end

-- 
ci-tooling packaging



More information about the pkg-kde-commits mailing list