Skip to content

Commit 02b960c

Browse files
committed
Make GitlabProjects#create_hooks a class method
1 parent 56e216f commit 02b960c

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

lib/gitlab_projects.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ class GitlabProjects
1616
# Ex /home/git/repositories/test.git
1717
attr_reader :full_path
1818

19+
def self.create_hooks(path)
20+
hook = File.join(path, 'hooks', 'update')
21+
File.delete(hook) if File.exists?(hook)
22+
File.symlink(File.join(ROOT_PATH, 'hooks', 'update'), hook)
23+
end
24+
1925
def initialize
2026
@command = ARGV.shift
2127
@project_name = ARGV.shift
@@ -74,13 +80,7 @@ def add_project
7480
$logger.info "Adding project #{@project_name} at <#{full_path}>."
7581
FileUtils.mkdir_p(full_path, mode: 0770)
7682
cmd = %W(git --git-dir=#{full_path} init --bare)
77-
system(*cmd) && create_hooks(full_path)
78-
end
79-
80-
def create_hooks(path)
81-
hook = File.join(path, 'hooks', 'update')
82-
File.delete(hook) if File.exists?(hook)
83-
File.symlink(File.join(ROOT_PATH, 'hooks', 'update'), hook)
83+
system(*cmd) && self.class.create_hooks(full_path)
8484
end
8585

8686
def rm_project
@@ -94,7 +94,7 @@ def import_project
9494
@source = ARGV.shift
9595
$logger.info "Importing project #{@project_name} from <#{@source}> to <#{full_path}>."
9696
cmd = %W(git clone --bare -- #{@source} #{full_path})
97-
system(*cmd) && create_hooks(full_path)
97+
system(*cmd) && self.class.create_hooks(full_path)
9898
end
9999

100100
# Move repository from one directory to another
@@ -156,7 +156,7 @@ def fork_project
156156

157157
$logger.info "Forking project from <#{full_path}> to <#{full_destination_path}>."
158158
cmd = %W(git clone --bare -- #{full_path} #{full_destination_path})
159-
system(*cmd) && create_hooks(full_destination_path)
159+
system(*cmd) && self.class.create_hooks(full_destination_path)
160160
end
161161

162162
def update_head

spec/gitlab_projects_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@
9595

9696
it "should create a directory" do
9797
gl_projects.stub(system: true)
98-
gl_projects.stub(create_hooks: true)
98+
GitlabProjects.stub(create_hooks: true)
9999
gl_projects.exec
100100
File.exists?(tmp_repo_path).should be_true
101101
end
102102

103103
it "should receive valid cmd" do
104104
valid_cmd = ['git', "--git-dir=#{tmp_repo_path}", 'init', '--bare']
105105
gl_projects.should_receive(:system).with(*valid_cmd).and_return(true)
106-
gl_projects.should_receive(:create_hooks).with(tmp_repo_path)
106+
GitlabProjects.should_receive(:create_hooks).with(tmp_repo_path)
107107
gl_projects.exec
108108
end
109109

0 commit comments

Comments
 (0)