Class: UniversalGitClient::Http::Gitlab

Inherits:
Base
  • Object
show all
Defined in:
lib/universal-git-client/http/gitlab.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods included from ResponseValidation

#with_response_validation!

Constructor Details

This class inherits a constructor from UniversalGitClient::Http::Base

Instance Method Details

#branch(owner:, repo:, branch:) ⇒ Object



79
80
81
82
83
84
85
86
87
88
# File 'lib/universal-git-client/http/gitlab.rb', line 79

def branch(owner:, repo:, branch:)
  encoded_namespace = encode_namespace(owner, repo)
  encoded_branch = URI.encode_www_form_component(branch)
  with_response_validation! do
    self.class.get(
      "/projects/#{encoded_namespace}/repository/branches/#{encoded_branch}",
      default_options
    )
  end
end

#branches(owner:, repo:, page: 1, per_page: nil) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/universal-git-client/http/gitlab.rb', line 64

def branches(owner:, repo:, page: 1, per_page: nil)
  encoded_namespace = encode_namespace(owner, repo)
  with_response_validation! do
    self.class.get(
      "/projects/#{encoded_namespace}/repository/branches",
      default_options.merge(
        query: {
          page: page,
          per_page: per_page || default_elements_per_page,
        },
      )
    )
  end
end

#delete_repo_webhook(owner:, repo:, webhook_id:) ⇒ Object



114
115
116
117
118
119
120
121
122
# File 'lib/universal-git-client/http/gitlab.rb', line 114

def delete_repo_webhook(owner:, repo:, webhook_id:)
  encoded_namespace = encode_namespace(owner, repo)
  with_response_validation! do
    self.class.delete(
      "/projects/#{encoded_namespace}/hooks/#{webhook_id}",
      default_options
    )
  end
end

#download_repo_archive(owner:, repo:, branch: nil) ⇒ Object



90
91
92
93
94
95
# File 'lib/universal-git-client/http/gitlab.rb', line 90

def download_repo_archive(owner:, repo:, branch: nil)
  encoded_namespace = encode_namespace(owner, repo)
  path = "#{base_url}/projects/#{encoded_namespace}/repository/archive.zip"
  path << "?sha=#{branch}" if branch
  Down.download(path, down_default_options)
end

#orga_repos(organization:, page: 1, per_page: nil) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/universal-git-client/http/gitlab.rb', line 42

def orga_repos(organization:, page: 1, per_page: nil)
  encoded_namespace = URI.encode_www_form_component(organization)
  with_response_validation! do
    self.class.get(
      "/groups/#{encoded_namespace}/projects",
      default_options.merge(
        query: {
          page: page,
          per_page: per_page || default_elements_per_page,
        },
      )
    )
  end
end

#organizations(page: 1, per_page: nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/universal-git-client/http/gitlab.rb', line 13

def organizations(page: 1, per_page: nil)
  with_response_validation! do
    self.class.get(
      '/groups',
      default_options.merge(
        query: {
          page: page,
          per_page: per_page || default_elements_per_page,
        },
      )
    )
  end
end

#repository(owner:, repo:) ⇒ Object



57
58
59
60
61
62
# File 'lib/universal-git-client/http/gitlab.rb', line 57

def repository(owner:, repo:)
  encoded_namespace = encode_namespace(owner, repo)
  with_response_validation! do
    self.class.get("/projects/#{encoded_namespace}", default_options)
  end
end

#setup_repo_webhook(owner:, repo:, webhook_url:, webhook_secret: nil) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/universal-git-client/http/gitlab.rb', line 97

def setup_repo_webhook(owner:, repo:, webhook_url:, webhook_secret: nil)
  encoded_namespace = encode_namespace(owner, repo)
  with_response_validation! do
    self.class.post(
      "/projects/#{encoded_namespace}/hooks",
      default_options.merge(
        body: {
          url: webhook_url,
          token: webhook_secret,
          push_events: true,
          enable_ssl_verification: true,
        }.compact.to_json,
      )
    )
  end
end

#userObject



7
8
9
10
11
# File 'lib/universal-git-client/http/gitlab.rb', line 7

def user
  with_response_validation! do
    self.class.get('/user', default_options)
  end
end

#user_repos(page: 1, per_page: nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/universal-git-client/http/gitlab.rb', line 27

def user_repos(page: 1, per_page: nil)
  current_user_id = self.user['id']
  with_response_validation! do
    self.class.get(
      "/users/#{current_user_id}/projects",
      default_options.merge(
        query: {
          page: page,
          per_page: per_page || default_elements_per_page,
        },
      )
    )
  end
end