Commit 27d9ac0fe8a33f0e94178c1f46826bc114e16467
1 parent
6b9a6090
Exists in
master
and in
4 other branches
Make gitlab works with gitlab-shell
Showing
10 changed files
with
72 additions
and
99 deletions
Show diff stats
app/controllers/application_controller.rb
... | ... | @@ -10,11 +10,6 @@ class ApplicationController < ActionController::Base |
10 | 10 | |
11 | 11 | helper_method :abilities, :can? |
12 | 12 | |
13 | - rescue_from Gitlab::Gitolite::AccessDenied do |exception| | |
14 | - log_exception(exception) | |
15 | - render "errors/gitolite", layout: "errors", status: 500 | |
16 | - end | |
17 | - | |
18 | 13 | rescue_from Encoding::CompatibilityError do |exception| |
19 | 14 | log_exception(exception) |
20 | 15 | render "errors/encoding", layout: "errors", status: 500 | ... | ... |
app/models/key.rb
app/models/project.rb
... | ... | @@ -459,20 +459,6 @@ class Project < ActiveRecord::Base |
459 | 459 | namespace.try(:path) || '' |
460 | 460 | end |
461 | 461 | |
462 | - def update_repository | |
463 | - GitoliteWorker.perform_async( | |
464 | - :update_repository, | |
465 | - self.id | |
466 | - ) | |
467 | - end | |
468 | - | |
469 | - def destroy_repository | |
470 | - GitoliteWorker.perform_async( | |
471 | - :remove_repository, | |
472 | - self.path_with_namespace | |
473 | - ) | |
474 | - end | |
475 | - | |
476 | 462 | def repo_exists? |
477 | 463 | @repo_exists ||= (repository && repository.branches.present?) |
478 | 464 | rescue | ... | ... |
app/models/users_project.rb
... | ... | @@ -25,9 +25,6 @@ class UsersProject < ActiveRecord::Base |
25 | 25 | |
26 | 26 | attr_accessor :skip_git |
27 | 27 | |
28 | - after_save :update_repository, unless: :skip_git? | |
29 | - after_destroy :update_repository, unless: :skip_git? | |
30 | - | |
31 | 28 | validates :user, presence: true |
32 | 29 | validates :user_id, uniqueness: { scope: [:project_id], message: "already exists in project" } |
33 | 30 | validates :project_access, inclusion: { in: [GUEST, REPORTER, DEVELOPER, MASTER] }, presence: true |
... | ... | @@ -136,10 +133,6 @@ class UsersProject < ActiveRecord::Base |
136 | 133 | end |
137 | 134 | end |
138 | 135 | |
139 | - def update_repository | |
140 | - project.update_repository | |
141 | - end | |
142 | - | |
143 | 136 | def project_access_human |
144 | 137 | Project.access_options.key(self.project_access) |
145 | 138 | end | ... | ... |
app/observers/key_observer.rb
... | ... | @@ -3,20 +3,16 @@ class KeyObserver < ActiveRecord::Observer |
3 | 3 | |
4 | 4 | def after_save(key) |
5 | 5 | GitoliteWorker.perform_async( |
6 | - :set_key, | |
7 | - key.identifier, | |
8 | - key.key, | |
9 | - key.projects.map(&:id) | |
6 | + :add_key, | |
7 | + key.owner_name, | |
8 | + key.key | |
10 | 9 | ) |
11 | 10 | end |
12 | 11 | |
13 | 12 | def after_destroy(key) |
14 | - return if key.is_deploy_key && !key.last_deploy? | |
15 | - | |
16 | 13 | GitoliteWorker.perform_async( |
17 | 14 | :remove_key, |
18 | - key.identifier, | |
19 | - key.projects.map(&:id) | |
15 | + key.key, | |
20 | 16 | ) |
21 | 17 | end |
22 | 18 | end | ... | ... |
app/observers/project_observer.rb
1 | 1 | class ProjectObserver < ActiveRecord::Observer |
2 | 2 | def after_create(project) |
3 | - project.update_repository | |
3 | + GitoliteWorker.perform_async( | |
4 | + :add_repository, | |
5 | + project.path_with_namespace | |
6 | + ) | |
7 | + | |
8 | + log_info("#{project.owner.name} created a new project \"#{project.name_with_namespace}\"") | |
4 | 9 | end |
5 | 10 | |
6 | 11 | def after_update(project) |
... | ... | @@ -8,14 +13,15 @@ class ProjectObserver < ActiveRecord::Observer |
8 | 13 | end |
9 | 14 | |
10 | 15 | def after_destroy(project) |
11 | - log_info("Project \"#{project.name}\" was removed") | |
16 | + GitoliteWorker.perform_async( | |
17 | + :remove_repository, | |
18 | + self.path_with_namespace | |
19 | + ) | |
12 | 20 | |
13 | 21 | project.satellite.destroy |
14 | 22 | project.destroy_repository |
15 | - end | |
16 | 23 | |
17 | - def after_create project | |
18 | - log_info("#{project.owner.name} created a new project \"#{project.name_with_namespace}\"") | |
24 | + log_info("Project \"#{project.name}\" was removed") | |
19 | 25 | end |
20 | 26 | |
21 | 27 | protected | ... | ... |
config/initializers/5_backend.rb
lib/gitlab/backend/gitolite.rb
... | ... | @@ -1,57 +0,0 @@ |
1 | -module Gitlab | |
2 | - class Gitolite | |
3 | - class AccessDenied < StandardError; end | |
4 | - | |
5 | - def config | |
6 | - Gitlab::GitoliteConfig.new | |
7 | - end | |
8 | - | |
9 | - # Add new key to gitlab-shell | |
10 | - # | |
11 | - # Ex. | |
12 | - # add_key("randx", "sha-rsa ...") | |
13 | - # | |
14 | - def add_key(username, key_content) | |
15 | - # TODO: implement | |
16 | - end | |
17 | - | |
18 | - # Remove ssh key from gitlab shell | |
19 | - # | |
20 | - # Ex. | |
21 | - # remove_key("sha-rsa") | |
22 | - # | |
23 | - def remove_key(key_content) | |
24 | - # TODO: implement | |
25 | - end | |
26 | - | |
27 | - # Remove repository from file system | |
28 | - # | |
29 | - # name - project path with namespace | |
30 | - # | |
31 | - # Ex. | |
32 | - # remove_repository("gitlab/gitlab-ci") | |
33 | - # | |
34 | - def remove_repository(name) | |
35 | - # TODO: implement | |
36 | - end | |
37 | - | |
38 | - # Init new repository | |
39 | - # | |
40 | - # name - project path with namespace | |
41 | - # | |
42 | - # Ex. | |
43 | - # add_repository("gitlab/gitlab-ci") | |
44 | - # | |
45 | - def add_repository(name) | |
46 | - # TODO: implement | |
47 | - end | |
48 | - | |
49 | - def url_to_repo path | |
50 | - Gitlab.config.gitolite.ssh_path_prefix + "#{path}.git" | |
51 | - end | |
52 | - | |
53 | - def enable_automerge | |
54 | - config.admin_all_repo! | |
55 | - end | |
56 | - end | |
57 | -end |
... | ... | @@ -0,0 +1,50 @@ |
1 | +module Gitlab | |
2 | + class Shell | |
3 | + class AccessDenied < StandardError; end | |
4 | + | |
5 | + # Init new repository | |
6 | + # | |
7 | + # name - project path with namespace | |
8 | + # | |
9 | + # Ex. | |
10 | + # add_repository("gitlab/gitlab-ci") | |
11 | + # | |
12 | + def add_repository(name) | |
13 | + system("/home/git/gitlab-shell/bin/gitlab-projects add-project #{name}.git") | |
14 | + end | |
15 | + | |
16 | + # Remove repository from file system | |
17 | + # | |
18 | + # name - project path with namespace | |
19 | + # | |
20 | + # Ex. | |
21 | + # remove_repository("gitlab/gitlab-ci") | |
22 | + # | |
23 | + def remove_repository(name) | |
24 | + system("/home/git/gitlab-shell/bin/gitlab-projects rm-project #{name}.git") | |
25 | + end | |
26 | + | |
27 | + # Add new key to gitlab-shell | |
28 | + # | |
29 | + # Ex. | |
30 | + # add_key("randx", "sha-rsa ...") | |
31 | + # | |
32 | + def add_key(username, key_content) | |
33 | + system("/home/git/gitlab-shell/bin/gitlab-keys add-key #{username} \"#{key_content}\"") | |
34 | + end | |
35 | + | |
36 | + # Remove ssh key from gitlab shell | |
37 | + # | |
38 | + # Ex. | |
39 | + # remove_key("sha-rsa") | |
40 | + # | |
41 | + def remove_key(key_content) | |
42 | + system("/home/git/gitlab-shell/bin/gitlab-keys rm-key \"#{key_content}\"") | |
43 | + end | |
44 | + | |
45 | + | |
46 | + def url_to_repo path | |
47 | + Gitlab.config.gitolite.ssh_path_prefix + "#{path}.git" | |
48 | + end | |
49 | + end | |
50 | +end | ... | ... |