shell.rb 1.5 KB
Newer Older
1
module Gitlab
2
  class Shell
D
Dmitriy Zaporozhets 已提交
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 13
    def add_repository(name)
      system("/home/git/gitlab-shell/bin/gitlab-projects add-project #{name}.git")
14 15
    end

16 17 18 19 20 21 22 23 24 25 26
    # Import repository
    #
    # name - project path with namespace
    #
    # Ex.
    #   import_repository("gitlab/gitlab-ci", "https://github.com/randx/six.git")
    #
    def import_repository(name, url)
      system("/home/git/gitlab-shell/bin/gitlab-projects import-project #{name}.git #{url}")
    end

D
Dmitriy Zaporozhets 已提交
27
    # Remove repository from file system
28 29 30 31 32 33 34
    #
    # name - project path with namespace
    #
    # Ex.
    #   remove_repository("gitlab/gitlab-ci")
    #
    def remove_repository(name)
35
      system("/home/git/gitlab-shell/bin/gitlab-projects rm-project #{name}.git")
D
Dmitriy Zaporozhets 已提交
36 37
    end

38
    # Add new key to gitlab-shell
D
Dmitriy Zaporozhets 已提交
39
    #
40
    # Ex.
41
    #   add_key("key-42", "sha-rsa ...")
42
    #
43 44
    def add_key(key_id, key_content)
      system("/home/git/gitlab-shell/bin/gitlab-keys add-key #{key_id} \"#{key_content}\"")
45 46 47
    end

    # Remove ssh key from gitlab shell
48 49
    #
    # Ex.
50
    #   remove_key("key-342", "sha-rsa ...")
51
    #
52 53
    def remove_key(key_id, key_content)
      system("/home/git/gitlab-shell/bin/gitlab-keys rm-key #{key_id} \"#{key_content}\"")
54 55
    end

R
randx 已提交
56
    def url_to_repo path
57
      Gitlab.config.gitlab_shell.ssh_path_prefix + "#{path}.git"
R
randx 已提交
58
    end
D
Dmitriy Zaporozhets 已提交
59 60
  end
end