summaryrefslogtreecommitdiff
path: root/lib/gitlab/backend/gitolite.rb
blob: d026b76f5efbb2d2cc0c5456736398934635dcf6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require_relative 'gitolite_config'

module Gitlab
  class Gitolite
    class AccessDenied < StandardError; end

    def config
      Gitlab::GitoliteConfig.new
    end

    def set_key key_id, key_content, projects
      config.apply do |config|
        config.write_key(key_id, key_content)
        config.update_projects(projects)
      end
    end

    def remove_key key_id, projects
      config.apply do |config|
        config.rm_key(key_id)
        config.update_projects(projects)
      end
    end

    def update_repository project_id
      project = Project.find(project_id)
      config.update_project!(project)
    end

    def move_repository(old_repo, project)
      config.apply do |config|
        config.clean_repo(old_repo)
        config.update_project(project)
      end
    end

    # Remove repository from gitolite
    #
    # name - project path with namespace
    #
    # Ex.
    #   remove_repository("gitlab/gitlab-ci")
    #
    def remove_repository(name)
      config.destroy_project!(name)
    end

    def url_to_repo path
      Gitlab.config.gitolite.ssh_path_prefix + "#{path}.git"
    end

    def enable_automerge
      config.admin_all_repo!
    end

    def update_repositories projects
      config.apply do |config|
        config.update_projects(projects)
      end
    end

    alias_method :create_repository, :update_repository
  end
end