Class: Gitlab::Git::Hook

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/git/hook.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, repo_path) ⇒ Hook

Returns a new instance of Hook


6
7
8
9
10
# File 'lib/gitlab/git/hook.rb', line 6

def initialize(name, repo_path)
  @name = name
  @repo_path = repo_path
  @path = File.join(repo_path.strip, 'hooks', name)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


4
5
6
# File 'lib/gitlab/git/hook.rb', line 4

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path


4
5
6
# File 'lib/gitlab/git/hook.rb', line 4

def path
  @path
end

#repo_pathObject (readonly)

Returns the value of attribute repo_path


4
5
6
# File 'lib/gitlab/git/hook.rb', line 4

def repo_path
  @repo_path
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)

12
13
14
# File 'lib/gitlab/git/hook.rb', line 12

def exists?
  File.exist?(path)
end

#trigger(gl_id, oldrev, newrev, ref) ⇒ Object


16
17
18
19
20
21
22
23
24
25
# File 'lib/gitlab/git/hook.rb', line 16

def trigger(gl_id, oldrev, newrev, ref)
  return true unless exists?

  case name
  when "pre-receive", "post-receive"
    call_receive_hook(gl_id, oldrev, newrev, ref)
  when "update"
    call_update_hook(gl_id, oldrev, newrev, ref)
  end
end