Class: Hubeye::Hooks::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/hubeye/hooks/command.rb

Defined Under Namespace

Classes: NoHookError

Class Method Summary collapse

Class Method Details

.execute(commands, options = {}) ⇒ Object

options include the directory to execute the command and the full repo name of the changed repository



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/hubeye/hooks/command.rb', line 9

def self.execute(commands, options={})
  opts = {:directory => nil, :repo => nil}.merge(options)
  dir  = opts[:directory]
  repo = opts[:repo]
  begin
    commands.each do |cmd|
      if dir
        Dir.chdir(File.expand_path(dir)) do
          if repo
            ::Kernel.system "HUBEYE_CHANGED_REPO=#{repo} #{cmd}"
          else
            ::Kernel.system cmd
          end
        end
      else
        ::Kernel.system cmd
      end
    end
  rescue ArgumentError
    raise NoHookError.new "There aren't any hook commands for the repository #{repo}"
  end
end