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