Commit 27d9ac0f authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Make gitlab works with gitlab-shell

parent 6b9a6090
......@@ -10,11 +10,6 @@ class ApplicationController < ActionController::Base
helper_method :abilities, :can?
rescue_from Gitlab::Gitolite::AccessDenied do |exception|
log_exception(exception)
render "errors/gitolite", layout: "errors", status: 500
end
rescue_from Encoding::CompatibilityError do |exception|
log_exception(exception)
render "errors/encoding", layout: "errors", status: 500
......
......@@ -80,4 +80,8 @@ class Key < ActiveRecord::Base
def last_deploy?
Key.where(identifier: identifier).count == 0
end
def owner_name
user.username
end
end
......@@ -459,20 +459,6 @@ class Project < ActiveRecord::Base
namespace.try(:path) || ''
end
def update_repository
GitoliteWorker.perform_async(
:update_repository,
self.id
)
end
def destroy_repository
GitoliteWorker.perform_async(
:remove_repository,
self.path_with_namespace
)
end
def repo_exists?
@repo_exists ||= (repository && repository.branches.present?)
rescue
......
......@@ -25,9 +25,6 @@ class UsersProject < ActiveRecord::Base
attr_accessor :skip_git
after_save :update_repository, unless: :skip_git?
after_destroy :update_repository, unless: :skip_git?
validates :user, presence: true
validates :user_id, uniqueness: { scope: [:project_id], message: "already exists in project" }
validates :project_access, inclusion: { in: [GUEST, REPORTER, DEVELOPER, MASTER] }, presence: true
......@@ -136,10 +133,6 @@ class UsersProject < ActiveRecord::Base
end
end
def update_repository
project.update_repository
end
def project_access_human
Project.access_options.key(self.project_access)
end
......
......@@ -3,20 +3,16 @@ class KeyObserver < ActiveRecord::Observer
def after_save(key)
GitoliteWorker.perform_async(
:set_key,
key.identifier,
key.key,
key.projects.map(&:id)
:add_key,
key.owner_name,
key.key
)
end
def after_destroy(key)
return if key.is_deploy_key && !key.last_deploy?
GitoliteWorker.perform_async(
:remove_key,
key.identifier,
key.projects.map(&:id)
key.key,
)
end
end
class ProjectObserver < ActiveRecord::Observer
def after_create(project)
project.update_repository
GitoliteWorker.perform_async(
:add_repository,
project.path_with_namespace
)
log_info("#{project.owner.name} created a new project \"#{project.name_with_namespace}\"")
end
def after_update(project)
......@@ -8,14 +13,15 @@ class ProjectObserver < ActiveRecord::Observer
end
def after_destroy(project)
log_info("Project \"#{project.name}\" was removed")
GitoliteWorker.perform_async(
:remove_repository,
self.path_with_namespace
)
project.satellite.destroy
project.destroy_repository
end
def after_create project
log_info("#{project.owner.name} created a new project \"#{project.name_with_namespace}\"")
log_info("Project \"#{project.name}\" was removed")
end
protected
......
# GIT over HTTP
require Rails.root.join("lib", "gitlab", "backend", "grack_auth")
# GITOLITE backend
require Rails.root.join("lib", "gitlab", "backend", "gitolite")
# GIT over SSH
require Rails.root.join("lib", "gitlab", "backend", "shell")
module Gitlab
class Gitolite
class Shell
class AccessDenied < StandardError; end
def config
Gitlab::GitoliteConfig.new
end
# Add new key to gitlab-shell
#
# Ex.
# add_key("randx", "sha-rsa ...")
# Init new repository
#
def add_key(username, key_content)
# TODO: implement
end
# Remove ssh key from gitlab shell
# name - project path with namespace
#
# Ex.
# remove_key("sha-rsa")
# add_repository("gitlab/gitlab-ci")
#
def remove_key(key_content)
# TODO: implement
def add_repository(name)
system("/home/git/gitlab-shell/bin/gitlab-projects add-project #{name}.git")
end
# Remove repository from file system
......@@ -32,26 +21,30 @@ module Gitlab
# remove_repository("gitlab/gitlab-ci")
#
def remove_repository(name)
# TODO: implement
system("/home/git/gitlab-shell/bin/gitlab-projects rm-project #{name}.git")
end
# Init new repository
# Add new key to gitlab-shell
#
# name - project path with namespace
# Ex.
# add_key("randx", "sha-rsa ...")
#
def add_key(username, key_content)
system("/home/git/gitlab-shell/bin/gitlab-keys add-key #{username} \"#{key_content}\"")
end
# Remove ssh key from gitlab shell
#
# Ex.
# add_repository("gitlab/gitlab-ci")
# remove_key("sha-rsa")
#
def add_repository(name)
# TODO: implement
def remove_key(key_content)
system("/home/git/gitlab-shell/bin/gitlab-keys rm-key \"#{key_content}\"")
end
def url_to_repo path
Gitlab.config.gitolite.ssh_path_prefix + "#{path}.git"
end
def enable_automerge
config.admin_all_repo!
end
end
end
......@@ -6,6 +6,6 @@
#
module Gitolited
def gitolite
Gitlab::Gitolite.new
Gitlab::Shell.new
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment