Use similar interface to access gitolite

Simplified gitolite handle logic
Stubn over monkeypatch
Stub only specific methods in Gitlab:Gitolite
Moved grach auth to lib
added specs for keys observer
removes SshKey role
This commit is contained in:
randx 2012-08-29 00:04:06 +03:00
parent aded7056fd
commit 7cdc5b9e04
20 changed files with 155 additions and 88 deletions

View file

@ -1,7 +1,6 @@
require 'digest/md5'
class Key < ActiveRecord::Base
include SshKey
belongs_to :user
belongs_to :project
@ -50,6 +49,10 @@ class Key < ActiveRecord::Base
user.projects
end
end
def last_deploy?
Key.where(identifier: identifier).count == 0
end
end
# == Schema Information
#

View file

@ -1,4 +1,6 @@
class ProtectedBranch < ActiveRecord::Base
include GitHost
belongs_to :project
validates_presence_of :project_id
validates_presence_of :name
@ -7,7 +9,7 @@ class ProtectedBranch < ActiveRecord::Base
after_destroy :update_repository
def update_repository
Gitlab::GitHost.system.update_project(project.path, project)
git_host.update_repository(project)
end
def commit

View file

@ -1,4 +1,6 @@
class UsersProject < ActiveRecord::Base
include GitHost
GUEST = 10
REPORTER = 20
DEVELOPER = 30
@ -58,9 +60,7 @@ class UsersProject < ActiveRecord::Base
end
def update_repository
Gitlab::GitHost.system.new.configure do |c|
c.update_project(project.path, project)
end
git_host.update_repository(project)
end
def project_access_human

View file

@ -1,9 +1,12 @@
class KeyObserver < ActiveRecord::Observer
include GitHost
def after_save(key)
key.update_repository
git_host.set_key(key.identifier, key.key, key.projects)
end
def after_destroy(key)
key.repository_delete_key
return if key.is_deploy_key && !key.last_deploy?
git_host.remove_key(key.identifier, key.projects)
end
end

5
app/roles/git_host.rb Normal file
View file

@ -0,0 +1,5 @@
module GitHost
def git_host
Gitlab::Gitolite.new
end
end

View file

@ -1,2 +0,0 @@
module GitMerge
end

View file

@ -1,4 +1,6 @@
module Repository
include GitHost
def valid_repo?
repo
rescue
@ -48,7 +50,7 @@ module Repository
end
def url_to_repo
Gitlab::GitHost.url_to_repo(path)
git_host.url_to_repo(path)
end
def path_to_repo
@ -56,11 +58,11 @@ module Repository
end
def update_repository
Gitlab::GitHost.system.update_project(path, self)
git_host.update_repository(self)
end
def destroy_repository
Gitlab::GitHost.system.destroy_project(self)
git_host.remove_repository(self)
end
def repo_exists?

View file

@ -1,18 +0,0 @@
module SshKey
def update_repository
Gitlab::GitHost.system.new.configure do |c|
c.update_keys(identifier, key)
c.update_projects(projects)
end
end
def repository_delete_key
Gitlab::GitHost.system.new.configure do |c|
#delete key file is there is no identically deploy keys
if !is_deploy_key || Key.where(identifier: identifier).count() == 0
c.delete_key(identifier)
end
c.update_projects(projects)
end
end
end