OSDN Git Service

Update svn hook scripts
authorAkihiro Ono <a-ono@users.sourceforge.jp>
Sun, 23 Jan 2011 13:51:37 +0000 (22:51 +0900)
committerAkihiro Ono <a-ono@users.sourceforge.jp>
Sun, 23 Jan 2011 13:51:37 +0000 (22:51 +0900)
script/hooks/subversion_hook/base.rb
script/hooks/subversion_hook/post_commit.rb
script/hooks/subversion_hook/pre_commit.rb

index ccbe41e..d3705ae 100644 (file)
@@ -59,7 +59,8 @@ module SubversionHook
                        end\r
                        \r
                        list = @changed_files[options[:type]] || @changed_files[:all]\r
-                       list = list.select {|path| path.index(options[:in]) == 0} if options[:in]\r
+                       list = list.select {|path| options[:in].to_a.any? {|inpath|\r
+          path.index(inpath) == 0} if options[:in]\r
                        list = list.select {|path|\r
                                options[:extension].include?(File.extname(path).downcase)\r
                        } if options[:extension]\r
@@ -70,14 +71,5 @@ module SubversionHook
                        file = File.join(@repos, "hooks/hook_config.yml")\r
                        conf = File.file?(file) ? YAML.load_file(file) : {}\r
                end\r
-\r
-               def http_port\r
-                       unless @http_port\r
-                               filename ||= File.join(HOME, "config/service.yml")\r
-                               conf = File.file?(filename) ? YAML.load_file(filename) : {}\r
-                               @http_port = conf["apache"]["port"]\r
-                       end\r
-                       @http_port\r
-               end\r
        end\r
 end\r
index 596659b..d98f314 100644 (file)
@@ -21,26 +21,19 @@ module SubversionHook
                end\r
 \r
                def fetch_changesets(options)\r
-                       return unless changed_files.size > 0\r
-\r
                        run_background(%Q[ruby "#{HOME}/redmine/script/runner" "Repository.fetch_changesets"])\r
                end\r
 \r
                def perform_build(options)\r
-                       return unless options["jobs"]\r
-                       options["jobs"].each {|job|\r
-                               name = job["name"]\r
-                               next unless name || changed_files(:in => job["path"]).size > 0\r
+                       port = options["http_port"] || 80\r
+                       token = options["token"]\r
+                       return unless jobs = options["jobs"]\r
 \r
-                               hudson_xml = File.join(HOME, "hudson/home/jobs/#{name}/config.xml")\r
-                               path = "/hudson/job/#{name}/build"\r
-                               next unless File.file?(hudson_xml)\r
+                       jobs.each {|job|\r
+                               next unless changed_files(:in => job["path"]).size > 0\r
+                               name = job["name"]\r
 \r
-                               require 'rexml/document'\r
-                               doc = REXML::Document.new(File.new(hudson_xml))\r
-                               elem = doc.elements["/project/authToken"]\r
-                               path += "?token=#{elem.text}" if elem\r
-                               run_background(%Q[ruby -e "require 'net/http'; Net::HTTP.get('localhost', '#{path}', #{http_port})"])\r
+                               run_background(%Q[ruby -e "require 'net/http'; Net::HTTP.get('localhost', '/hudson/job/#{name}/build?token=#{token}', #{port})"])\r
                        }\r
                end\r
        end\r
index 1745725..a26e320 100644 (file)
@@ -37,9 +37,11 @@ module SubversionHook
                end\r
 \r
                def check_commit_message(options)\r
-                       return unless changed_files(:in => options["path"]).size > 0\r
+                       path = options["path"]\r
+                       keywords = options["keywords"]\r
+                       return unless changed_files(:in => path).size > 0\r
 \r
-                       (options["keywords"] || []).each {|keyword|\r
+                       keywords.each {|keyword|\r
                                begin\r
                                        case keyword\r
                                        when String\r
@@ -71,8 +73,9 @@ module SubversionHook
                def check_encoding(options)\r
                        require 'iconv'\r
 \r
+                       path = options["path"]\r
                        @encoding = options["encoding"]\r
-                       changed_files(:type => :text, :in => options["path"], :extension => options["filetype"]).each {|file|\r
+                       changed_files(:type => :text, :in => path, :extension => options["filetype"]).each {|file|\r
                                begin\r
                                        Iconv.iconv(@encoding, @encoding, cat(file))\r
                                rescue Iconv::IllegalSequence\r
@@ -83,13 +86,14 @@ module SubversionHook
 \r
                # type: space or tab (default both)\r
                def check_white_space(options)\r
+                       path = options["path"]\r
                        h = {"space" => " ", "tab" => "\t"}\r
                        char = h[options["type"]]\r
                        @white_space_error_message = char ?\r
                                "The following files are not indented with #{options['type']} only:" :\r
                                "The following files are indented with a mixture of tabs and spaces:"\r
 \r
-                       changed_files(:type => :text, :in => options["path"], :extension => options["filetype"]).each {|file|\r
+                       changed_files(:type => :text, :in => path, :extension => options["filetype"]).each {|file|\r
                                cat(file).each{|line|\r
                                        next unless s = line.match(/^\s+/)\r
                                        s = s.to_s\r