summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab_config.rb4
-rw-r--r--lib/gitlab_projects.rb35
-rw-r--r--lib/gitlab_update.rb17
3 files changed, 50 insertions, 6 deletions
diff --git a/lib/gitlab_config.rb b/lib/gitlab_config.rb
index 6cfee5d..ac6cc19 100644
--- a/lib/gitlab_config.rb
+++ b/lib/gitlab_config.rb
@@ -22,4 +22,8 @@ class GitlabConfig
def http_settings
@config['http_settings'] ||= {}
end
+
+ def redis
+ @config['redis'] ||= {}
+ end
end
diff --git a/lib/gitlab_projects.rb b/lib/gitlab_projects.rb
index aef343e..0b9bb8c 100644
--- a/lib/gitlab_projects.rb
+++ b/lib/gitlab_projects.rb
@@ -29,6 +29,7 @@ class GitlabProjects
when 'rm-project'; rm_project
when 'mv-project'; mv_project
when 'import-project'; import_project
+ when 'fork-project'; fork_project
else
puts 'not allowed'
false
@@ -44,10 +45,7 @@ class GitlabProjects
end
def create_hooks_cmd
- pr_hook_path = File.join(ROOT_PATH, 'hooks', 'post-receive')
- up_hook_path = File.join(ROOT_PATH, 'hooks', 'update')
-
- "ln -s #{pr_hook_path} #{full_path}/hooks/post-receive && ln -s #{up_hook_path} #{full_path}/hooks/update"
+ create_hooks_to(full_path)
end
def rm_project
@@ -84,4 +82,33 @@ class GitlabProjects
FileUtils.mv(full_path, new_full_path)
end
+
+ def fork_project
+ new_namespace = ARGV.shift
+
+ # destination namespace must be provided
+ return false unless new_namespace
+
+ #destination namespace must exist
+ namespaced_path = File.join(repos_path, new_namespace)
+ return false unless File.exists?(namespaced_path)
+
+ #a project of the same name cannot already be within the destination namespace
+ full_destination_path = File.join(namespaced_path, project_name.split('/')[-1])
+ return false if File.exists?(full_destination_path)
+
+ cmd = "cd #{namespaced_path} && git clone --bare #{full_path} && #{create_hooks_to(full_destination_path)}"
+ system(cmd)
+ end
+
+ private
+
+ def create_hooks_to(dest_path)
+ pr_hook_path = File.join(ROOT_PATH, 'hooks', 'post-receive')
+ up_hook_path = File.join(ROOT_PATH, 'hooks', 'update')
+
+ "ln -s #{pr_hook_path} #{dest_path}/hooks/post-receive && ln -s #{up_hook_path} #{dest_path}/hooks/update"
+
+ end
+
end
diff --git a/lib/gitlab_update.rb b/lib/gitlab_update.rb
index 8282897..a486ecc 100644
--- a/lib/gitlab_update.rb
+++ b/lib/gitlab_update.rb
@@ -3,9 +3,11 @@ require_relative 'gitlab_net'
class GitlabUpdate
def initialize(repo_path, key_id, refname)
+ config = GitlabConfig.new
+
@repo_path = repo_path.strip
@repo_name = repo_path
- @repo_name.gsub!(GitlabConfig.new.repos_path.to_s, "")
+ @repo_name.gsub!(config.repos_path.to_s, "")
@repo_name.gsub!(/\.git$/, "")
@repo_name.gsub!(/^\//, "")
@@ -15,6 +17,8 @@ class GitlabUpdate
@oldrev = ARGV[1]
@newrev = ARGV[2]
+
+ @redis = config.redis
end
def exec
@@ -49,7 +53,16 @@ class GitlabUpdate
end
def update_redis
- command = "env -i redis-cli rpush 'resque:gitlab:queue:post_receive' '{\"class\":\"PostReceive\",\"args\":[\"#{@repo_path}\",\"#{@oldrev}\",\"#{@newrev}\",\"#{@refname}\",\"#{@key_id}\"]}' > /dev/null 2>&1"
+ if !@redis.empty? && !@redis.has_key?("socket")
+ redis_command = "#{@redis['bin']} -h #{@redis['host']} -p #{@redis['port']}"
+ elsif !@redis.empty? && @redis.has_key?("socket")
+ redis_command = "#{@redis['bin']} -s #{@redis['socket']}"
+ else
+ # Default to old method of connecting to redis for users that haven't updated their configuration
+ redis_command = "env -i redis-cli"
+ end
+
+ command = "#{redis_command} rpush '#{@redis['namespace']}:queue:post_receive' '{\"class\":\"PostReceive\",\"args\":[\"#{@repo_path}\",\"#{@oldrev}\",\"#{@newrev}\",\"#{@refname}\",\"#{@key_id}\"]}' > /dev/null 2>&1"
system(command)
end
end