2012-09-07 07:16:29 +02:00
|
|
|
require_relative 'gitolite_config'
|
2011-12-04 00:44:59 +01:00
|
|
|
|
2012-05-26 12:37:49 +02:00
|
|
|
module Gitlab
|
2011-12-04 00:44:59 +01:00
|
|
|
class Gitolite
|
|
|
|
class AccessDenied < StandardError; end
|
2012-09-07 07:16:29 +02:00
|
|
|
|
|
|
|
def config
|
2012-09-07 14:36:40 +02:00
|
|
|
Gitlab::GitoliteConfig.new
|
2012-09-07 07:16:29 +02:00
|
|
|
end
|
2011-12-04 00:44:59 +01:00
|
|
|
|
2013-01-28 20:02:10 +01:00
|
|
|
# Update gitolite config with new key
|
|
|
|
#
|
|
|
|
# Ex.
|
|
|
|
# set_key("m_gitlab_com_12343", "sha-rsa ...", [2, 3, 6])
|
|
|
|
#
|
|
|
|
def set_key(key_id, key_content, project_ids)
|
|
|
|
projects = Project.where(id: project_ids)
|
|
|
|
|
2012-09-07 07:16:29 +02:00
|
|
|
config.apply do |config|
|
|
|
|
config.write_key(key_id, key_content)
|
|
|
|
config.update_projects(projects)
|
2012-08-28 23:04:06 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-28 20:02:10 +01:00
|
|
|
# Remove ssh key from gitolite config
|
|
|
|
#
|
|
|
|
# Ex.
|
|
|
|
# remove_key("m_gitlab_com_12343", [2, 3, 6])
|
|
|
|
#
|
|
|
|
def remove_key(key_id, project_ids)
|
|
|
|
projects = Project.where(id: project_ids)
|
|
|
|
|
2012-09-07 07:16:29 +02:00
|
|
|
config.apply do |config|
|
|
|
|
config.rm_key(key_id)
|
|
|
|
config.update_projects(projects)
|
2012-08-28 23:04:06 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-28 16:39:02 +01:00
|
|
|
# Update project config in gitolite by project id
|
|
|
|
#
|
|
|
|
# Ex.
|
|
|
|
# update_repository(23)
|
|
|
|
#
|
|
|
|
def update_repository(project_id)
|
2013-01-28 16:22:45 +01:00
|
|
|
project = Project.find(project_id)
|
2012-11-27 07:31:15 +01:00
|
|
|
config.update_project!(project)
|
2012-03-05 23:26:40 +01:00
|
|
|
end
|
|
|
|
|
2012-11-27 15:35:00 +01:00
|
|
|
def move_repository(old_repo, project)
|
2012-11-21 06:54:05 +01:00
|
|
|
config.apply do |config|
|
|
|
|
config.clean_repo(old_repo)
|
2012-11-27 15:35:00 +01:00
|
|
|
config.update_project(project)
|
2012-11-21 06:54:05 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-28 16:22:45 +01:00
|
|
|
# Remove repository from gitolite
|
|
|
|
#
|
|
|
|
# name - project path with namespace
|
|
|
|
#
|
|
|
|
# Ex.
|
|
|
|
# remove_repository("gitlab/gitlab-ci")
|
|
|
|
#
|
|
|
|
def remove_repository(name)
|
|
|
|
config.destroy_project!(name)
|
2012-03-05 23:26:40 +01:00
|
|
|
end
|
|
|
|
|
2013-01-28 16:39:02 +01:00
|
|
|
# Update projects configs in gitolite by project ids
|
|
|
|
#
|
|
|
|
# Ex.
|
|
|
|
# update_repositories([1, 4, 6])
|
|
|
|
#
|
|
|
|
def update_repositories(project_ids)
|
|
|
|
projects = Project.where(id: project_ids)
|
|
|
|
|
|
|
|
config.apply do |config|
|
|
|
|
config.update_projects(projects)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-08-28 23:04:06 +02:00
|
|
|
def url_to_repo path
|
2012-12-15 01:16:25 +01:00
|
|
|
Gitlab.config.gitolite.ssh_path_prefix + "#{path}.git"
|
2012-08-28 23:04:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def enable_automerge
|
2012-09-08 13:24:38 +02:00
|
|
|
config.admin_all_repo!
|
2012-03-30 07:25:04 +02:00
|
|
|
end
|
2012-08-28 23:33:19 +02:00
|
|
|
|
2012-09-07 07:16:29 +02:00
|
|
|
alias_method :create_repository, :update_repository
|
2011-12-04 00:44:59 +01:00
|
|
|
end
|
|
|
|
end
|