New upstream version 4.8.0
Utkarsh Gupta
4 years ago
0 | # Number of days of inactivity before an issue becomes stale | |
1 | daysUntilStale: 90 | |
2 | # Number of days of inactivity before a stale issue is closed | |
3 | daysUntilClose: 10 | |
4 | # Issues with these labels will never be considered stale | |
5 | exemptLabels: | |
6 | - pinned | |
7 | - security | |
8 | - contribution welcome | |
9 | # Label to use when marking an issue as stale | |
10 | staleLabel: stale | |
11 | # Comment to post when marking an issue as stale. Set to `false` to disable | |
12 | markComment: > | |
13 | This issue has been automatically marked as stale because it has not had | |
14 | recent activity. It will be closed if no further activity occurs. Thank you | |
15 | for your contributions. | |
16 | # Comment to post when closing a stale issue. Set to `false` to disable | |
17 | closeComment: false |
0 | Layout/SpaceAroundEqualsInParameterDefault: | |
1 | Enabled: false | |
0 | --- | |
1 | inherit_from: .rubocop_todo.yml | |
2 | 2 | |
3 | Style/Alias: | |
4 | Enabled: false | |
5 | ||
6 | Style/PercentLiteralDelimiters: | |
7 | Enabled: false | |
8 | ||
9 | Layout/DotPosition: | |
10 | Enabled: false | |
3 | AllCops: | |
4 | TargetRubyVersion: 2.3 | |
11 | 5 | |
12 | 6 | Metrics/LineLength: |
13 | Max: 100 | |
7 | Max: 125 | |
14 | 8 | Exclude: |
15 | 9 | - 'lib/gitlab/client/*' |
16 | - 'spec/**/*' | |
17 | ||
18 | Style/ClassAndModuleChildren: | |
19 | Exclude: | |
20 | - 'lib/gitlab/client/*' | |
21 | ||
22 | Layout/SpaceInsideHashLiteralBraces: | |
23 | Exclude: | |
24 | - 'lib/gitlab/client/*' | |
25 | ||
26 | Style/StringLiterals: | |
27 | Exclude: | |
28 | 10 | - 'spec/**/*' |
29 | 11 | |
30 | 12 | Metrics/BlockLength: |
31 | 13 | Exclude: |
32 | 14 | - 'spec/**/*' |
15 | ||
16 | Style/Documentation: | |
17 | Enabled: false | |
18 | ||
19 | Style/ClassAndModuleChildren: | |
20 | Exclude: | |
21 | - 'lib/gitlab/*' | |
22 | - 'lib/gitlab/client/*' | |
23 | ||
24 | Style/FrozenStringLiteralComment: | |
25 | Exclude: | |
26 | - 'spec/gitlab/file_response_spec.rb' | |
27 | - 'spec/gitlab/help_spec.rb' | |
28 | ||
29 | Style/SpecialGlobalVars: | |
30 | Exclude: | |
31 | - 'gitlab.gemspec' |
0 | # This configuration was generated by | |
1 | # `rubocop --auto-gen-config` | |
2 | # on 2018-10-10 10:25:27 +0400 using RuboCop version 0.59.2. | |
3 | # The point is for the user to remove these configuration records | |
4 | # one by one as the offenses are removed from the code base. | |
5 | # Note that changes in the inspected code, or installation of new | |
6 | # versions of RuboCop, may require this file to be generated again. | |
7 | ||
8 | # Offense count: 1 | |
9 | Lint/UriEscapeUnescape: | |
10 | Exclude: | |
11 | - 'lib/gitlab/client.rb' | |
12 | ||
13 | # Offense count: 5 | |
14 | Metrics/AbcSize: | |
15 | Max: 34 | |
16 | ||
17 | # Offense count: 4 | |
18 | Metrics/CyclomaticComplexity: | |
19 | Max: 14 | |
20 | ||
21 | # Offense count: 10 | |
22 | # Configuration parameters: CountComments, ExcludedMethods. | |
23 | Metrics/MethodLength: | |
24 | Max: 34 | |
25 | ||
26 | # Offense count: 2 | |
27 | # Configuration parameters: CountComments. | |
28 | Metrics/ModuleLength: | |
29 | Max: 165 | |
30 | ||
31 | # Offense count: 2 | |
32 | # Configuration parameters: CountKeywordArgs. | |
33 | Metrics/ParameterLists: | |
34 | Max: 6 | |
35 | ||
36 | # Offense count: 1 | |
37 | Metrics/PerceivedComplexity: | |
38 | Max: 10 | |
39 | ||
40 | # Offense count: 1 | |
41 | # Cop supports --auto-correct. | |
42 | # Configuration parameters: AutoCorrect. | |
43 | Security/JSONLoad: | |
44 | Exclude: | |
45 | - 'lib/gitlab/request.rb' |
0 | --- | |
0 | 1 | language: ruby |
1 | 2 | rvm: |
2 | 3 | - 2.3 |
3 | 4 | - 2.4 |
4 | 5 | - 2.5 |
5 | before_install: gem update bundler | |
6 | - 2.6 | |
6 | 7 | |
7 | matrix: | |
8 | jobs: | |
8 | 9 | include: |
9 | - rvm: 2.4 | |
10 | env: "TRAVIS_CI_RUBOCOP=true" | |
11 | allow_failures: | |
12 | - env: "TRAVIS_CI_RUBOCOP=true" | |
10 | - stage: lint | |
11 | rvm: 2.3 | |
12 | script: bundle exec rake rubocop |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | source 'https://rubygems.org' |
1 | 3 | |
2 | 4 | # Specify your gem's dependencies in gitlab.gemspec |
0 | Copyright (c) 2012-2015 Nihad Abbasov <mail@narkoz.me> | |
0 | Copyright (c) 2012-2019 Nihad Abbasov <nihad@42na.in> | |
1 | 1 | All rights reserved. |
2 | 2 | |
3 | 3 | Redistribution and use in source and binary forms, with or without |
0 | 0 | # Gitlab |
1 | 1 | |
2 | 2 | [](https://travis-ci.org/NARKOZ/gitlab) |
3 | [](https://codeclimate.com/github/NARKOZ/gitlab) | |
4 | [](https://inch-ci.org/github/NARKOZ/gitlab) | |
3 | [](https://codeclimate.com/github/NARKOZ/gitlab) | |
4 | [](https://inch-ci.org/github/NARKOZ/gitlab) | |
5 | 5 | [](https://rubygems.org/gems/gitlab) |
6 | 6 | [](https://github.com/NARKOZ/gitlab/blob/master/LICENSE.txt) |
7 | 7 | |
8 | [website](http://narkoz.github.io/gitlab) | | |
9 | [documentation](http://rubydoc.info/gems/gitlab/frames) | | |
8 | [website](https://narkoz.github.io/gitlab) | | |
9 | [documentation](https://rubydoc.info/gems/gitlab/frames) | | |
10 | 10 | [gitlab-live](https://github.com/NARKOZ/gitlab-live) |
11 | 11 | |
12 | 12 | Gitlab is a Ruby wrapper and CLI for the [GitLab API](https://docs.gitlab.com/ce/api/README.html). |
13 | As of version `4.0.0` this gem only supports Ruby 2.0+ and Gitlab API v4. | |
13 | As of version `4.0.0` this gem only supports Ruby 2.0+ and GitLab API v4. | |
14 | 14 | |
15 | 15 | ## Installation |
16 | 16 | |
53 | 53 | |
54 | 54 | ```ruby |
55 | 55 | # set an API endpoint |
56 | Gitlab.endpoint = 'http://example.net/api/v4' | |
57 | # => "http://example.net/api/v4" | |
56 | Gitlab.endpoint = 'https://example.net/api/v4' | |
57 | # => "https://example.net/api/v4" | |
58 | 58 | |
59 | 59 | # set a user private token |
60 | 60 | Gitlab.private_token = 'qEsq1pt6HJPaNciie3MG' |
62 | 62 | |
63 | 63 | # configure a proxy server |
64 | 64 | Gitlab.http_proxy('proxyhost', 8888) |
65 | # proxy server w/ basic auth | |
65 | # proxy server with basic auth | |
66 | 66 | Gitlab.http_proxy('proxyhost', 8888, 'proxyuser', 'strongpasswordhere') |
67 | # set timeout for responses | |
68 | ENV['GITLAB_API_HTTPARTY_OPTIONS'] = '{read_timeout: 60}' | |
67 | 69 | |
68 | 70 | # list projects |
69 | 71 | Gitlab.projects(per_page: 5) |
107 | 109 | projects.auto_paginate |
108 | 110 | ``` |
109 | 111 | |
110 | For more information, refer to [documentation](http://rubydoc.info/gems/gitlab/frames). | |
112 | For more information, refer to [documentation](https://rubydoc.info/gems/gitlab/frames). | |
111 | 113 | |
112 | 114 | ## CLI |
113 | 115 | |
114 | It is possible to use this gem as a command line interface to gitlab. In order to make that work you need to set a few environment variables: | |
116 | It is possible to use this gem as a command line interface to GitLab. In order to make that work you need to set a few environment variables: | |
115 | 117 | ```sh |
116 | 118 | export GITLAB_API_ENDPOINT=https://gitlab.yourcompany.com/api/v4 |
117 | 119 | export GITLAB_API_PRIVATE_TOKEN=<your private token from /profile/account> |
123 | 125 | |
124 | 126 | Usage: |
125 | 127 | |
126 | When you want to know which CLI commands are supported, take a look at the client [commands implemented in this gem](http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client). Any of those methods can be called as a command by passing the parameters of the commands as parameters of the CLI. | |
128 | When you want to know which CLI commands are supported, take a look at the client [commands implemented in this gem](https://www.rubydoc.info/gems/gitlab/4.5.0/Gitlab/Client). Any of those methods can be called as a command by passing the parameters of the commands as parameters of the CLI. | |
127 | 129 | |
128 | 130 | Usage examples: |
129 | 131 | |
130 | 132 | ```sh |
131 | 133 | # list users |
132 | # see: http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client/Users#users-instance_method | |
134 | # see: https://www.rubydoc.info/gems/gitlab/4.5.0/Gitlab/Client/Users#users-instance_method | |
133 | 135 | gitlab users |
134 | 136 | |
135 | 137 | # get current user |
136 | # see: http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client/Users#user-instance_method | |
138 | # see: https://www.rubydoc.info/gems/gitlab/4.5.0/Gitlab/Client/Users#user-instance_method | |
137 | 139 | gitlab user |
138 | 140 | |
139 | 141 | # get a user |
140 | # see: http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client/Users#user-instance_method | |
142 | # see: https://www.rubydoc.info/gems/gitlab/4.5.0/Gitlab/Client/Users#user-instance_method | |
141 | 143 | gitlab user 2 |
142 | 144 | |
143 | 145 | # filter output |
149 | 151 | gitlab user 2 --json |
150 | 152 | |
151 | 153 | # passing options hash to a command (use YAML) |
152 | # see: http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client/MergeRequests#create_merge_request-instance_method | |
154 | # see: https://www.rubydoc.info/gems/gitlab/4.5.0/Gitlab/Client/MergeRequests#create_merge_request-instance_method | |
153 | 155 | gitlab create_merge_request 4 "New merge request" "{source_branch: 'new_branch', target_branch: 'master', assignee_id: 42}" |
154 | 156 | |
155 | 157 | ``` |
176 | 178 | ``` |
177 | 179 | |
178 | 180 | Web version is available at https://gitlab-live.herokuapp.com |
179 | For more information, refer to [website](http://narkoz.github.io/gitlab). | |
181 | For more information, refer to [website](https://narkoz.github.io/gitlab). | |
180 | 182 | |
181 | 183 | ## Development |
182 | 184 | |
183 | ### With a dockerized Gitlab instance | |
184 | ||
185 | ```shell | |
186 | docker-compose up -d gitlab # Will start the gitlab instance in the background (approx. 3 minutes) | |
187 | ``` | |
188 | ||
189 | After a while, your Gitlab instance will be accessible on http://localhost:3000. | |
185 | ### With a dockerized GitLab instance | |
186 | ||
187 | ```shell | |
188 | docker-compose up -d gitlab # Will start the GitLab instance in the background (approx. 3 minutes) | |
189 | ``` | |
190 | ||
191 | After a while, your GitLab instance will be accessible on http://localhost:3000. | |
190 | 192 | |
191 | 193 | Once you have set your new root password, you can login with the root user. |
192 | 194 | |
205 | 207 | => [#<Gitlab::ObjectifiedHash:47231290771040 {hash: {"id"=>1, "name"=>"Administrator", "username"=>"root", ...] |
206 | 208 | ``` |
207 | 209 | |
208 | To launch the specs, | |
210 | To launch the specs: | |
209 | 211 | |
210 | 212 | ```shell |
211 | 213 | docker-compose run app rake spec |
212 | 214 | ``` |
213 | 215 | |
214 | #### Want to use Gitlab Enterprise? | |
216 | #### Want to use GitLab Enterprise? | |
215 | 217 | |
216 | 218 | Just change the image from `gitlab/gitlab-ce:latest` to `gitlab/gitlab-ee:latest` in the `docker-compose.yml` file. |
217 | 219 | |
218 | ### With an external Gitlab instance | |
220 | ### With an external GitLab instance | |
219 | 221 | |
220 | 222 | First, set the variables to the correct values in the `docker.env` file. |
221 | 223 |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | require 'bundler/gem_tasks' |
1 | 3 | |
2 | 4 | require 'rspec/core/rake_task' |
9 | 11 | task.options = ['-D', '--parallel'] |
10 | 12 | end |
11 | 13 | |
12 | if ENV['TRAVIS_CI_RUBOCOP'] | |
13 | task default: :rubocop | |
14 | else | |
15 | task default: :spec | |
16 | end | |
14 | task default: :spec |
0 | 0 | #!/usr/bin/env ruby |
1 | # frozen_string_literal: true | |
1 | 2 | |
2 | 3 | # ENV['GITLAB_API_ENDPOINT'] = '' |
3 | 4 | # ENV['GITLAB_API_PRIVATE_TOKEN'] = '' |
0 | 0 | #!/usr/bin/env ruby |
1 | # frozen_string_literal: true | |
1 | 2 | |
2 | $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) | |
3 | $LOAD_PATH.unshift File.expand_path('../lib', __dir__) | |
4 | ||
5 | # Exit cleanly from an early interrupt | |
6 | Signal.trap('INT') { exit 1 } | |
3 | 7 | |
4 | 8 | require 'gitlab/cli' |
5 | 9 |
0 | lib = File.expand_path('../lib', __FILE__) | |
0 | # frozen_string_literal: true | |
1 | ||
2 | lib = File.expand_path('lib', __dir__) | |
1 | 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) |
2 | 4 | require 'gitlab/version' |
3 | 5 | |
10 | 12 | gem.summary = 'A Ruby wrapper and CLI for the GitLab API' |
11 | 13 | gem.homepage = 'https://github.com/narkoz/gitlab' |
12 | 14 | |
13 | gem.files = `git ls-files`.split($/). | |
14 | reject { |f| f[/^spec/] } - | |
15 | %w[Dockerfile docker-compose.yml docker.env .travis.yml .rubocop.yml .dockerignore] | |
15 | gem.files = `git ls-files`.split($/) | |
16 | .grep_v(/^spec/) - | |
17 | %w[Dockerfile docker-compose.yml docker.env .travis.yml | |
18 | .rubocop.yml .dockerignore] | |
16 | 19 | gem.bindir = 'exe' |
17 | 20 | gem.executables = gem.files.grep(%r{^exe/}) { |f| File.basename(f) } |
18 | 21 | gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) |
19 | 22 | gem.require_paths = ['lib'] |
20 | 23 | gem.license = 'BSD' |
21 | 24 | |
22 | gem.required_ruby_version = '>= 2.0.0' | |
25 | gem.required_ruby_version = '>= 2.3' | |
23 | 26 | |
24 | 27 | gem.add_runtime_dependency 'httparty', '>= 0.14.0' |
25 | 28 | gem.add_runtime_dependency 'terminal-table', '>= 1.5.1' |
27 | 30 | gem.add_development_dependency 'pry' |
28 | 31 | gem.add_development_dependency 'rake' |
29 | 32 | gem.add_development_dependency 'rspec' |
33 | gem.add_development_dependency 'rubocop' | |
30 | 34 | gem.add_development_dependency 'webmock' |
31 | gem.add_development_dependency 'rubocop' | |
32 | 35 | end |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | module Gitlab |
1 | 3 | # @private |
2 | 4 | class API < Request |
3 | 5 | # @private |
4 | 6 | attr_accessor(*Configuration::VALID_OPTIONS_KEYS) |
5 | 7 | # @private |
6 | alias_method :auth_token=, :private_token= | |
8 | alias auth_token= private_token= | |
7 | 9 | |
8 | 10 | # Creates a new API. |
9 | 11 | # @raise [Error:MissingCredentials] |
10 | def initialize(options={}) | |
12 | def initialize(options = {}) | |
11 | 13 | options = Gitlab.options.merge(options) |
12 | 14 | (Configuration::VALID_OPTIONS_KEYS + [:auth_token]).each do |key| |
13 | 15 | send("#{key}=", options[key]) if options[key] |
14 | 16 | end |
15 | request_defaults(@sudo) | |
17 | request_defaults(sudo) | |
16 | 18 | self.class.headers 'User-Agent' => user_agent |
17 | 19 | end |
18 | 20 | end |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | require 'gitlab' |
1 | 3 | require 'terminal-table/import' |
2 | 4 | require_relative 'cli_helpers' |
16 | 18 | # |
17 | 19 | # @param [Array] args The command and it's optional arguments. |
18 | 20 | def self.start(args) |
19 | command = args.shift.strip rescue 'help' | |
21 | command = begin | |
22 | args.shift.strip | |
23 | rescue StandardError | |
24 | 'help' | |
25 | end | |
20 | 26 | run(command, args) |
21 | 27 | end |
22 | 28 | |
29 | 35 | # @param [String] cmd The name of a command. |
30 | 36 | # @param [Array] args The optional arguments for a command. |
31 | 37 | # @return [nil] |
32 | def self.run(cmd, args=[]) | |
38 | def self.run(cmd, args = []) | |
33 | 39 | case cmd |
34 | 40 | when 'help' |
35 | 41 | puts help(args.shift) { |out| out.gsub!(/Gitlab\./, 'gitlab ') } |
36 | 42 | when 'info' |
37 | endpoint = Gitlab.endpoint ? Gitlab.endpoint : 'not set' | |
38 | private_token = Gitlab.private_token ? Gitlab.private_token : 'not set' | |
43 | endpoint = Gitlab.endpoint || 'not set' | |
44 | private_token = Gitlab.private_token || 'not set' | |
39 | 45 | puts "Gitlab endpoint is #{endpoint}" |
40 | 46 | puts "Gitlab private token is #{private_token}" |
41 | 47 | puts "Ruby Version is #{RUBY_VERSION}" |
59 | 65 | |
60 | 66 | begin |
61 | 67 | command_args.map! { |arg| symbolize_keys(yaml_load(arg)) } |
62 | rescue => e | |
68 | rescue StandardError => e | |
63 | 69 | puts e.message |
64 | 70 | exit 1 |
65 | 71 | end |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | require 'yaml' |
1 | 3 | require 'json' |
2 | 4 | require 'base64' |
4 | 6 | class Gitlab::CLI |
5 | 7 | # Defines methods related to CLI output and formatting. |
6 | 8 | module Helpers |
7 | extend self | |
9 | module_function | |
8 | 10 | |
9 | 11 | # Returns actions available to CLI & Shell |
10 | 12 | # |
70 | 72 | |
71 | 73 | puts 'Are you sure? (y/n)' |
72 | 74 | |
73 | if %w(y yes).include?($stdin.gets.to_s.strip.downcase) | |
75 | if %w[y yes].include?($stdin.gets.to_s.strip.downcase) | |
74 | 76 | puts 'Proceeding..' |
75 | 77 | else |
76 | 78 | puts 'Command aborted.' |
81 | 83 | # Gets defined help for a specific command/action. |
82 | 84 | # |
83 | 85 | # @return [String] |
84 | def help(cmd=nil, &block) | |
86 | def help(cmd = nil, &block) | |
85 | 87 | if cmd.nil? || Gitlab::Help.help_map.key?(cmd) |
86 | 88 | Gitlab::Help.actions_table(cmd) |
87 | 89 | else |
89 | 91 | end |
90 | 92 | end |
91 | 93 | |
92 | # Outputs a nicely formatted table or error msg. | |
94 | # Outputs a nicely formatted table or error message. | |
93 | 95 | def output_table(cmd, args, data) |
94 | 96 | case data |
95 | 97 | when Gitlab::ObjectifiedHash, Gitlab::FileResponse |
96 | 98 | puts record_table([data], cmd, args) |
97 | 99 | when Gitlab::PaginatedResponse |
98 | 100 | puts record_table(data, cmd, args) |
99 | else # probably just an error msg | |
101 | else # probably just an error message | |
100 | 102 | puts data |
101 | 103 | end |
102 | 104 | end |
158 | 160 | # @param [Array] args Options passed to the API call |
159 | 161 | # @param [bool] single_value If set to true, a single result should be returned |
160 | 162 | # @return [Hash] Result hash |
161 | def record_hash(data, cmd, args, single_value=false) | |
163 | def record_hash(data, cmd, args, single_value = false) | |
162 | 164 | if data.empty? |
163 | 165 | result = nil |
164 | 166 | else |
168 | 170 | row = {} |
169 | 171 | |
170 | 172 | keys.each do |key| |
171 | case hash[key] | |
172 | when Hash | |
173 | row[key] = 'Hash' | |
174 | when StringIO | |
175 | row[key] = Base64.encode64(hash[key].read) | |
176 | when nil | |
177 | row[key] = nil | |
178 | else | |
179 | row[key] = hash[key] | |
180 | end | |
173 | row[key] = case hash[key] | |
174 | when Hash | |
175 | 'Hash' | |
176 | when StringIO | |
177 | Base64.encode64(hash[key].read) | |
178 | when nil | |
179 | nil | |
180 | else | |
181 | hash[key] | |
182 | end | |
181 | 183 | end |
182 | 184 | |
183 | 185 | result.push row |
184 | 186 | end |
185 | result = result[0] if single_value && result.count > 0 | |
187 | result = result[0] if single_value && result.count.positive? | |
186 | 188 | end |
187 | 189 | |
188 | 190 | { |
201 | 203 | end |
202 | 204 | |
203 | 205 | # Helper function to call Gitlab commands with args. |
204 | def gitlab_helper(cmd, args=[]) | |
206 | def gitlab_helper(cmd, args = []) | |
205 | 207 | begin |
206 | 208 | data = args.any? ? Gitlab.send(cmd, *args) : Gitlab.send(cmd) |
207 | rescue => e | |
209 | rescue StandardError => e | |
208 | 210 | puts e.message |
209 | 211 | yield if block_given? |
210 | 212 | end |
216 | 218 | # @return [Hash] |
217 | 219 | def symbolize_keys(hash) |
218 | 220 | if hash.is_a?(Hash) |
219 | hash = hash.each_with_object({}) do |(key, value), newhash| | |
221 | hash = hash.each_with_object({}) do |(key, value), new_hash| | |
220 | 222 | begin |
221 | newhash[key.to_sym] = symbolize_keys(value) | |
223 | new_hash[key.to_sym] = symbolize_keys(value) | |
222 | 224 | rescue NoMethodError |
223 | 225 | raise "Error: cannot convert hash key to symbol: #{key}" |
224 | 226 | end |
228 | 230 | hash |
229 | 231 | end |
230 | 232 | |
233 | # Check if arg is a color in 6-digit hex notation with leading '#' sign | |
234 | def hex_color?(arg) | |
235 | pattern = /\A#\h{6}\Z/ | |
236 | ||
237 | pattern.match(arg) | |
238 | end | |
239 | ||
231 | 240 | # YAML::load on a single argument |
232 | 241 | def yaml_load(arg) |
233 | YAML.safe_load(arg) | |
242 | hex_color?(arg) ? arg : YAML.safe_load(arg) | |
234 | 243 | rescue Psych::SyntaxError |
235 | 244 | raise "Error: Argument is not valid YAML syntax: #{arg}" |
236 | 245 | end |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to Award Emojis. |
2 | 4 | # @see https://docs.gitlab.com/ce/api/access_requests.html |
11 | 13 | def project_access_requests(project) |
12 | 14 | get("/projects/#{url_encode project}/access_requests") |
13 | 15 | end |
16 | ||
14 | 17 | # Gets a list of access requests for a group viewable by the authenticated user. |
15 | 18 | # |
16 | 19 | # @example |
21 | 24 | def group_access_requests(group) |
22 | 25 | get("/groups/#{url_encode group}/access_requests") |
23 | 26 | end |
27 | ||
24 | 28 | # Requests access for the authenticated user to a project. |
25 | 29 | # |
26 | 30 | # @example |
31 | 35 | def request_project_access(project) |
32 | 36 | post("/projects/#{url_encode project}/access_requests") |
33 | 37 | end |
38 | ||
34 | 39 | # Requests access for the authenticated user to a group. |
35 | 40 | # |
36 | 41 | # @example |
41 | 46 | def request_group_access(group) |
42 | 47 | post("/groups/#{url_encode group}/access_requests") |
43 | 48 | end |
49 | ||
44 | 50 | # Approves a project access request for the given user. |
45 | 51 | # |
46 | 52 | # @example |
54 | 60 | def approve_project_access_request(project, user_id, options = {}) |
55 | 61 | put("/projects/#{url_encode project}/access_requests/#{user_id}/approve", body: options) |
56 | 62 | end |
63 | ||
57 | 64 | # Approves a group access request for the given user. |
58 | 65 | # |
59 | 66 | # @example |
67 | 74 | def approve_group_access_request(group, user_id, options = {}) |
68 | 75 | put("/groups/#{url_encode group}/access_requests/#{user_id}/approve", body: options) |
69 | 76 | end |
77 | ||
70 | 78 | # Denies a project access request for the given user. |
71 | 79 | # |
72 | 80 | # @example |
78 | 86 | def deny_project_access_request(project, user_id) |
79 | 87 | delete("/projects/#{url_encode project}/access_requests/#{user_id}") |
80 | 88 | end |
89 | ||
81 | 90 | # Denies a group access request for the given user. |
82 | 91 | # |
83 | 92 | # @example |
90 | 99 | delete("/groups/#{url_encode group}/access_requests/#{user_id}") |
91 | 100 | end |
92 | 101 | end |
93 | end⏎ | |
102 | end |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to Award Emojis. |
2 | 4 | # @see https://docs.gitlab.com/ce/api/award_emoji.html |
78 | 80 | # @param [String] emoji_name The name of the emoji, without colons. |
79 | 81 | # @return [Gitlab::ObjectifiedHash] |
80 | 82 | def create_award_emoji(project, awardable_id, awardable_type, emoji_name) |
81 | post("/projects/#{url_encode project}/#{awardable_type}s/#{awardable_id}/award_emoji", body: {name: emoji_name}) | |
83 | post("/projects/#{url_encode project}/#{awardable_type}s/#{awardable_id}/award_emoji", body: { name: emoji_name }) | |
82 | 84 | end |
83 | 85 | |
84 | 86 | # Awards a new emoji to a note on an awardable(issue, merge request or snippet) |
95 | 97 | # @param [String] emoji_name The name of the emoji, without colons. |
96 | 98 | # @return [Gitlab::ObjectifiedHash] |
97 | 99 | def create_note_award_emoji(project, awardable_id, awardable_type, note_id, emoji_name) |
98 | post("/projects/#{url_encode project}/#{awardable_type}s/#{awardable_id}/notes/#{note_id}/award_emoji", body: {name: emoji_name}) | |
100 | post("/projects/#{url_encode project}/#{awardable_type}s/#{awardable_id}/notes/#{note_id}/award_emoji", body: { name: emoji_name }) | |
99 | 101 | end |
100 | 102 | |
101 | 103 | # Deletes a single award emoji from an awardable(issue, merge request or snippet) |
131 | 133 | delete("/projects/#{url_encode project}/#{awardable_type}s/#{awardable_id}/notes/#{note_id}/award_emoji/#{award_id}") |
132 | 134 | end |
133 | 135 | end |
134 | end⏎ | |
136 | end |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to issue boards. |
2 | 4 | # @see https://docs.gitlab.com/ce/api/boards.html |
12 | 14 | # @option options [Integer] :page The page number. |
13 | 15 | # @option options [Integer] :per_page The number of results per page. |
14 | 16 | # @return [Array<Gitlab::ObjectifiedHash>] |
15 | def boards(project, options={}) | |
17 | def boards(project, options = {}) | |
16 | 18 | get("/projects/#{url_encode project}/boards", query: options) |
17 | 19 | end |
18 | 20 | |
27 | 29 | def board_lists(project, id) |
28 | 30 | get("/projects/#{url_encode project}/boards/#{id}/lists") |
29 | 31 | end |
32 | ||
30 | 33 | # |
31 | 34 | # Gets a single board list |
32 | 35 | # |
52 | 55 | # @param [Integer] label_id The ID of a label. |
53 | 56 | # @return [Gitlab::ObjectifiedHash] Information about created list. |
54 | 57 | def create_board_list(project, board_id, label_id) |
55 | post("/projects/#{url_encode project}/boards/#{board_id}/lists", body: {label_id: label_id}) | |
58 | post("/projects/#{url_encode project}/boards/#{board_id}/lists", body: { label_id: label_id }) | |
56 | 59 | end |
57 | 60 | |
58 | 61 | # Updates a board list. |
66 | 69 | # @param [Integer] id The ID of a list. |
67 | 70 | # @return [Gitlab::ObjectifiedHash] Information about updated board list. |
68 | 71 | def edit_board_list(project, board_id, id, position) |
69 | put("/projects/#{url_encode project}/boards/#{board_id}/lists/#{id}", body: {position: position}) | |
72 | put("/projects/#{url_encode project}/boards/#{board_id}/lists/#{id}", body: { position: position }) | |
70 | 73 | end |
71 | 74 | |
72 | 75 | # Deletes a board list. |
84 | 87 | end |
85 | 88 | end |
86 | 89 | end |
87 |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to repositories. |
2 | 4 | # @see https://docs.gitlab.com/ce/api/branches.html |
11 | 13 | # @option options [Integer] :page The page number. |
12 | 14 | # @option options [Integer] :per_page The number of results per page. |
13 | 15 | # @return [Array<Gitlab::ObjectifiedHash>] |
14 | def branches(project, options={}) | |
16 | def branches(project, options = {}) | |
15 | 17 | get("/projects/#{url_encode project}/repository/branches", query: options) |
16 | 18 | end |
17 | alias_method :repo_branches, :branches | |
19 | alias repo_branches branches | |
18 | 20 | |
19 | 21 | # Gets information about a repository branch. |
20 | 22 | # |
28 | 30 | def branch(project, branch) |
29 | 31 | get("/projects/#{url_encode project}/repository/branches/#{url_encode branch}") |
30 | 32 | end |
31 | alias_method :repo_branch, :branch | |
33 | alias repo_branch branch | |
32 | 34 | |
33 | 35 | # Protects a repository branch. |
34 | 36 | # |
46 | 48 | # @option options [Boolean] :developers_can_merge True to allow developers to merge into the branch (default = false) |
47 | 49 | # @return [Gitlab::ObjectifiedHash] Details about the branch |
48 | 50 | def protect_branch(project, branch, options = {}) |
49 | post("/projects/#{url_encode project}/protected_branches", body: {name: branch}.merge(options)) | |
51 | post("/projects/#{url_encode project}/protected_branches", body: { name: branch }.merge(options)) | |
50 | 52 | end |
51 | alias_method :repo_protect_branch, :protect_branch | |
53 | alias repo_protect_branch protect_branch | |
52 | 54 | |
53 | 55 | # Unprotects a repository branch. |
54 | 56 | # |
62 | 64 | def unprotect_branch(project, branch) |
63 | 65 | delete("/projects/#{url_encode project}/protected_branches/#{url_encode branch}") |
64 | 66 | end |
65 | alias_method :repo_unprotect_branch, :unprotect_branch | |
67 | alias repo_unprotect_branch unprotect_branch | |
66 | 68 | |
67 | 69 | # Creates a repository branch. Requires Gitlab >= 6.8.x |
68 | 70 | # |
77 | 79 | def create_branch(project, branch, ref) |
78 | 80 | post("/projects/#{url_encode project}/repository/branches", query: { branch: branch, ref: ref }) |
79 | 81 | end |
80 | alias_method :repo_create_branch, :create_branch | |
82 | alias repo_create_branch create_branch | |
81 | 83 | |
82 | 84 | # Deletes a repository branch. Requires Gitlab >= 6.8.x |
83 | 85 | # |
90 | 92 | def delete_branch(project, branch) |
91 | 93 | delete("/projects/#{url_encode project}/repository/branches/#{url_encode branch}") |
92 | 94 | end |
93 | alias_method :repo_delete_branch, :delete_branch | |
95 | alias repo_delete_branch delete_branch | |
96 | ||
97 | # Delete all branches that are merged into the project default branch. Protected branches will not be deleted as part of this operation. | |
98 | # | |
99 | # @example | |
100 | # Gitlab.delete_merged_branches(3) | |
101 | # | |
102 | # @param [Integer, String] project The ID or name of a project. | |
103 | # @return [nil] This API call returns an empty response body. | |
104 | def delete_merged_branches(project) | |
105 | delete("/projects/#{url_encode project}/repository/merged_branches") | |
106 | end | |
107 | alias repo_delete_merged_branches delete_merged_branches | |
108 | ||
109 | # Gets a list of protected branches from a project. | |
110 | # | |
111 | # @example | |
112 | # Gitlab.protected_branches(42) | |
113 | # | |
114 | # @param [Integer, String] project The ID or name of a project. | |
115 | # @return [Array<Gitlab::ObjectifiedHash>] | |
116 | def protected_branches(project) | |
117 | get("/projects/#{url_encode project}/protected_branches") | |
118 | end | |
119 | alias repo_protected_branches protected_branches | |
120 | ||
121 | # Gets a single protected branch or wildcard protected branch | |
122 | # | |
123 | # @example | |
124 | # Gitlab.protected_branch(3, 'api') | |
125 | # | |
126 | # @param [Integer, String] project The ID or name of a project. | |
127 | # @param [String] name The name of the branch or wildcard | |
128 | # @return [Gitlab::ObjectifiedHash] | |
129 | def protected_branch(project, branch) | |
130 | get("/projects/#{url_encode project}/protected_branches/#{url_encode branch}") | |
131 | end | |
132 | alias repo_protected_branch protected_branch | |
94 | 133 | end |
95 | 134 | end |
0 | # frozen_string_literal: true | |
1 | ||
2 | class Gitlab::Client | |
3 | # Defines methods related to broadcast messages (only accessible to administrators). | |
4 | # @see https://docs.gitlab.com/ce/api/broadcast_messages.html | |
5 | module BroadcastMessages | |
6 | # Get all broadcast messages | |
7 | # | |
8 | # @example | |
9 | # Gitlab.broadcast_messages | |
10 | # | |
11 | # @return [Array<Gitlab::ObjectifiedHash>] | |
12 | def broadcast_messages | |
13 | get('/broadcast_messages') | |
14 | end | |
15 | ||
16 | # Get a specific broadcast message | |
17 | # | |
18 | # @example | |
19 | # Gitlab.broadcast_message(3) | |
20 | # | |
21 | # @param [Integer] id The ID of broadcast message | |
22 | # @return [Gitlab::ObjectifiedHash] | |
23 | def broadcast_message(id) | |
24 | get("/broadcast_messages/#{id}") | |
25 | end | |
26 | ||
27 | # Create a broadcast message. | |
28 | # | |
29 | # @example | |
30 | # Gitlab.create_broadcast_message('Mayday') | |
31 | # Gitlab.create_broadcast_message('Mayday', {starts_at: Time.zone.now, ends_at: Time.zone.now + 30.minutes, color: '#cecece', font: '#FFFFFF'}) | |
32 | # | |
33 | # @param [String] message Message to display | |
34 | # @param [Hash] options A customizable set of options. | |
35 | # @option options [DateTime] :starts_at(optional) Starting time (defaults to current time) | |
36 | # @option options [DateTime] :ends_at(optional) Ending time (defaults to one hour from current time) | |
37 | # @option options [String] :color(optional) Background color hex code | |
38 | # @option options [String] :font(optional) Foreground color hex code | |
39 | # @return [Gitlab::ObjectifiedHash] Information about created broadcast message. | |
40 | def create_broadcast_message(message, options = {}) | |
41 | body = { message: message }.merge(options) | |
42 | post('/broadcast_messages', body: body) | |
43 | end | |
44 | ||
45 | # Update a broadcast message | |
46 | # | |
47 | # @example | |
48 | # Gitlab.edit_broadcast_message(6, { message: 'No Mayday' }) | |
49 | # Gitlab.edit_broadcast_message(6, { font: '#FEFEFE' }) | |
50 | # | |
51 | # @param [Integer] id The ID of a broadcast message | |
52 | # @param [Hash] options A customizable set of options. | |
53 | # @option options [String] :message(optional) Message to display | |
54 | # @option options [DateTime] :starts_at(optional) Starting time (defaults to current time) | |
55 | # @option options [DateTime] :ends_at(optional) Ending time (defaults to one hour from current time) | |
56 | # @option options [String] :color(optional) Background color hex code | |
57 | # @option options [String] :font(optional) Foreground color hex code | |
58 | # @return [Gitlab::ObjectifiedHash] Information about updated broadcast message. | |
59 | def edit_broadcast_message(id, options = {}) | |
60 | put("/broadcast_messages/#{id}", body: options) | |
61 | end | |
62 | ||
63 | # Delete a broadcast message. | |
64 | # | |
65 | # @example | |
66 | # Gitlab.delete_broadcast_message(3) | |
67 | # | |
68 | # @param [Integer] id The ID of a broadcast message. | |
69 | # @return [nil] This API call returns an empty response body. | |
70 | def delete_broadcast_message(id) | |
71 | delete("/broadcast_messages/#{id}") | |
72 | end | |
73 | end | |
74 | end |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to builds. |
2 | 4 | # @see https://docs.gitlab.com/ce/api/build_variables.html |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to builds. |
2 | 4 | # @see https://docs.gitlab.com/ce/api/builds.html |
13 | 15 | # @option options [Integer] :per_page The number of results per page. |
14 | 16 | # @param [Integer, String] project The ID or name of a project. |
15 | 17 | # @return [Array<Gitlab::ObjectifiedHash>] |
16 | def builds(project, options={}) | |
18 | def builds(project, options = {}) | |
17 | 19 | get("/projects/#{url_encode project}/builds", query: options) |
18 | 20 | end |
19 | 21 | |
39 | 41 | # @return [Gitlab::FileResponse] |
40 | 42 | def build_artifacts(project, id) |
41 | 43 | get("/projects/#{url_encode project}/builds/#{id}/artifacts", |
42 | format: nil, | |
43 | headers: { Accept: 'application/octet-stream' }, | |
44 | parser: proc { |body, _| | |
45 | if body.encoding == Encoding::ASCII_8BIT # binary response | |
46 | ::Gitlab::FileResponse.new StringIO.new(body, 'rb+') | |
47 | else # error with json response | |
48 | ::Gitlab::Request.parse(body) | |
49 | end | |
50 | }) | |
44 | format: nil, | |
45 | headers: { Accept: 'application/octet-stream' }, | |
46 | parser: proc { |body, _| | |
47 | if body.encoding == Encoding::ASCII_8BIT # binary response | |
48 | ::Gitlab::FileResponse.new StringIO.new(body, 'rb+') | |
49 | else # error with json response | |
50 | ::Gitlab::Request.parse(body) | |
51 | end | |
52 | }) | |
51 | 53 | end |
52 | 54 | |
53 | 55 | # Gets a list of builds for specific commit in a project. |
62 | 64 | # @option options [Integer] :page The page number. |
63 | 65 | # @option options [Integer] :per_page The number of results per page. |
64 | 66 | # @return [Array<Gitlab::ObjectifiedHash>] The list of builds. |
65 | def commit_builds(project, sha, options={}) | |
67 | def commit_builds(project, sha, options = {}) | |
66 | 68 | get("/projects/#{url_encode project}/repository/commits/#{sha}/builds", query: options) |
67 | 69 | end |
68 | 70 |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to repository commits. |
2 | 4 | # @see https://docs.gitlab.com/ce/api/commits.html |
13 | 15 | # @option options [Integer] :page The page number. |
14 | 16 | # @option options [Integer] :per_page The number of results per page. |
15 | 17 | # @return [Array<Gitlab::ObjectifiedHash>] |
16 | def commits(project, options={}) | |
18 | def commits(project, options = {}) | |
17 | 19 | get("/projects/#{url_encode project}/repository/commits", query: options) |
18 | 20 | end |
19 | alias_method :repo_commits, :commits | |
21 | alias repo_commits commits | |
20 | 22 | |
21 | 23 | # Gets a specific commit identified by the commit hash or name of a branch or tag. |
22 | 24 | # |
30 | 32 | def commit(project, sha) |
31 | 33 | get("/projects/#{url_encode project}/repository/commits/#{sha}") |
32 | 34 | end |
33 | alias_method :repo_commit, :commit | |
35 | alias repo_commit commit | |
36 | ||
37 | # Cherry picks a commit to a given branch. | |
38 | # | |
39 | # @example | |
40 | # Gitlab.cherry_pick_commit(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6', 'master') | |
41 | # | |
42 | # @param [Integer, String] project The ID or name of a project. | |
43 | # @param [String] sha The commit hash or name of a repository branch or tag | |
44 | # @param [String] branch The name of the branch | |
45 | # @return [Gitlab::ObjectifiedHash] | |
46 | def cherry_pick_commit(project, sha, branch) | |
47 | post("/projects/#{url_encode project}/repository/commits/#{sha}/cherry_pick", body: { branch: branch }) | |
48 | end | |
34 | 49 | |
35 | 50 | # Get the diff of a commit in a project. |
36 | 51 | # |
44 | 59 | def commit_diff(project, sha) |
45 | 60 | get("/projects/#{url_encode project}/repository/commits/#{sha}/diff") |
46 | 61 | end |
47 | alias_method :repo_commit_diff, :commit_diff | |
62 | alias repo_commit_diff commit_diff | |
48 | 63 | |
49 | 64 | # Gets a list of comments for a commit. |
50 | 65 | # |
56 | 71 | # @option options [Integer] :page The page number. |
57 | 72 | # @option options [Integer] :per_page The number of results per page. |
58 | 73 | # @return [Array<Gitlab::ObjectifiedHash>] |
59 | def commit_comments(project, commit, options={}) | |
74 | def commit_comments(project, commit, options = {}) | |
60 | 75 | get("/projects/#{url_encode project}/repository/commits/#{commit}/comments", query: options) |
61 | 76 | end |
62 | alias_method :repo_commit_comments, :commit_comments | |
77 | alias repo_commit_comments commit_comments | |
63 | 78 | |
64 | 79 | # Creates a new comment for a commit. |
65 | 80 | # |
74 | 89 | # @option options [Integer] :line The line number. |
75 | 90 | # @option options [String] :line_type The line type (new or old). |
76 | 91 | # @return [Gitlab::ObjectifiedHash] Information about created comment. |
77 | def create_commit_comment(project, commit, note, options={}) | |
92 | def create_commit_comment(project, commit, note, options = {}) | |
78 | 93 | post("/projects/#{url_encode project}/repository/commits/#{commit}/comments", body: options.merge(note: note)) |
79 | 94 | end |
80 | alias_method :repo_create_commit_comment, :create_commit_comment | |
95 | alias repo_create_commit_comment create_commit_comment | |
81 | 96 | |
82 | 97 | # Get the status of a commit |
83 | 98 | # |
93 | 108 | # @option options [String] :stage Filter by stage |
94 | 109 | # @option options [String] :name Filter by status name, eg. jenkins |
95 | 110 | # @option options [Boolean] :all The flag to return all statuses, not only latest ones |
96 | def commit_status(project, sha, options={}) | |
111 | def commit_status(project, sha, options = {}) | |
97 | 112 | get("/projects/#{url_encode project}/repository/commits/#{sha}/statuses", query: options) |
98 | 113 | end |
99 | alias_method :repo_commit_status, :commit_status | |
114 | alias repo_commit_status commit_status | |
100 | 115 | |
101 | 116 | # Adds or updates a status of a commit. |
102 | 117 | # |
112 | 127 | # @option options [String] :ref The ref (branch or tag) to which the status refers |
113 | 128 | # @option options [String] :name Filter by status name, eg. jenkins |
114 | 129 | # @option options [String] :target_url The target URL to associate with this status |
115 | def update_commit_status(project, sha, state, options={}) | |
130 | def update_commit_status(project, sha, state, options = {}) | |
116 | 131 | post("/projects/#{url_encode project}/statuses/#{sha}", query: options.merge(state: state)) |
117 | 132 | end |
118 | alias_method :repo_update_commit_status, :update_commit_status | |
133 | alias repo_update_commit_status update_commit_status | |
119 | 134 | |
120 | 135 | # Creates a single commit with one or more changes |
121 | 136 | # |
133 | 148 | # @option options [String] :author_email the email address of the author |
134 | 149 | # @option options [String] :author_name the name of the author |
135 | 150 | # @return [Gitlab::ObjectifiedHash] hash of commit related data |
136 | def create_commit(project, branch, message, actions, options={}) | |
151 | def create_commit(project, branch, message, actions, options = {}) | |
137 | 152 | payload = { |
138 | branch: branch, | |
139 | commit_message: message, | |
140 | actions: actions, | |
153 | branch: branch, | |
154 | commit_message: message, | |
155 | actions: actions | |
141 | 156 | }.merge(options) |
142 | 157 | post("/projects/#{url_encode project}/repository/commits", body: payload) |
143 | 158 | end |
155 | 170 | # @option options [Integer] :page The page number. |
156 | 171 | # @option options [Integer] :per_page The number of results per page. |
157 | 172 | # @return [Array<Gitlab::ObjectifiedHash>] |
158 | def commit_merge_requests(project, commit, options={}) | |
173 | def commit_merge_requests(project, commit, options = {}) | |
159 | 174 | get("/projects/#{url_encode project}/repository/commits/#{commit}/merge_requests", query: options) |
160 | 175 | end |
161 | alias_method :repo_commit_merge_requests, :commit_merge_requests | |
176 | alias repo_commit_merge_requests commit_merge_requests | |
162 | 177 | end |
163 | 178 | end |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to deployments. |
2 | 4 | # @see https://docs.gitlab.com/ce/api/deployments.html |
12 | 14 | # @option options [Integer] :page The page number. |
13 | 15 | # @option options [Integer] :per_page The number of results per page. |
14 | 16 | # @return [Array<Gitlab::ObjectifiedHash>] |
15 | def deployments(project, options={}) | |
17 | def deployments(project, options = {}) | |
16 | 18 | get("/projects/#{url_encode project}/deployments", query: options) |
17 | 19 | end |
18 | 20 |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to environments. |
2 | 4 | # @see https://docs.gitlab.com/ce/api/environments.html |
12 | 14 | # @option options [Integer] :page The page number. |
13 | 15 | # @option options [Integer] :per_page The number of results per page. |
14 | 16 | # @return [Array<Gitlab::ObjectifiedHash>] |
15 | def environments(project, options={}) | |
17 | def environments(project, options = {}) | |
16 | 18 | get("/projects/#{url_encode project}/environments", query: options) |
17 | 19 | end |
18 | 20 | |
39 | 41 | # @option options [String] :external_url Optional URL for viewing the deployed project in this environment |
40 | 42 | # @return [Gitlab::ObjectifiedHash] The updated environment. |
41 | 43 | def create_environment(project, env_name, options = {}) |
42 | body = {name: env_name}.merge(options) | |
44 | body = { name: env_name }.merge(options) | |
43 | 45 | post("/projects/#{url_encode project}/environments", body: body) |
44 | 46 | end |
45 | 47 | |
55 | 57 | # @option options [String] env_name Name for the environment |
56 | 58 | # @option options [String] external_url Optional URL for viewing the deployed project in this environment |
57 | 59 | # @return [Gitlab::ObjectifiedHash] The updated environment. |
58 | def edit_environment(project, id, options={}) | |
60 | def edit_environment(project, id, options = {}) | |
59 | 61 | put("/projects/#{url_encode project}/environments/#{id}", body: options) |
60 | 62 | end |
61 | 63 |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to events. |
2 | 4 | # @see https://docs.gitlab.com/ce/api/events.html |
14 | 16 | # @option options [String] :after Only events created after YYYY-MM-DD |
15 | 17 | # @option options [String] :sort Sort by created_at either 'asc' or 'desc' |
16 | 18 | # @return [Array<Gitlab::ObjectifiedHash>] |
17 | def events(options={}) | |
19 | def events(options = {}) | |
18 | 20 | get('/events', query: options) |
19 | 21 | end |
20 | 22 | |
32 | 34 | # @option options [String] :after Only events created after YYYY-MM-DD |
33 | 35 | # @option options [String] :sort Sort by created_at either 'asc' or 'desc' |
34 | 36 | # @return [Array<Gitlab::ObjectifiedHash>] |
35 | def user_events(user, options={}) | |
37 | def user_events(user, options = {}) | |
36 | 38 | get("/users/#{url_encode user}/events", query: options) |
37 | 39 | end |
38 | 40 | |
50 | 52 | # @option options [String] :after Only events created after YYYY-MM-DD |
51 | 53 | # @option options [String] :sort Sort by created_at either 'asc' or 'desc' |
52 | 54 | # @return [Array<Gitlab::ObjectifiedHash>] |
53 | def project_events(project, options={}) | |
54 | get("/#{url_encode project}/events", query: options) | |
55 | def project_events(project, options = {}) | |
56 | get("/projects/#{url_encode project}/events", query: options) | |
55 | 57 | end |
56 | 58 | end |
57 | 59 | end |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to group milestones. |
2 | 4 | # @see https://docs.gitlab.com/ee/api/group_milestones.html |
11 | 13 | # @option options [Integer] :page The page number. |
12 | 14 | # @option options [Integer] :per_page The number of results per page. |
13 | 15 | # @return [Array<Gitlab::ObjectifiedHash>] |
14 | def group_milestones(id, options={}) | |
16 | def group_milestones(id, options = {}) | |
15 | 17 | get("/groups/#{url_encode id}/milestones", query: options) |
16 | 18 | end |
17 | 19 | |
38 | 40 | # @option options [String] :description The description of a milestone. |
39 | 41 | # @option options [String] :due_date The due date of a milestone. |
40 | 42 | # @return [Gitlab::ObjectifiedHash] Information about created milestone. |
41 | def create_group_milestone(id, title, options={}) | |
43 | def create_group_milestone(id, title, options = {}) | |
42 | 44 | body = { title: title }.merge(options) |
43 | 45 | post("/groups/#{url_encode id}/milestones", body: body) |
44 | 46 | end |
56 | 58 | # @option options [String] :due_date The due date of a milestone. |
57 | 59 | # @option options [String] :state_event The state of a milestone ('close' or 'activate'). |
58 | 60 | # @return [Gitlab::ObjectifiedHash] Information about updated milestone. |
59 | def edit_group_milestone(id, milestone_id, options={}) | |
61 | def edit_group_milestone(id, milestone_id, options = {}) | |
60 | 62 | put("/groups/#{url_encode id}/milestones/#{milestone_id}", body: options) |
61 | 63 | end |
62 | 64 | |
70 | 72 | # @option options [Integer] :page The page number. |
71 | 73 | # @option options [Integer] :per_page The number of results per page. |
72 | 74 | # @return [Array<Gitlab::ObjectifiedHash>] |
73 | def group_milestone_issues(id, milestone_id, options={}) | |
75 | def group_milestone_issues(id, milestone_id, options = {}) | |
74 | 76 | get("/groups/#{url_encode id}/milestones/#{milestone_id}/issues", query: options) |
75 | 77 | end |
76 | 78 | |
84 | 86 | # @option options [Integer] :page The page number. |
85 | 87 | # @option options [Integer] :per_page The number of results per page. |
86 | 88 | # @return [Array<Gitlab::ObjectifiedHash>] |
87 | def group_milestone_merge_requests(id, milestone_id, options={}) | |
89 | def group_milestone_merge_requests(id, milestone_id, options = {}) | |
88 | 90 | get("/groups/#{url_encode id}/milestones/#{milestone_id}/merge_requests", query: options) |
89 | 91 | end |
90 | 92 | end |
91 | 93 | end |
92 |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to groups. |
2 | 4 | # @see https://docs.gitlab.com/ce/api/groups.html |
11 | 13 | # @option options [Integer] :page The page number. |
12 | 14 | # @option options [Integer] :per_page The number of results per page. |
13 | 15 | # @return [Array<Gitlab::ObjectifiedHash>] |
14 | def groups(options={}) | |
15 | get("/groups", query: options) | |
16 | def groups(options = {}) | |
17 | get('/groups', query: options) | |
16 | 18 | end |
17 | 19 | |
18 | 20 | # Gets a single group. |
35 | 37 | # @param [String] name The name of a group. |
36 | 38 | # @param [String] path The path of a group. |
37 | 39 | # @return [Gitlab::ObjectifiedHash] Information about created group. |
38 | def create_group(name, path, options={}) | |
40 | def create_group(name, path, options = {}) | |
39 | 41 | body = { name: name, path: path }.merge(options) |
40 | post("/groups", body: body) | |
42 | post('/groups', body: body) | |
41 | 43 | end |
42 | 44 | |
43 | 45 | # Delete's a group. |
61 | 63 | # @option options [Integer] :page The page number. |
62 | 64 | # @option options [Integer] :per_page The number of results per page. |
63 | 65 | # @return [Array<Gitlab::ObjectifiedHash>] |
64 | def group_members(id, options={}) | |
66 | def group_members(id, options = {}) | |
65 | 67 | get("/groups/#{url_encode id}/members", query: options) |
66 | 68 | end |
67 | 69 | |
137 | 139 | # @option options [String] :per_page Number of projects to return per page |
138 | 140 | # @option options [String] :page The page to retrieve |
139 | 141 | # @return [Array<Gitlab::ObjectifiedHash>] |
140 | def group_search(search, options={}) | |
142 | def group_search(search, options = {}) | |
141 | 143 | options[:search] = search |
142 | get("/groups", query: options) | |
144 | get('/groups', query: options) | |
143 | 145 | end |
144 | 146 | |
145 | 147 | # Get a list of projects under a group |
148 | 150 | # |
149 | 151 | # @param [Integer] id The ID of a group |
150 | 152 | # @return [Array<Gitlab::ObjectifiedHash>] List of projects under a group |
151 | def group_projects(id, options={}) | |
153 | def group_projects(id, options = {}) | |
152 | 154 | get("/groups/#{url_encode id}/projects", query: options) |
153 | 155 | end |
154 | 156 | |
166 | 168 | # @option options [String] :statistics Include group statistics (admins only). |
167 | 169 | # @option options [String] :owned Limit to groups owned by the current user. |
168 | 170 | # @return [Array<Gitlab::ObjectifiedHash>] List of subgroups under a group |
169 | def group_subgroups(id, options={}) | |
171 | def group_subgroups(id, options = {}) | |
170 | 172 | get("/groups/#{url_encode id}/subgroups", query: options) |
171 | 173 | end |
172 | 174 | |
185 | 187 | # @option options [String] :lfs_enabled Enable/disable Large File Storage (LFS) for the projects in this groupr. |
186 | 188 | # @option options [String] :request_access_enabled Allow users to request member access. |
187 | 189 | # @return [Gitlab::ObjectifiedHash] Information about the edited group. |
188 | def edit_group(id, options={}) | |
190 | def edit_group(id, options = {}) | |
189 | 191 | put("/groups/#{url_encode id}", body: options) |
190 | 192 | end |
191 | 193 | end |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to issues. |
2 | 4 | # @see https://docs.gitlab.com/ce/api/issues.html |
14 | 16 | # @option options [Integer] :page The page number. |
15 | 17 | # @option options [Integer] :per_page The number of results per page. |
16 | 18 | # @return [Array<Gitlab::ObjectifiedHash>] |
17 | def issues(project=nil, options={}) | |
19 | def issues(project = nil, options = {}) | |
18 | 20 | if project.to_s.empty? && project.to_i.zero? |
19 | get("/issues", query: options) | |
21 | get('/issues', query: options) | |
20 | 22 | else |
21 | 23 | get("/projects/#{url_encode project}/issues", query: options) |
22 | 24 | end |
48 | 50 | # @option options [Integer] :milestone_id The ID of a milestone to assign issue. |
49 | 51 | # @option options [String] :labels Comma-separated label names for an issue. |
50 | 52 | # @return [Gitlab::ObjectifiedHash] Information about created issue. |
51 | def create_issue(project, title, options={}) | |
53 | def create_issue(project, title, options = {}) | |
52 | 54 | body = { title: title }.merge(options) |
53 | 55 | post("/projects/#{url_encode project}/issues", body: body) |
54 | 56 | end |
68 | 70 | # @option options [String] :labels Comma-separated label names for an issue. |
69 | 71 | # @option options [String] :state_event The state event of an issue ('close' or 'reopen'). |
70 | 72 | # @return [Gitlab::ObjectifiedHash] Information about updated issue. |
71 | def edit_issue(project, id, options={}) | |
73 | def edit_issue(project, id, options = {}) | |
72 | 74 | put("/projects/#{url_encode project}/issues/#{id}", body: options) |
73 | 75 | end |
74 | 76 | |
142 | 144 | # @param [Integer] id The ID of an issue. |
143 | 145 | # @option options [String] :to_project_id The ID of the new project. |
144 | 146 | # @return [Gitlab::ObjectifiedHash] Information about moved issue. |
145 | def move_issue(project, id, options={}) | |
147 | def move_issue(project, id, options = {}) | |
146 | 148 | post("/projects/#{url_encode project}/issues/#{id}/move", body: options) |
147 | 149 | end |
148 | ||
150 | ||
149 | 151 | # Sets an estimated time of work for an issue. |
150 | 152 | # |
151 | 153 | # @example |
157 | 159 | def estimate_time_of_issue(project, id, duration) |
158 | 160 | post("/projects/#{url_encode project}/issues/#{id}/time_estimate", body: { duration: url_encode(duration) }) |
159 | 161 | end |
160 | ||
161 | # Resets the estimated time for an issue to 0 seconds. | |
162 | ||
163 | # Resets the estimated time for an issue to 0 seconds. | |
162 | 164 | # |
163 | 165 | # @example |
164 | 166 | # Gitlab.reset_time_estimate_of_issue(3, 42) |
168 | 170 | def reset_time_estimate_of_issue(project, id) |
169 | 171 | post("/projects/#{url_encode project}/issues/#{id}/reset_time_estimate") |
170 | 172 | end |
171 | ||
173 | ||
172 | 174 | # Adds spent time for an issue |
173 | 175 | # |
174 | 176 | # @example |
180 | 182 | def add_time_spent_on_issue(project, id, duration) |
181 | 183 | post("/projects/#{url_encode project}/issues/#{id}/add_spent_time", body: { duration: url_encode(duration) }) |
182 | 184 | end |
183 | ||
185 | ||
184 | 186 | # Resets the total spent time for this issue to 0 seconds. |
185 | 187 | # |
186 | 188 | # @example |
191 | 193 | def reset_time_spent_on_issue(project, id) |
192 | 194 | post("/projects/#{url_encode project}/issues/#{id}/reset_spent_time") |
193 | 195 | end |
194 | ||
196 | ||
195 | 197 | # Get time tracking stats for an issue |
196 | 198 | # |
197 | 199 | # @example |
202 | 204 | def time_stats_for_issue(project, id) |
203 | 205 | get("/projects/#{url_encode project}/issues/#{id}/time_stats") |
204 | 206 | end |
205 | ||
207 | ||
208 | # Get participants on issue | |
209 | # | |
210 | # @example | |
211 | # @gitlab.participants_on_issue(3, 42) | |
212 | # | |
213 | # @param [Integer, String] project The ID or name of a project. | |
214 | # @param [Integer] id The ID of an issue. | |
215 | def participants_on_issue(project, id) | |
216 | get("/projects/#{url_encode project}/issues/#{id}/participants") | |
217 | end | |
218 | ||
219 | # List merge requests that will close issue on merge | |
220 | # | |
221 | # @example | |
222 | # Gitlab.merge_requests_closing_issue_on_merge(3, 42) | |
223 | # | |
224 | # @param [Integer, String] project The ID or name of a project. | |
225 | # @param [Integer] id The ID of an issue. | |
226 | def merge_requests_closing_issue_on_merge(project, id) | |
227 | get("/projects/#{url_encode project}/issues/#{id}/closed_by") | |
228 | end | |
206 | 229 | end |
207 | 230 | end |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to projects. |
2 | 4 | # @see https://docs.gitlab.com/ee/api/jobs.html |
6 | 8 | # @example |
7 | 9 | # Gitlab.jobs(1) |
8 | 10 | # Gitlab.jobs("project") |
11 | # Gitlab.jobs("project", {scope: ["manual", "success"], per_page: 100 }) | |
9 | 12 | # |
10 | 13 | # @param [Integer, String] id The ID or name of a project. |
11 | 14 | # @param [Hash] options A customizable set of options. |
12 | 15 | # @option options [Array] :scope The scope of jobs to show, one or array of: created, pending, running, failed, success, canceled, skipped, manual; showing all jobs if none provided. |
16 | # @option options [Integer] :page The page number. | |
17 | # @option options [Integer] :per_page The number of results per page. | |
13 | 18 | # @return [Array<Gitlab::ObjectifiedHash>] |
14 | 19 | def jobs(project_id, options = {}) |
15 | 20 | get("/projects/#{url_encode project_id}/jobs", query: options) |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to keys. |
2 | 4 | # @see https://docs.gitlab.com/ce/api/keys.html |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to labels. |
2 | 4 | # @see https://docs.gitlab.com/ce/api/labels.html |
8 | 10 | # |
9 | 11 | # @param [Integer, String] project The ID or name of a project. |
10 | 12 | # @return [Array<Gitlab::ObjectifiedHash>] |
11 | def labels(project, options={}) | |
13 | def labels(project, options = {}) | |
12 | 14 | get("/projects/#{url_encode project}/labels", query: options) |
13 | 15 | end |
14 | 16 | |
42 | 44 | # @option options [String] :description The description of the label. |
43 | 45 | # @option options [String] :priority The priority of the label. Must be greater or equal than zero or null to remove the priority. |
44 | 46 | # @return [Gitlab::ObjectifiedHash] Information about updated label. |
45 | def edit_label(project, name, options={}) | |
47 | def edit_label(project, name, options = {}) | |
46 | 48 | put("/projects/#{url_encode project}/labels", body: options.merge(name: name)) |
47 | 49 | end |
48 | 50 |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to MR Approvals. |
2 | 4 | # @see https://docs.gitlab.com/ee/api/merge_request_approvals.html |
106 | 108 | post("/projects/#{url_encode project}/merge_requests/#{merge_request}/unapprove") |
107 | 109 | end |
108 | 110 | end |
109 | end⏎ | |
111 | end |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to merge requests. |
2 | 4 | # @see https://docs.gitlab.com/ce/api/merge_requests.html |
24 | 26 | # @option options [Integer] :page The page number. |
25 | 27 | # @option options [Integer] :per_page The number of results per page. |
26 | 28 | # @return [Array<Gitlab::ObjectifiedHash>] |
27 | def merge_requests(project, options={}) | |
29 | def merge_requests(project, options = {}) | |
28 | 30 | get("/projects/#{url_encode project}/merge_requests", query: options) |
29 | 31 | end |
30 | 32 | |
38 | 40 | # @return <Gitlab::ObjectifiedHash] |
39 | 41 | def merge_request(project, id) |
40 | 42 | get("/projects/#{url_encode project}/merge_requests/#{id}") |
43 | end | |
44 | ||
45 | # Gets a list of merge request pipelines. | |
46 | # | |
47 | # @example | |
48 | # Gitlab.merge_request_pipelines(5, 36) | |
49 | # | |
50 | # @param [Integer, String] project The ID or name of a project. | |
51 | # @param [Integer] id The ID of a merge request. | |
52 | # @return [Array<Gitlab::ObjectifiedHash>] | |
53 | def merge_request_pipelines(project, id) | |
54 | get("/projects/#{url_encode project}/merge_requests/#{id}/pipelines") | |
41 | 55 | end |
42 | 56 | |
43 | 57 | # Creates a merge request. |
57 | 71 | # @option options [Integer] :target_project_id (optional) The target project ID. |
58 | 72 | # @option options [String] :labels (optional) Labels as a comma-separated list. |
59 | 73 | # @return [Gitlab::ObjectifiedHash] Information about created merge request. |
60 | def create_merge_request(project, title, options={}) | |
74 | def create_merge_request(project, title, options = {}) | |
61 | 75 | body = { title: title }.merge(options) |
62 | 76 | post("/projects/#{url_encode project}/merge_requests", body: body) |
63 | 77 | end |
76 | 90 | # @option options [Integer] :assignee_id The ID of a user to assign merge request. |
77 | 91 | # @option options [String] :state_event New state (close|reopen|merge). |
78 | 92 | # @return [Gitlab::ObjectifiedHash] Information about updated merge request. |
79 | def update_merge_request(project, id, options={}) | |
93 | def update_merge_request(project, id, options = {}) | |
80 | 94 | put("/projects/#{url_encode project}/merge_requests/#{id}", body: options) |
81 | 95 | end |
82 | 96 | |
90 | 104 | # @param [Hash] options A customizable set of options. |
91 | 105 | # @option options [String] :merge_commit_message Custom merge commit message |
92 | 106 | # @return [Gitlab::ObjectifiedHash] Information about updated merge request. |
93 | def accept_merge_request(project, id, options={}) | |
107 | def accept_merge_request(project, id, options = {}) | |
94 | 108 | put("/projects/#{url_encode project}/merge_requests/#{id}/merge", body: options) |
95 | 109 | end |
96 | 110 | |
204 | 218 | # * :x (Integer) X coordinate (for 'image' diff notes) |
205 | 219 | # * :y (Integer) Y coordinate (for 'image' diff notes) |
206 | 220 | # @return [Gitlab::ObjectifiedHash] The created merge request discussion. |
207 | def create_merge_request_discussion(project, merge_request_id, options={}) | |
221 | def create_merge_request_discussion(project, merge_request_id, options = {}) | |
208 | 222 | post("/projects/#{url_encode project}/merge_requests/#{merge_request_id}/discussions", body: options) |
209 | 223 | end |
210 | 224 | |
270 | 284 | def delete_merge_request_discussion_note(project, merge_request_id, discussion_id, note_id) |
271 | 285 | delete("/projects/#{url_encode project}/merge_requests/#{merge_request_id}/discussions/#{discussion_id}/notes/#{note_id}") |
272 | 286 | end |
287 | ||
288 | # Gets a list of merge request diff versions | |
289 | # | |
290 | # @example | |
291 | # Gitlab.merge_request_versions(5, 1) | |
292 | # Gitlab.merge_request_versions('gitlab', 1) | |
293 | # @param [Integer, String] project The ID or name of a project. | |
294 | # @param [Integer] id The ID of a merge request. | |
295 | # @return [Gitlab::ObjectifiedHash] A list of the merge request versions. | |
296 | def merge_request_diff_versions(project, merge_request_id) | |
297 | get("/projects/#{url_encode project}/merge_requests/#{merge_request_id}/versions") | |
298 | end | |
299 | ||
300 | # Gets the diff a single merge request diff version\ | |
301 | # | |
302 | # @example | |
303 | # Gitlab.merge_request_diff_version(5, 1, 1) | |
304 | # Gitlab.merge_request_diff_version('gitlab', 1, 1) | |
305 | # @param [Integer, String] project The ID or name of a project. | |
306 | # @param [Integer] id The ID of a merge request. | |
307 | # @param [Integer] id The ID of a merge request diff version. | |
308 | # @return [Gitlab::ObjectifiedHash] Record of the specific diff | |
309 | def merge_request_diff_version(project, merge_request_id, version_id) | |
310 | get("/projects/#{url_encode project}/merge_requests/#{merge_request_id}/versions/#{version_id}") | |
311 | end | |
273 | 312 | end |
274 | 313 | end |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to milestones. |
2 | 4 | # @see https://docs.gitlab.com/ce/api/milestones.html |
11 | 13 | # @option options [Integer] :page The page number. |
12 | 14 | # @option options [Integer] :per_page The number of results per page. |
13 | 15 | # @return [Array<Gitlab::ObjectifiedHash>] |
14 | def milestones(project, options={}) | |
16 | def milestones(project, options = {}) | |
15 | 17 | get("/projects/#{url_encode project}/milestones", query: options) |
16 | 18 | end |
17 | 19 | |
37 | 39 | # @option options [Integer] :page The page number. |
38 | 40 | # @option options [Integer] :per_page The number of results per page. |
39 | 41 | # @return [Array<Gitlab::ObjectifiedHash>] |
40 | def milestone_issues(project, milestone, options={}) | |
42 | def milestone_issues(project, milestone, options = {}) | |
41 | 43 | get("/projects/#{url_encode project}/milestones/#{milestone}/issues", query: options) |
42 | 44 | end |
43 | 45 | |
51 | 53 | # @option options [Integer] :page The page number. |
52 | 54 | # @option options [Integer] :per_page The number of results per page. |
53 | 55 | # @return [Array<Gitlab::ObjectifiedHash>] |
54 | def milestone_merge_requests(project, milestone, options={}) | |
56 | def milestone_merge_requests(project, milestone, options = {}) | |
55 | 57 | get("/projects/#{url_encode project}/milestones/#{milestone}/merge_requests", query: options) |
56 | 58 | end |
57 | 59 | |
66 | 68 | # @option options [String] :description The description of a milestone. |
67 | 69 | # @option options [String] :due_date The due date of a milestone. |
68 | 70 | # @return [Gitlab::ObjectifiedHash] Information about created milestone. |
69 | def create_milestone(project, title, options={}) | |
71 | def create_milestone(project, title, options = {}) | |
70 | 72 | body = { title: title }.merge(options) |
71 | 73 | post("/projects/#{url_encode project}/milestones", body: body) |
72 | 74 | end |
84 | 86 | # @option options [String] :due_date The due date of a milestone. |
85 | 87 | # @option options [String] :state_event The state of a milestone ('close' or 'activate'). |
86 | 88 | # @return [Gitlab::ObjectifiedHash] Information about updated milestone. |
87 | def edit_milestone(project, id, options={}) | |
89 | def edit_milestone(project, id, options = {}) | |
88 | 90 | put("/projects/#{url_encode project}/milestones/#{id}", body: options) |
91 | end | |
92 | ||
93 | # Delete a project milestone. | |
94 | # | |
95 | # @example | |
96 | # Gitlab.delete_milestone(5, 2) | |
97 | # | |
98 | # @param [Integer, String] project The ID or name of a project. | |
99 | # @param [Integer] id The ID of a milestone. | |
100 | # @return [nil] This API call returns an empty response body. | |
101 | def delete_milestone(project, id) | |
102 | delete("/projects/#{url_encode project}/milestones/#{id}") | |
89 | 103 | end |
90 | 104 | end |
91 | 105 | end |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to namespaces |
2 | 4 | # @see https://docs.gitlab.com/ce/api/namespaces.html |
12 | 14 | # @options options [Integer] :per_page The number of results per page. |
13 | 15 | # @options opttion [String] :search The string to search for. |
14 | 16 | # @return [Array<Gitlab::ObjectifiedHash>] |
15 | def namespaces(options={}) | |
16 | get("/namespaces", query: options) | |
17 | def namespaces(options = {}) | |
18 | get('/namespaces', query: options) | |
17 | 19 | end |
18 | 20 | end |
19 | 21 | end |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to notes. |
2 | 4 | # @see https://docs.gitlab.com/ce/api/notes.html |
10 | 12 | # @option options [Integer] :page The page number. |
11 | 13 | # @option options [Integer] :per_page The number of results per page. |
12 | 14 | # @return [Array<Gitlab::ObjectifiedHash>] |
13 | def notes(project, options={}) | |
15 | def notes(project, options = {}) | |
14 | 16 | get("/projects/#{url_encode project}/notes", query: options) |
15 | 17 | end |
16 | 18 | |
24 | 26 | # @option options [Integer] :page The page number. |
25 | 27 | # @option options [Integer] :per_page The number of results per page. |
26 | 28 | # @return [Array<Gitlab::ObjectifiedHash>] |
27 | def issue_notes(project, issue, options={}) | |
29 | def issue_notes(project, issue, options = {}) | |
28 | 30 | get("/projects/#{url_encode project}/issues/#{issue}/notes", query: options) |
29 | 31 | end |
30 | 32 | |
38 | 40 | # @option options [Integer] :page The page number. |
39 | 41 | # @option options [Integer] :per_page The number of results per page. |
40 | 42 | # @return [Array<Gitlab::ObjectifiedHash>] |
41 | def snippet_notes(project, snippet, options={}) | |
43 | def snippet_notes(project, snippet, options = {}) | |
42 | 44 | get("/projects/#{url_encode project}/snippets/#{snippet}/notes", query: options) |
43 | 45 | end |
44 | 46 | |
52 | 54 | # @option options [Integer] :page The page number. |
53 | 55 | # @option options [Integer] :per_page The number of results per page. |
54 | 56 | # @return [Array<Gitlab::ObjectifiedHash>] |
55 | def merge_request_notes(project, merge_request, options={}) | |
57 | def merge_request_notes(project, merge_request, options = {}) | |
56 | 58 | get("/projects/#{url_encode project}/merge_requests/#{merge_request}/notes", query: options) |
57 | 59 | end |
58 | alias_method :merge_request_comments, :merge_request_notes | |
60 | alias merge_request_comments merge_request_notes | |
59 | 61 | |
60 | 62 | # Gets a single wall note. |
61 | 63 | # |
157 | 159 | def create_merge_request_note(project, merge_request, body) |
158 | 160 | post("/projects/#{url_encode project}/merge_requests/#{merge_request}/notes", body: { body: body }) |
159 | 161 | end |
160 | alias_method :create_merge_request_comment, :create_merge_request_note | |
162 | alias create_merge_request_comment create_merge_request_note | |
161 | 163 | |
162 | 164 | # Deletes a wall note. |
163 | 165 | # |
209 | 211 | def delete_merge_request_note(project, merge_request, id) |
210 | 212 | delete("/projects/#{url_encode project}/merge_requests/#{merge_request}/notes/#{id}") |
211 | 213 | end |
212 | alias_method :delete_merge_request_comment, :delete_merge_request_note | |
214 | alias delete_merge_request_comment delete_merge_request_note | |
213 | 215 | |
214 | 216 | # Modifies a wall note. |
215 | 217 | # |
265 | 267 | def edit_merge_request_note(project, merge_request, id, body) |
266 | 268 | put("/projects/#{url_encode project}/merge_requests/#{merge_request}/notes/#{id}", body: note_content(body)) |
267 | 269 | end |
268 | alias_method :edit_merge_request_comment, :edit_merge_request_note | |
270 | alias edit_merge_request_comment edit_merge_request_note | |
269 | 271 | |
270 | 272 | private |
271 | 273 | |
273 | 275 | # in the 'else'. |
274 | 276 | def note_content(body) |
275 | 277 | if body.is_a?(Hash) |
276 | STDERR.puts "Passing the note body as a Hash is deprecated. You should just pass the String." | |
278 | STDERR.puts 'Passing the note body as a Hash is deprecated. You should just pass the String.' | |
277 | 279 | body |
278 | 280 | else |
279 | 281 | { body: body } |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to pipeline schedules. |
2 | 4 | # @see https://docs.gitlab.com/ce/api/pipeline_schedules.html |
11 | 13 | # @param [Hash] options A customizable set of options. |
12 | 14 | # @options options [String] :scope The scope of pipeline schedules, one of a 'active' or 'inactive'. |
13 | 15 | # @return [Array<Gitlab::ObjectifiedHash>] |
14 | def pipeline_schedules(project, options={}) | |
16 | def pipeline_schedules(project, options = {}) | |
15 | 17 | get("/projects/#{url_encode project}/pipeline_schedules", query: options) |
16 | 18 | end |
17 | 19 | |
40 | 42 | # @option options [String] :cron_timezone The timezone supproted by ActiveSupport::TimeZone (e.g. Pacific Time (US & Canada)) (default: 'UTC'). |
41 | 43 | # @option options [Boolean] :active The activation of pipeline schedule. If false is set, the pipeline schedule will deactivated initially (default: true). |
42 | 44 | # @return [Array<Gitlab::ObjectifiedHash>] |
43 | def create_pipeline_schedule(project, options={}) | |
45 | def create_pipeline_schedule(project, options = {}) | |
44 | 46 | post("/projects/#{url_encode project}/pipeline_schedules", query: options) |
45 | 47 | end |
46 | 48 | |
58 | 60 | # @option options [String] :cron_timezone The timezone supproted by ActiveSupport::TimeZone (e.g. Pacific Time (US & Canada)) (default: 'UTC'). |
59 | 61 | # @option options [Boolean] :active The activation of pipeline schedule. If false is set, the pipeline schedule will deactivated initially (default: true). |
60 | 62 | # @return [Array<Gitlab::ObjectifiedHash>] The updated pipeline schedule. |
61 | def edit_pipeline_schedule(project, pipeline_schedule_id, options={}) | |
63 | def edit_pipeline_schedule(project, pipeline_schedule_id, options = {}) | |
62 | 64 | put("/projects/#{url_encode project}/pipeline_schedules/#{pipeline_schedule_id}", query: options) |
63 | 65 | end |
64 | 66 | |
97 | 99 | # @option options [String] :key The key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed. |
98 | 100 | # @option options [String] :value The value of a variable |
99 | 101 | # @return [Array<Gitlab::ObjectifiedHash>] The created pipeline schedule variable. |
100 | def create_pipeline_schedule_variable(project, pipeline_schedule_id, options={}) | |
102 | def create_pipeline_schedule_variable(project, pipeline_schedule_id, options = {}) | |
101 | 103 | post("/projects/#{url_encode project}/pipeline_schedules/#{pipeline_schedule_id}/variables", query: options) |
102 | 104 | end |
103 | 105 | |
112 | 114 | # @param [Hash] options A customizable set of options. |
113 | 115 | # @option options [String] :value The value of a variable. |
114 | 116 | # @return [Array<Gitlab::ObjectifiedHash>] The updated pipeline schedule variable. |
115 | def edit_pipeline_schedule_variable(project, pipeline_schedule_id, key, options={}) | |
117 | def edit_pipeline_schedule_variable(project, pipeline_schedule_id, key, options = {}) | |
116 | 118 | put("/projects/#{url_encode project}/pipeline_schedules/#{pipeline_schedule_id}/variables/#{url_encode key}", query: options) |
117 | 119 | end |
118 | 120 | |
125 | 127 | # @param [Integer] The pipeline schedule ID. |
126 | 128 | # @param [String] The key of a variable. |
127 | 129 | # @return [Array<Gitlab::ObjectifiedHash>] The deleted pipeline schedule variable. |
128 | def delete_pipeline_schedule_variable(project, pipeline_schedule_id, key, options={}) | |
130 | def delete_pipeline_schedule_variable(project, pipeline_schedule_id, key, _options = {}) | |
129 | 131 | delete("/projects/#{url_encode project}/pipeline_schedules/#{pipeline_schedule_id}/variables/#{url_encode key}") |
130 | 132 | end |
131 | 133 | end |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to pipelines. |
2 | 4 | # @see https://docs.gitlab.com/ce/api/pipeline_triggers.html |
34 | 36 | # @param [String] description The trigger name |
35 | 37 | # @return [Gitlab::ObjectifiedHash] The created trigger. |
36 | 38 | def create_trigger(project, description) |
37 | post("/projects/#{url_encode project}/triggers", body: {description: description}) | |
39 | post("/projects/#{url_encode project}/triggers", body: { description: description }) | |
38 | 40 | end |
39 | 41 | |
40 | 42 | # Update a project trigger |
47 | 49 | # @param [Hash] options A customizable set of options. |
48 | 50 | # @option options [String] :description The trigger name. |
49 | 51 | # @return [Gitlab::ObjectifiedHash] The updated trigger. |
50 | def update_trigger(project, trigger_id, options={}) | |
52 | def update_trigger(project, trigger_id, options = {}) | |
51 | 53 | put("/projects/#{url_encode project}/triggers/#{trigger_id}", body: options) |
52 | 54 | end |
53 | 55 | |
74 | 76 | def remove_trigger(project, trigger_id) |
75 | 77 | delete("/projects/#{url_encode project}/triggers/#{trigger_id}") |
76 | 78 | end |
77 | alias_method :delete_trigger, :remove_trigger | |
79 | alias delete_trigger remove_trigger | |
78 | 80 | |
79 | 81 | # Run the given project pipeline trigger. |
80 | 82 | # |
89 | 91 | # @param [String] ref Branch or tag name to build. |
90 | 92 | # @param [Hash] variables A set of build variables to use for the build. (optional) |
91 | 93 | # @return [Gitlab::ObjectifiedHash] The trigger. |
92 | def run_trigger(project, token, ref, variables={}) | |
94 | def run_trigger(project, token, ref, variables = {}) | |
93 | 95 | post("/projects/#{url_encode project}/trigger/pipeline", unauthenticated: true, body: { |
94 | token: token, | |
95 | ref: ref, | |
96 | variables: variables | |
97 | }) | |
96 | token: token, | |
97 | ref: ref, | |
98 | variables: variables | |
99 | }) | |
98 | 100 | end |
99 | 101 | end |
100 | 102 | end |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to pipelines. |
2 | 4 | # @see https://docs.gitlab.com/ce/api/pipelines.html |
12 | 14 | # @option options [Integer] :page The page number. |
13 | 15 | # @option options [Integer] :per_page The number of results per page. |
14 | 16 | # @return [Array<Gitlab::ObjectifiedHash>] |
15 | def pipelines(project, options={}) | |
17 | def pipelines(project, options = {}) | |
16 | 18 | get("/projects/#{url_encode project}/pipelines", query: options) |
17 | 19 | end |
18 | 20 | |
35 | 37 | # |
36 | 38 | # @param [Integer, String] project The ID or name of a project. |
37 | 39 | # @param [String] ref Reference to commit. |
40 | # @param [Hash] variables Variables passed to pipelines | |
38 | 41 | # @return [Gitlab::ObjectifiedHash] The pipelines changes. |
39 | def create_pipeline(project, ref) | |
40 | post("/projects/#{url_encode project}/pipeline?ref=#{ref}") | |
42 | def create_pipeline(project, ref, variables = {}) | |
43 | body = {} | |
44 | ||
45 | # This mapping is necessary, cause the API expects an array with objects (with `key` and `value` keys) | |
46 | # See: https://docs.gitlab.com/ee/api/pipelines.html#create-a-new-pipeline | |
47 | body[:variables] = variables.map { |(key, value)| { key: key, value: value } } if variables.any? | |
48 | ||
49 | post( | |
50 | "/projects/#{url_encode project}/pipeline", | |
51 | query: { ref: ref }, | |
52 | body: body | |
53 | ) | |
41 | 54 | end |
42 | 55 | |
43 | 56 | # Cancels a pipeline. |
0 | # frozen_string_literal: true | |
1 | ||
2 | class Gitlab::Client | |
3 | # Defines methods related to project badges. | |
4 | # @see https://docs.gitlab.com/ee/api/project_badges.html | |
5 | module ProjectBadges | |
6 | # Gets a list of a projects badges and its group badges. | |
7 | # | |
8 | # @example | |
9 | # Gitlab.project_badges(5) | |
10 | # | |
11 | # @param [Integer, String] project The ID or name of a project. | |
12 | # @return [Array<Gitlab::ObjectifiedHash>] List of all badges of a project | |
13 | def project_badges(project) | |
14 | get("/projects/#{url_encode project}/badges") | |
15 | end | |
16 | ||
17 | # Gets a badge of a project. | |
18 | # | |
19 | # @example | |
20 | # Gitlab.project_badge(5, 42) | |
21 | # | |
22 | # @param [Integer, String] project The ID or name of a project. | |
23 | # @param [Integer] badge_id The badge ID. | |
24 | # @return [Gitlab::ObjectifiedHash] Information about the requested badge | |
25 | def project_badge(project, badge_id) | |
26 | get("/projects/#{url_encode project}/badges/#{badge_id}") | |
27 | end | |
28 | ||
29 | # Adds a badge to a project. | |
30 | # | |
31 | # @example | |
32 | # Gitlab.add_project_badge(5, { link_url: 'https://abc.com/gitlab/gitlab-ce/commits/master', image_url: 'https://shields.io/my/badge1' }) | |
33 | # | |
34 | # @param [Integer, String] project The ID or name of a project. | |
35 | # @param [Hash] options A customizable set of options. | |
36 | # @option options [String] :link_url(required) URL of the badge link | |
37 | # @option options [String] :image_url(required) URL of the badge image | |
38 | # @return [Gitlab::ObjectifiedHash] Information about the added project badge. | |
39 | def add_project_badge(project, options = {}) | |
40 | post("/projects/#{url_encode project}/badges", body: options) | |
41 | end | |
42 | ||
43 | # Updates a badge of a project.. | |
44 | # | |
45 | # @example | |
46 | # Gitlab.edit_project_badge(5, 1, { link_url: 'https://abc.com/gitlab/gitlab-ce/commits/master', image_url: 'https://shields.io/my/badge1' }) | |
47 | # | |
48 | # @param [Integer, String] project The ID or name of a project. | |
49 | # @param [Integer] badge_id The badge ID. | |
50 | # @param [Hash] options A customizable set of options. | |
51 | # @option options [String] :link_url(optional) URL of the badge link | |
52 | # @option options [String] :image_url(optional) URL of the badge image | |
53 | # @return [Gitlab::ObjectifiedHash] Information about the updated project badge. | |
54 | def edit_project_badge(project, badge_id, options = {}) | |
55 | put("/projects/#{url_encode project}/badges/#{badge_id}", body: options) | |
56 | end | |
57 | ||
58 | # Removes a badge from a project. Only projects badges will be removed by using this endpoint. | |
59 | # | |
60 | # @example | |
61 | # Gitlab.remove_project_badge(5, 42) | |
62 | # | |
63 | # @param [Integer, String] project The ID or name of a project. | |
64 | # @param [Integer] badge_id The badge ID. | |
65 | # @return [nil] This API call returns an empty response body. | |
66 | def remove_project_badge(project, badge_id) | |
67 | delete("/projects/#{url_encode project}/badges/#{badge_id}") | |
68 | end | |
69 | ||
70 | # Preview a badge from a project. | |
71 | # | |
72 | # @example | |
73 | # Gitlab.preview_project_badge(3, 'https://abc.com/gitlab/gitlab-ce/commits/master', 'https://shields.io/my/badge1') | |
74 | # | |
75 | # @param [Integer, String] project The ID or name of a project. | |
76 | # @param [String] :link_url URL of the badge link | |
77 | # @param [String] :image_url URL of the badge image | |
78 | # @return [Gitlab::ObjectifiedHash] Returns how the link_url and image_url final URLs would be after resolving the placeholder interpolation. | |
79 | def preview_project_badge(project, link_url, image_url) | |
80 | query = { link_url: link_url, image_url: image_url } | |
81 | get("/projects/#{url_encode project}/badges/render", query: query) | |
82 | end | |
83 | end | |
84 | end |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to projects. |
2 | 4 | # @see https://docs.gitlab.com/ce/api/projects.html |
12 | 14 | # (Any provided options will be passed to Gitlab. See {https://docs.gitlab.com/ce/api/projects.html#list-all-projects Gitlab docs} for all valid options) |
13 | 15 | # |
14 | 16 | # @return [Array<Gitlab::ObjectifiedHash>] |
15 | def projects(options={}) | |
16 | get("/projects", query: options) | |
17 | def projects(options = {}) | |
18 | get('/projects', query: options) | |
17 | 19 | end |
18 | 20 | |
19 | 21 | # Search for projects by name. |
29 | 31 | # @option options [String] :order_by Return requests ordered by id, name, created_at or last_activity_at fields |
30 | 32 | # @option options [String] :sort Return requests sorted in asc or desc order |
31 | 33 | # @return [Array<Gitlab::ObjectifiedHash>] |
32 | def project_search(query, options={}) | |
33 | get("/projects", query: options.merge(search:query)) | |
34 | end | |
35 | alias_method :search_projects, :project_search | |
34 | def project_search(query, options = {}) | |
35 | get('/projects', query: options.merge(search: query)) | |
36 | end | |
37 | alias search_projects project_search | |
36 | 38 | |
37 | 39 | # Gets information about a project. |
38 | 40 | # |
67 | 69 | # @option options [Boolean] :public The setting for making a project public (0 = false, 1 = true). |
68 | 70 | # @option options [Integer] :user_id The user/owner id of a project. |
69 | 71 | # @return [Gitlab::ObjectifiedHash] Information about created project. |
70 | def create_project(name, options={}) | |
71 | url = options[:user_id] ? "/projects/user/#{options[:user_id]}" : "/projects" | |
72 | def create_project(name, options = {}) | |
73 | url = options[:user_id] ? "/projects/user/#{options[:user_id]}" : '/projects' | |
72 | 74 | post(url, body: { name: name }.merge(options)) |
73 | 75 | end |
74 | 76 | |
95 | 97 | # @option options [Integer] :page The page number. |
96 | 98 | # @option options [Integer] :per_page The number of results per page. |
97 | 99 | # @return [Array<Gitlab::ObjectifiedHash>] |
98 | def team_members(project, options={}) | |
100 | def team_members(project, options = {}) | |
99 | 101 | get("/projects/#{url_encode project}/members", query: options) |
100 | 102 | end |
101 | 103 | |
115 | 117 | # |
116 | 118 | # @example |
117 | 119 | # Gitlab.add_team_member('gitlab', 2, 40) |
120 | # Gitlab.add_team_member('gitlab', 2, 40, { expires_at: "2018-12-31"}) | |
118 | 121 | # |
119 | 122 | # @param [Integer, String] project The ID or path of a project. |
120 | 123 | # @param [Integer] id The ID of a user. |
121 | 124 | # @param [Integer] access_level The access level to project. |
122 | 125 | # @param [Hash] options A customizable set of options. |
126 | # @option options [String] :expires_at A date string in the format YEAR-MONTH-DAY. | |
123 | 127 | # @return [Gitlab::ObjectifiedHash] Information about added team member. |
124 | def add_team_member(project, id, access_level) | |
125 | post("/projects/#{url_encode project}/members", body: { user_id: id, access_level: access_level }) | |
128 | def add_team_member(project, id, access_level, options = {}) | |
129 | body = { user_id: id, access_level: access_level }.merge(options) | |
130 | post("/projects/#{url_encode project}/members", body: body) | |
126 | 131 | end |
127 | 132 | |
128 | 133 | # Updates a team member's project access level. |
129 | 134 | # |
130 | 135 | # @example |
131 | 136 | # Gitlab.edit_team_member('gitlab', 3, 20) |
137 | # Gitlab.edit_team_member('gitlab', 3, 20, { expires_at: "2018-12-31"}) | |
132 | 138 | # |
133 | 139 | # @param [Integer, String] project The ID or path of a project. |
134 | 140 | # @param [Integer] id The ID of a user. |
135 | 141 | # @param [Integer] access_level The access level to project. |
136 | 142 | # @param [Hash] options A customizable set of options. |
143 | # @option options [String] :expires_at A date string in the format YEAR-MONTH-DAY. | |
137 | 144 | # @return [Array<Gitlab::ObjectifiedHash>] Information about updated team member. |
138 | def edit_team_member(project, id, access_level) | |
139 | put("/projects/#{url_encode project}/members/#{id}", body: { access_level: access_level }) | |
145 | def edit_team_member(project, id, access_level, options = {}) | |
146 | body = { access_level: access_level }.merge(options) | |
147 | put("/projects/#{url_encode project}/members/#{id}", body: body) | |
140 | 148 | end |
141 | 149 | |
142 | 150 | # Removes a user from project team. |
163 | 171 | # @option options [Integer] :page The page number. |
164 | 172 | # @option options [Integer] :per_page The number of results per page. |
165 | 173 | # @return [Array<Gitlab::ObjectifiedHash>] |
166 | def project_hooks(project, options={}) | |
174 | def project_hooks(project, options = {}) | |
167 | 175 | get("/projects/#{url_encode project}/hooks", query: options) |
168 | 176 | end |
169 | 177 | |
193 | 201 | # @param option [Boolean] :merge_requests_events Trigger hook on merge_requests events (0 = false, 1 = true) |
194 | 202 | # @param option [Boolean] :tag_push_events Trigger hook on push_tag events (0 = false, 1 = true) |
195 | 203 | # @return [Gitlab::ObjectifiedHash] Information about added hook. |
196 | def add_project_hook(project, url, options={}) | |
204 | def add_project_hook(project, url, options = {}) | |
197 | 205 | body = { url: url }.merge(options) |
198 | 206 | post("/projects/#{url_encode project}/hooks", body: body) |
199 | 207 | end |
212 | 220 | # @param option [Boolean] :merge_requests_events Trigger hook on merge_requests events (0 = false, 1 = true) |
213 | 221 | # @param option [Boolean] :tag_push_events Trigger hook on push_tag events (0 = false, 1 = true) |
214 | 222 | # @return [Gitlab::ObjectifiedHash] Information about updated hook. |
215 | def edit_project_hook(project, id, url, options={}) | |
223 | def edit_project_hook(project, id, url, options = {}) | |
216 | 224 | body = { url: url }.merge(options) |
217 | 225 | put("/projects/#{url_encode project}/hooks/#{id}", body: body) |
218 | 226 | end |
252 | 260 | # @param option [Boolean] :deny_delete_tag Do not allow users to remove git tags with git push (0 = false, 1 = true) |
253 | 261 | # @param option [String] :commit_message_regex Commit message regex |
254 | 262 | # @return [Gitlab::ObjectifiedHash] Information about added push rule. |
255 | def add_push_rule(id, options={}) | |
263 | def add_push_rule(id, options = {}) | |
256 | 264 | post("/projects/#{url_encode id}/push_rule", body: options) |
257 | 265 | end |
258 | 266 | |
267 | 275 | # @param option [Boolean] :deny_delete_tag Do not allow users to remove git tags with git push (0 = false, 1 = true) |
268 | 276 | # @param option [String] :commit_message_regex Commit message regex |
269 | 277 | # @return [Gitlab::ObjectifiedHash] Information about updated push rule. |
270 | def edit_push_rule(id, options={}) | |
278 | def edit_push_rule(id, options = {}) | |
271 | 279 | put("/projects/#{url_encode id}/push_rule", body: options) |
272 | 280 | end |
273 | 281 | |
317 | 325 | # @option options [Integer] :page The page number. |
318 | 326 | # @option options [Integer] :per_page The number of results per page. |
319 | 327 | # @return [Array<Gitlab::ObjectifiedHash>] |
320 | def deploy_keys(project, options={}) | |
328 | def deploy_keys(project, options = {}) | |
321 | 329 | get("/projects/#{url_encode project}/deploy_keys", query: options) |
322 | 330 | end |
323 | 331 | |
393 | 401 | # @param [Hash] options A customizable set of options. |
394 | 402 | # @option options [String] :sudo The username the project will be forked for |
395 | 403 | # @return [Gitlab::ObjectifiedHash] Information about the forked project. |
396 | def create_fork(id, options={}) | |
404 | def create_fork(id, options = {}) | |
397 | 405 | post("/projects/#{url_encode id}/fork", body: options) |
398 | 406 | end |
399 | 407 | |
411 | 419 | # @option options [String] :order_by Return requests ordered by id, name, created_at or last_activity_at fields |
412 | 420 | # @option options [String] :sort Return requests sorted in asc or desc order |
413 | 421 | # @return [Array<Gitlab::ObjectifiedHash>] |
414 | def project_forks(id, options={}) | |
422 | def project_forks(id, options = {}) | |
415 | 423 | get("/projects/#{url_encode id}/forks", query: options) |
416 | 424 | end |
417 | 425 | |
430 | 438 | # (Any provided options will be passed to Gitlab. See {https://docs.gitlab.com/ce/api/projects.html#edit-project Gitlab docs} for all valid options) |
431 | 439 | # |
432 | 440 | # @return [Gitlab::ObjectifiedHash] Information about the edited project. |
433 | def edit_project(id, options={}) | |
441 | def edit_project(id, options = {}) | |
434 | 442 | put("/projects/#{url_encode id}", body: options) |
435 | 443 | end |
436 | 444 | |
458 | 466 | delete("/projects/#{url_encode project}/share/#{id}") |
459 | 467 | end |
460 | 468 | |
469 | # Transfer a project to a new namespace. | |
470 | # | |
471 | # @example | |
472 | # Gitlab.transfer_project(42, 'yolo') | |
473 | # | |
474 | # @param [Integer, String] project The ID or path of a project | |
475 | # @param [Integer, String] namespace The ID or path of the namespace to transfer to project to | |
476 | # @return [Gitlab::ObjectifiedHash] Information about transfered project. | |
477 | def transfer_project(project, namespace) | |
478 | put("/projects/#{url_encode project}/transfer", body: { namespace: namespace }) | |
479 | end | |
480 | ||
461 | 481 | # Stars a project. |
462 | 482 | # @see https://docs.gitlab.com/ce/api/projects.html#star-a-project |
463 | 483 | # |
499 | 519 | # @option options [String] :order_by Return projects ordered by id, name, path, created_at, updated_at, or last_activity_at fields. |
500 | 520 | # @option options [String] :sort Return projects sorted in asc or desc order. |
501 | 521 | # @return [Array<Gitlab::ObjectifiedHash>] |
502 | def user_projects(user_id, options={}) | |
522 | def user_projects(user_id, options = {}) | |
503 | 523 | get("/users/#{url_encode user_id}/projects", query: options) |
524 | end | |
525 | ||
526 | # Uploads a file to the specified project to be used in an issue or | |
527 | # merge request description, or a comment. | |
528 | # @see https://docs.gitlab.com/ee/api/projects.html#upload-a-file | |
529 | # | |
530 | # @example | |
531 | # Gitlab.upload_file(1, File.open(File::NULL, 'r')) | |
532 | # File.open('myfile') { |file| Gitlab.upload_file(1, file) } | |
533 | # | |
534 | # @param [Integer, String] id The ID or path of a project. | |
535 | # @param [File] The file you are interested to upload. | |
536 | # @return [Gitlab::ObjectifiedHash] | |
537 | def upload_file(id, file) | |
538 | post("/projects/#{url_encode id}/uploads", body: { file: file }) | |
539 | end | |
540 | ||
541 | # Get all project templates of a particular type | |
542 | # @see https://docs.gitlab.com/ce/api/project_templates.html | |
543 | # | |
544 | # @example | |
545 | # Gitlab.project_templates(1, 'dockerfiles') | |
546 | # Gitlab.project_templates(1, 'licenses') | |
547 | # | |
548 | # @param [Integer, String] id The ID or URL-encoded path of the project. | |
549 | # @param [String] type The type (dockerfiles|gitignores|gitlab_ci_ymls|licenses) of the template | |
550 | # @return [Array<Gitlab::ObjectifiedHash>] | |
551 | def project_templates(project, type) | |
552 | get("/projects/#{url_encode project}/templates/#{type}") | |
553 | end | |
554 | ||
555 | # Get one project template of a particular type | |
556 | # @see https://docs.gitlab.com/ce/api/project_templates.html | |
557 | # | |
558 | # @example | |
559 | # Gitlab.project_template(1, 'dockerfiles', 'dockey') | |
560 | # Gitlab.project_template(1, 'licenses', 'gpl', { project: 'some project', fullname: 'Holder Holding' }) | |
561 | # | |
562 | # @param [Integer, String] project The ID or URL-encoded path of the project. | |
563 | # @param [String] type The type (dockerfiles|gitignores|gitlab_ci_ymls|licenses) of the template | |
564 | # @param [String] key The key of the template, as obtained from the collection endpoint | |
565 | # @param [Hash] options A customizable set of options. | |
566 | # @option options [String] project(optional) The project name to use when expanding placeholders in the template. Only affects licenses | |
567 | # @option options [String] fullname(optional) The full name of the copyright holder to use when expanding placeholders in the template. Only affects licenses | |
568 | # @return [Gitlab::ObjectifiedHash] | |
569 | def project_template(project, type, key, options = {}) | |
570 | get("/projects/#{url_encode project}/templates/#{type}/#{key}", query: options) | |
504 | 571 | end |
505 | 572 | end |
506 | 573 | end |
0 | # frozen_string_literal: true | |
1 | ||
2 | class Gitlab::Client | |
3 | # Defines methods related to Protected Tags. | |
4 | # @see https://docs.gitlab.com/ce/api/protected_tags.html | |
5 | module ProtectedTags | |
6 | # Gets a list of protected tags from a project | |
7 | # | |
8 | # @example | |
9 | # Gitlab.protected_tags(1) | |
10 | # | |
11 | # @param [Integer, String] project(required) The ID or name of a project. | |
12 | # @option options [Integer] :page The page number. | |
13 | # @option options [Integer] :per_page The number of results per page. | |
14 | # @return [Array<Gitlab::ObjectifiedHash>] List of all protected tags requested | |
15 | def protected_tags(project, options = {}) | |
16 | get("/projects/#{url_encode project}/protected_tags", query: options) | |
17 | end | |
18 | ||
19 | # Gets a single protected tag or wildcard protected tag. | |
20 | # | |
21 | # @example | |
22 | # Gitlab.protected_tag(1, 'release-1-0') | |
23 | # | |
24 | # @param [Integer, String] project(required) The ID or name of a project. | |
25 | # @param [String] name(required) The name of the tag or wildcard | |
26 | # @return <Gitlab::ObjectifiedHash] Information about the requested protected tag | |
27 | def protected_tag(project, name) | |
28 | get("/projects/#{url_encode project}/protected_tags/#{name}") | |
29 | end | |
30 | ||
31 | # Protects a single repository tag or several project repository tags using a wildcard protected tag. | |
32 | # | |
33 | # @example | |
34 | # Gitlab.protect_repository_tag(1, 'release-1-0') | |
35 | # Gitlab.protect_repository_tag(1, 'release-1-0', create_access_level: 30) | |
36 | # | |
37 | # @param [Integer, String] project(required) The ID or name of a project. | |
38 | # @param [String] name(required) The name of the tag or wildcard | |
39 | # @option options [Integer] :create_access_level Access levels allowed to create (defaults: 40, maintainer access level) | |
40 | # @return <Gitlab::ObjectifiedHash] Information about the protected repository tag | |
41 | def protect_repository_tag(project, name, options = {}) | |
42 | body = { name: name }.merge(options) | |
43 | post("/projects/#{url_encode project}/protected_tags", body: body) | |
44 | end | |
45 | ||
46 | # Unprotects the given protected tag or wildcard protected tag. | |
47 | # | |
48 | # @example | |
49 | # Gitlab.unprotect_repository_tag(1, 'release-1-0') | |
50 | # | |
51 | # @param [Integer, String] project(required) The ID or name of a project. | |
52 | # @param [String] name(required) The name of the tag or wildcard | |
53 | # @return [nil] This API call returns an empty response body. | |
54 | def unprotect_repository_tag(project, name) | |
55 | delete("/projects/#{url_encode project}/protected_tags/#{name}") | |
56 | end | |
57 | end | |
58 | end |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to repositories. |
2 | 4 | # @see https://docs.gitlab.com/ce/api/repositories.html |
12 | 14 | # @option options [String] :path The path inside repository. |
13 | 15 | # @option options [String] :ref_name The name of a repository branch or tag. |
14 | 16 | # @return [Gitlab::ObjectifiedHash] |
15 | def tree(project, options={}) | |
17 | def tree(project, options = {}) | |
16 | 18 | get("/projects/#{url_encode project}/repository/tree", query: options) |
17 | 19 | end |
18 | alias_method :repo_tree, :tree | |
20 | alias repo_tree tree | |
19 | 21 | |
20 | 22 | # Get project repository archive |
21 | 23 | # |
53 | 55 | def compare(project, from, to) |
54 | 56 | get("/projects/#{url_encode project}/repository/compare", query: { from: from, to: to }) |
55 | 57 | end |
56 | alias_method :repo_compare, :compare | |
58 | alias repo_compare compare | |
59 | ||
60 | # Get the common ancestor for 2 refs (commit SHAs, branch names or tags). | |
61 | # | |
62 | # @example | |
63 | # Gitlab.merge_base(42, ['master', 'feature/branch']) | |
64 | # Gitlab.merge_base(42, ['master', 'feature/branch']) | |
65 | # | |
66 | # @param [Integer, String] project The ID or URL-encoded path of the project. | |
67 | # @param [Array] refs Array containing 2 commit SHAs, branch names, or tags. | |
68 | # @return [Gitlab::ObjectifiedHash] | |
69 | def merge_base(project, refs) | |
70 | get("/projects/#{url_encode project}/repository/merge_base", query: { refs: refs }) | |
71 | end | |
57 | 72 | end |
58 | 73 | end |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | require 'base64' |
1 | 3 | |
2 | 4 | class Gitlab::Client |
13 | 15 | # @param [String] filepath The relative path of the file in the repository |
14 | 16 | # @param [String] ref The name of a repository branch or tag or if not given the default branch. |
15 | 17 | # @return [String] |
16 | def file_contents(project, filepath, ref='master') | |
18 | def file_contents(project, filepath, ref = 'master') | |
17 | 19 | get "/projects/#{url_encode project}/repository/files/#{url_encode filepath}/raw", |
18 | query: { ref: ref}, | |
20 | query: { ref: ref }, | |
19 | 21 | format: nil, |
20 | 22 | headers: { Accept: 'text/plain' }, |
21 | 23 | parser: ::Gitlab::Request::Parser |
22 | 24 | end |
23 | alias_method :repo_file_contents, :file_contents | |
25 | alias repo_file_contents file_contents | |
24 | 26 | |
25 | 27 | # Gets a repository file. |
26 | 28 | # |
0 | # frozen_string_literal: true | |
1 | ||
2 | class Gitlab::Client | |
3 | # Defines methods related to repository submodules. | |
4 | # @see https://docs.gitlab.com/ce/api/repository_submodules.html | |
5 | module RepositorySubmodules | |
6 | # Edits an existing repository submodule. | |
7 | # | |
8 | # @example | |
9 | # Gitlab.edit_file(42, "submodule", { | |
10 | # branch: "branch", | |
11 | # commit_sha: "3ddec28ea23acc5caa5d8331a6ecb2a65fc03e88", | |
12 | # commit_message: "commit message" | |
13 | # }) | |
14 | # | |
15 | # @param [Integer, String] project The ID or name of a project. | |
16 | # @param [String] submodule full path of submodule to update. | |
17 | # @param [Hash] options A customizable set of options. | |
18 | # @param options [String] :branch the name of the branch to commit changes to. | |
19 | # @param options [String] :commit_sha commit SHA to update the submodule to. | |
20 | # @param options [String] :commit_message commit message text. | |
21 | # @return [Gitlab::ObjectifiedHash] | |
22 | def edit_submodule(project, submodule, options = {}) | |
23 | put("/projects/#{url_encode project}/repository/submodules/#{url_encode submodule}", body: options) | |
24 | end | |
25 | end | |
26 | end |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to runners. |
2 | 4 | # @see https://docs.gitlab.com/ce/api/runners.html |
3 | 5 | module Runners |
4 | ||
5 | 6 | # Get a list of specific runners available to the user. |
6 | 7 | # @see https://docs.gitlab.com/ce/api/runners.html#list-owned-runners |
7 | 8 | # |
14 | 15 | # @option options [String] :scope The scope of specific runners to show, one of: active, paused, online; showing all runners if none provided |
15 | 16 | # @return [Array<Gitlab::ObjectifiedHash>] |
16 | 17 | def runners(options = {}) |
17 | get("/runners", query: options) | |
18 | get('/runners', query: options) | |
18 | 19 | end |
19 | 20 | |
20 | 21 | # Get a list of all runners in the GitLab instance (specific and shared). Access is restricted to users with admin privileges. |
27 | 28 | # @option options [String] :scope The scope of runners to show, one of: specific, shared, active, paused, online; showing all runners if none provided |
28 | 29 | # @return [Array<Gitlab::ObjectifiedHash>] |
29 | 30 | def all_runners(options = {}) |
30 | get("/runners/all", query: options) | |
31 | get('/runners/all', query: options) | |
31 | 32 | end |
32 | 33 | |
33 | 34 | # Get details of a runner.. |
55 | 56 | # @option options [String] :active The state of a runner; can be set to true or false. |
56 | 57 | # @option options [String] :tag_list The list of tags for a runner; put array of tags, that should be finally assigned to a runner |
57 | 58 | # @return <Gitlab::ObjectifiedHash> |
58 | def update_runner(id, options={}) | |
59 | def update_runner(id, options = {}) | |
59 | 60 | put("/runners/#{id}", query: options) |
60 | 61 | end |
61 | 62 | |
120 | 121 | def project_disable_runner(id, runner_id) |
121 | 122 | delete("/projects/#{url_encode id}/runners/#{runner_id}") |
122 | 123 | end |
123 | ||
124 | 124 | end |
125 | 125 | end |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Third party services connected to a project. |
2 | 4 | # @see https://docs.gitlab.com/ce/api/services.html |
42 | 44 | end |
43 | 45 | |
44 | 46 | private |
47 | ||
45 | 48 | def correct_service_name(service) |
46 | service.to_s.gsub('_', '-') | |
49 | service.to_s.tr('_', '-') | |
47 | 50 | end |
48 | 51 | end |
49 | 52 | end |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to sidekiq metrics. |
2 | 4 | # @see https://docs.gitlab.com/ce/api/sidekiq_metrics.html |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to snippets. |
2 | 4 | # @see https://docs.gitlab.com/ce/api/project_snippets.html |
11 | 13 | # @option options [Integer] :page The page number. |
12 | 14 | # @option options [Integer] :per_page The number of results per page. |
13 | 15 | # @return [Gitlab::ObjectifiedHash] |
14 | def snippets(project, options={}) | |
16 | def snippets(project, options = {}) | |
15 | 17 | get("/projects/#{url_encode project}/snippets", query: options) |
16 | 18 | end |
17 | 19 | |
40 | 42 | # @option options [String] :lifetime (optional) The expiration date of a snippet. |
41 | 43 | # @option options [String] :visibility (required) The visibility of a snippet |
42 | 44 | # @return [Gitlab::ObjectifiedHash] Information about created snippet. |
43 | def create_snippet(project, options={}) | |
45 | def create_snippet(project, options = {}) | |
44 | 46 | post("/projects/#{url_encode project}/snippets", body: options) |
45 | 47 | end |
46 | 48 | |
58 | 60 | # @option options [String] :lifetime The expiration date of a snippet. |
59 | 61 | # @option options [String] :visibility (optional) The visibility of a snippet |
60 | 62 | # @return [Gitlab::ObjectifiedHash] Information about updated snippet. |
61 | def edit_snippet(project, id, options={}) | |
63 | def edit_snippet(project, id, options = {}) | |
62 | 64 | put("/projects/#{url_encode project}/snippets/#{id}", body: options) |
63 | 65 | end |
64 | 66 |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to system hooks. |
2 | 4 | # @see https://docs.gitlab.com/ce/api/system_hooks.html |
11 | 13 | # @option options [Integer] :page The page number. |
12 | 14 | # @option options [Integer] :per_page The number of results per page. |
13 | 15 | # @return [Array<Gitlab::ObjectifiedHash>] |
14 | def hooks(options={}) | |
15 | get("/hooks", query: options) | |
16 | def hooks(options = {}) | |
17 | get('/hooks', query: options) | |
16 | 18 | end |
17 | alias_method :system_hooks, :hooks | |
19 | alias system_hooks hooks | |
18 | 20 | |
19 | 21 | # Adds a new system hook. |
20 | 22 | # |
28 | 30 | # @option options [boolean] :enable_ssl_verification `false` will cause Gitlab to ignore invalid/unsigned certificate errors (default is `true`) |
29 | 31 | # @return [Gitlab::ObjectifiedHash] |
30 | 32 | def add_hook(url, options = {}) |
31 | post("/hooks", body: options.merge(url: url)) | |
33 | post('/hooks', body: options.merge(url: url)) | |
32 | 34 | end |
33 | alias_method :add_system_hook, :add_hook | |
35 | alias add_system_hook add_hook | |
34 | 36 | |
35 | 37 | # Tests a system hook. |
36 | 38 | # |
43 | 45 | def hook(id) |
44 | 46 | get("/hooks/#{id}") |
45 | 47 | end |
46 | alias_method :system_hook, :hook | |
48 | alias system_hook hook | |
47 | 49 | |
48 | 50 | # Deletes a new system hook. |
49 | 51 | # |
56 | 58 | def delete_hook(id) |
57 | 59 | delete("/hooks/#{id}") |
58 | 60 | end |
59 | alias_method :delete_system_hook, :delete_hook | |
61 | alias delete_system_hook delete_hook | |
60 | 62 | end |
61 | 63 | end |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to tags. |
2 | 4 | # @see https://docs.gitlab.com/ce/api/tags.html |
11 | 13 | # @option options [Integer] :page The page number. |
12 | 14 | # @option options [Integer] :per_page The number of results per page. |
13 | 15 | # @return [Array<Gitlab::ObjectifiedHash>] |
14 | def tags(project, options={}) | |
16 | def tags(project, options = {}) | |
15 | 17 | get("/projects/#{url_encode project}/repository/tags", query: options) |
16 | 18 | end |
17 | alias_method :repo_tags, :tags | |
19 | alias repo_tags tags | |
18 | 20 | |
19 | 21 | # Creates a new project repository tag. |
20 | 22 | # |
28 | 30 | # @param [String] message Optional message for tag, creates annotated tag if specified. |
29 | 31 | # @param [String] description Optional release notes for tag. |
30 | 32 | # @return [Gitlab::ObjectifiedHash] |
31 | def create_tag(project, tag_name, ref, message='', description=nil) | |
33 | def create_tag(project, tag_name, ref, message = '', description = nil) | |
32 | 34 | post("/projects/#{url_encode project}/repository/tags", body: { tag_name: tag_name, ref: ref, message: message, release_description: description }) |
33 | 35 | end |
34 | alias_method :repo_create_tag, :create_tag | |
36 | alias repo_create_tag create_tag | |
35 | 37 | |
36 | 38 | # Gets information about a repository tag. |
37 | 39 | # |
45 | 47 | def tag(project, tag) |
46 | 48 | get("/projects/#{url_encode project}/repository/tags/#{url_encode tag}") |
47 | 49 | end |
48 | alias_method :repo_tag, :tag | |
50 | alias repo_tag tag | |
49 | 51 | |
50 | 52 | # Deletes a repository tag. Requires Gitlab >= 6.8.x |
51 | 53 | # |
59 | 61 | def delete_tag(project, tag) |
60 | 62 | delete("/projects/#{url_encode project}/repository/tags/#{url_encode tag}") |
61 | 63 | end |
62 | alias_method :repo_delete_tag, :delete_tag | |
64 | alias repo_delete_tag delete_tag | |
63 | 65 | |
64 | 66 | # Adds release notes to an existing repository tag. Requires Gitlab >= 8.2.0 |
65 | 67 | # |
74 | 76 | def create_release(project, tag, description) |
75 | 77 | post("/projects/#{url_encode project}/repository/tags/#{url_encode tag}/release", body: { description: description }) |
76 | 78 | end |
77 | alias_method :repo_create_release, :create_release | |
79 | alias repo_create_release create_release | |
78 | 80 | |
79 | 81 | # Updates the release notes of a given release. Requires Gitlab >= 8.2.0 |
80 | 82 | # |
89 | 91 | def update_release(project, tag, description) |
90 | 92 | put("/projects/#{url_encode project}/repository/tags/#{url_encode tag}/release", body: { description: description }) |
91 | 93 | end |
92 | alias_method :repo_update_release, :update_release | |
93 | ||
94 | alias repo_update_release update_release | |
94 | 95 | end |
95 | 96 | end |
0 | # frozen_string_literal: true | |
1 | ||
2 | class Gitlab::Client | |
3 | # Defines methods related to templates. | |
4 | # @see https://docs.gitlab.com/ce/api/templates/dockerfiles.html | |
5 | # @see https://docs.gitlab.com/ce/api/templates/gitignores.html | |
6 | # @see https://docs.gitlab.com/ce/api/templates/gitlab_ci_ymls.html | |
7 | # @see https://docs.gitlab.com/ce/api/templates/licenses.html | |
8 | module Templates | |
9 | # Get all Dockerfile templates. | |
10 | # | |
11 | # @example | |
12 | # Gitlab.dockerfile_templates | |
13 | # | |
14 | # @return [Array<Gitlab::ObjectifiedHash>] | |
15 | def dockerfile_templates | |
16 | get('/templates/dockerfiles') | |
17 | end | |
18 | ||
19 | # Get a single Dockerfile template. | |
20 | # | |
21 | # @example | |
22 | # Gitlab.dockerfile_template('Binary') | |
23 | # | |
24 | # @param [String] key The key of the Dockerfile template | |
25 | # @return [Gitlab::ObjectifiedHash] | |
26 | def dockerfile_template(key) | |
27 | get("/templates/dockerfiles/#{key}") | |
28 | end | |
29 | ||
30 | # Get all gitignore templates. | |
31 | # | |
32 | # @example | |
33 | # Gitlab.gitignore_templates | |
34 | # | |
35 | # @return [Array<Gitlab::ObjectifiedHash>] | |
36 | def gitignore_templates | |
37 | get('/templates/gitignores') | |
38 | end | |
39 | ||
40 | # Get a single gitignore template. | |
41 | # | |
42 | # @example | |
43 | # Gitlab.gitignore_template('Ruby') | |
44 | # | |
45 | # @param [String] key The key of the gitignore template | |
46 | # @return [Gitlab::ObjectifiedHash] | |
47 | def gitignore_template(key) | |
48 | get("/templates/gitignores/#{key}") | |
49 | end | |
50 | ||
51 | # Get all `gitlab_ci.yml` templates. | |
52 | # | |
53 | # @example | |
54 | # Gitlab.gitlab_ci_yml_templates | |
55 | # | |
56 | # @return [Array<Gitlab::ObjectifiedHash>] | |
57 | def gitlab_ci_yml_templates | |
58 | get('/templates/gitlab_ci_ymls') | |
59 | end | |
60 | ||
61 | # Get a single `gitlab_ci.yml` template. | |
62 | # | |
63 | # @example | |
64 | # Gitlab.gitlab_ci_yml_template('Ruby') | |
65 | # | |
66 | # @param [String] key The key of the gitlab_ci_yml template | |
67 | # @return [Gitlab::ObjectifiedHash] | |
68 | def gitlab_ci_yml_template(key) | |
69 | get("/templates/gitlab_ci_ymls/#{key}") | |
70 | end | |
71 | ||
72 | # Get all license templates. | |
73 | # | |
74 | # @example | |
75 | # Gitlab.license_templates | |
76 | # Gitlab.license_templates(popular: true) | |
77 | # | |
78 | # @param [Hash] options A customizable set of options. | |
79 | # @option options [Boolean] popular(optional) If passed, returns only popular licenses. | |
80 | # @return [Array<Gitlab::ObjectifiedHash>] | |
81 | def license_templates(options = {}) | |
82 | get('/templates/licenses', query: options) | |
83 | end | |
84 | ||
85 | # Get a single license template. You can pass parameters to replace the license placeholder. | |
86 | # | |
87 | # @example | |
88 | # Gitlab.license_template('Ruby') | |
89 | # | |
90 | # @param [String] key The key of the license template | |
91 | # @param [Hash] options A customizable set of options. | |
92 | # @option options [String] project(optional) The copyrighted project name. | |
93 | # @option options [String] fullname(optional) The full-name of the copyright holder | |
94 | # @return [Gitlab::ObjectifiedHash] | |
95 | def license_template(key, options = {}) | |
96 | get("/templates/licenses/#{key}", query: options) | |
97 | end | |
98 | end | |
99 | end |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to todos |
2 | # @see https://docs.gitlab.com/ce/api/todos.html | |
4 | # @see https://docs.gitlab.com/ce/api/todos.html | |
3 | 5 | module Todos |
4 | 6 | # Gets a list of todos. |
5 | 7 | # |
15 | 17 | # @option options [Integer] :state The state of the todo. Can be either `pending` or `done` |
16 | 18 | # @option options [Integer] :type The type of a todo. Can be either `Issue` or `MergeRequest` |
17 | 19 | # @return [Array<Gitlab::ObjectifiedHash>] |
18 | def todos(options={}) | |
19 | get("/todos", query: options) | |
20 | def todos(options = {}) | |
21 | get('/todos', query: options) | |
20 | 22 | end |
21 | 23 | |
22 | 24 | # Marks a single pending todo for the current user as done. |
37 | 39 | # |
38 | 40 | # @return [void] This API call returns an empty response body. |
39 | 41 | def mark_all_todos_as_done |
40 | post("/todos/mark_as_done") | |
42 | post('/todos/mark_as_done') | |
41 | 43 | end |
42 | 44 | end |
43 | end⏎ | |
45 | end |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | class Gitlab::Client |
1 | 3 | # Defines methods related to users. |
2 | 4 | # @see https://docs.gitlab.com/ce/api/users.html |
11 | 13 | # @option options [Integer] :page The page number. |
12 | 14 | # @option options [Integer] :per_page The number of results per page. |
13 | 15 | # @return [Array<Gitlab::ObjectifiedHash>] |
14 | def users(options={}) | |
15 | get("/users", query: options) | |
16 | def users(options = {}) | |
17 | get('/users', query: options) | |
16 | 18 | end |
17 | 19 | |
18 | 20 | # Gets information about a user. |
24 | 26 | # |
25 | 27 | # @param [Integer] id The ID of a user. |
26 | 28 | # @return [Gitlab::ObjectifiedHash] |
27 | def user(id=nil) | |
28 | id.to_i.zero? ? get("/user") : get("/users/#{id}") | |
29 | def user(id = nil) | |
30 | id.to_i.zero? ? get('/user') : get("/users/#{id}") | |
29 | 31 | end |
30 | 32 | |
31 | 33 | # Creates a new user. |
47 | 49 | # @option options [Integer] :projects_limit The limit of projects for a user. |
48 | 50 | # @return [Gitlab::ObjectifiedHash] Information about created user. |
49 | 51 | def create_user(*args) |
50 | options = Hash === args.last ? args.pop : {} | |
52 | options = args.last.is_a?(Hash) ? args.pop : {} | |
51 | 53 | body = if args[2] |
52 | 54 | { email: args[0], password: args[1], username: args[2] } |
53 | 55 | else |
72 | 74 | # @option options [String] :twitter The twitter of a user. |
73 | 75 | # @option options [Integer] :projects_limit The limit of projects for a user. |
74 | 76 | # @return [Gitlab::ObjectifiedHash] Information about created user. |
75 | def edit_user(user_id, options={}) | |
77 | def edit_user(user_id, options = {}) | |
76 | 78 | put("/users/#{user_id}", body: options) |
77 | 79 | end |
78 | 80 | |
119 | 121 | # @return [Gitlab::ObjectifiedHash] |
120 | 122 | # @note This method doesn't require private_token to be set. |
121 | 123 | def session(email, password) |
122 | post("/session", body: { email: email, password: password }, unauthenticated: true) | |
124 | post('/session', body: { email: email, password: password }, unauthenticated: true) | |
123 | 125 | end |
124 | 126 | |
125 | 127 | # Gets a list of user's SSH keys. |
133 | 135 | # @option options [Integer] :per_page The number of results per page. |
134 | 136 | # @option options [Integer] :user_id The ID of the user to retrieve the keys for. |
135 | 137 | # @return [Array<Gitlab::ObjectifiedHash>] |
136 | def ssh_keys(options={}) | |
138 | def ssh_keys(options = {}) | |
137 | 139 | user_id = options.delete :user_id |
138 | 140 | if user_id.to_i.zero? |
139 | get("/user/keys", query: options) | |
141 | get('/user/keys', query: options) | |
140 | 142 | else |
141 | 143 | get("/users/#{user_id}/keys", query: options) |
142 | 144 | end |
160 | 162 | # |
161 | 163 | # @param [String] title The title of an SSH key. |
162 | 164 | # @param [String] key The SSH key body. |
165 | # @param [Hash] options A customizable set of options. | |
166 | # @option options [Integer] :user_id id of the user to associate the key with | |
163 | 167 | # @return [Gitlab::ObjectifiedHash] Information about created SSH key. |
164 | def create_ssh_key(title, key) | |
165 | post("/user/keys", body: { title: title, key: key }) | |
168 | def create_ssh_key(title, key, options = {}) | |
169 | user_id = options.delete :user_id | |
170 | if user_id.to_i.zero? | |
171 | post('/user/keys', body: { title: title, key: key }) | |
172 | else | |
173 | post("/users/#{user_id}/keys", body: { title: title, key: key }) | |
174 | end | |
166 | 175 | end |
167 | 176 | |
168 | 177 | # Deletes an SSH key. |
171 | 180 | # Gitlab.delete_ssh_key(1) |
172 | 181 | # |
173 | 182 | # @param [Integer] id The ID of a user's SSH key. |
183 | # @param [Hash] options A customizable set of options. | |
184 | # @option options [Integer] :user_id id of the user to associate the key with | |
174 | 185 | # @return [Gitlab::ObjectifiedHash] Information about deleted SSH key. |
175 | def delete_ssh_key(id) | |
176 | delete("/user/keys/#{id}") | |
186 | def delete_ssh_key(id, options = {}) | |
187 | user_id = options.delete :user_id | |
188 | if user_id.to_i.zero? | |
189 | delete("/user/keys/#{id}") | |
190 | else | |
191 | delete("/users/#{user_id}/keys/#{id}") | |
192 | end | |
177 | 193 | end |
178 | 194 | |
179 | 195 | # Gets user emails. |
185 | 201 | # |
186 | 202 | # @param [Integer] user_id The ID of a user. |
187 | 203 | # @return [Gitlab::ObjectifiedHash] |
188 | def emails(user_id=nil) | |
189 | url = user_id.to_i.zero? ? "/user/emails" : "/users/#{user_id}/emails" | |
204 | def emails(user_id = nil) | |
205 | url = user_id.to_i.zero? ? '/user/emails' : "/users/#{user_id}/emails" | |
190 | 206 | get(url) |
191 | 207 | end |
192 | 208 | |
211 | 227 | # @param [String] email Email address |
212 | 228 | # @param [Integer] user_id The ID of a user. |
213 | 229 | # @return [Gitlab::ObjectifiedHash] |
214 | def add_email(email, user_id=nil) | |
215 | url = user_id.to_i.zero? ? "/user/emails" : "/users/#{user_id}/emails" | |
216 | post(url, body: {email: email}) | |
230 | def add_email(email, user_id = nil) | |
231 | url = user_id.to_i.zero? ? '/user/emails' : "/users/#{user_id}/emails" | |
232 | post(url, body: { email: email }) | |
217 | 233 | end |
218 | 234 | |
219 | 235 | # Delete email |
226 | 242 | # @param [Integer] id Email address ID |
227 | 243 | # @param [Integer] user_id The ID of a user. |
228 | 244 | # @return [Boolean] |
229 | def delete_email(id, user_id=nil) | |
245 | def delete_email(id, user_id = nil) | |
230 | 246 | url = user_id.to_i.zero? ? "/user/emails/#{id}" : "/users/#{user_id}/emails/#{id}" |
231 | 247 | delete(url) |
232 | 248 | end |
241 | 257 | # @option options [String] :per_page Number of user to return per page |
242 | 258 | # @option options [String] :page The page to retrieve |
243 | 259 | # @return [Array<Gitlab::ObjectifiedHash>] |
244 | def user_search(search, options={}) | |
260 | def user_search(search, options = {}) | |
245 | 261 | options[:search] = search |
246 | get("/users", query: options) | |
262 | get('/users', query: options) | |
247 | 263 | end |
248 | 264 | end |
249 | 265 | end |
0 | # frozen_string_literal: true | |
1 | ||
2 | class Gitlab::Client | |
3 | # Defines methods related to version | |
4 | # @see https://docs.gitlab.com/ce/api/version.html | |
5 | module Versions | |
6 | # Returns server version. | |
7 | # @see https://docs.gitlab.com/ce/api/version.html | |
8 | # | |
9 | # @example | |
10 | # Gitlab.version | |
11 | # | |
12 | # @return [Array<Gitlab::ObjectifiedHash>] | |
13 | def version | |
14 | get('/version') | |
15 | end | |
16 | end | |
17 | end |
0 | # frozen_string_literal: true | |
1 | ||
2 | class Gitlab::Client | |
3 | # Defines methods related to wikis. | |
4 | # @see https://docs.gitlab.com/ce/api/wikis.html | |
5 | module Wikis | |
6 | # Get all wiki pages for a given project. | |
7 | # | |
8 | # @example | |
9 | # Gitlab.wikis(3) | |
10 | # Gitlab.wikis(3, {with_content: 'Some wiki content'}) | |
11 | # | |
12 | # @param [Integer, String] project The ID or name of a project. | |
13 | # @param [Hash] options A customizable set of options. | |
14 | # @option options [String] with_content(optional) Include pages content | |
15 | # @return [Array<Gitlab::ObjectifiedHash>] | |
16 | def wikis(project, options = {}) | |
17 | get("/projects/#{url_encode project}/wikis", query: options) | |
18 | end | |
19 | ||
20 | # Get a wiki page for a given project. | |
21 | # | |
22 | # @example | |
23 | # Gitlab.wiki(3, 'home') | |
24 | # | |
25 | # @param [Integer, String] project The ID or name of a project. | |
26 | # @param [String] slug The slug (a unique string) of the wiki page | |
27 | # @return [Gitlab::ObjectifiedHash] | |
28 | def wiki(project, slug) | |
29 | get("/projects/#{url_encode project}/wikis/#{slug}") | |
30 | end | |
31 | ||
32 | # Creates a new wiki page for the given repository with the given title, slug, and content. | |
33 | # | |
34 | # @example | |
35 | # Gitlab.create_wiki(3, 'Some Title', 'Some Content') | |
36 | # Gitlab.create_wiki(3, 'Some Title', 'Some Content', { format: 'rdoc' }) | |
37 | # | |
38 | # @param [Integer, String] project The ID or name of a project. | |
39 | # @param [String] content The content of the wiki page. | |
40 | # @param [String] title The title of the wiki page. | |
41 | # @param [Hash] options A customizable set of options. | |
42 | # @option options [String] format (optional) The format of the wiki page. Available formats are: markdown (default), rdoc, and asciidoc. | |
43 | # @return [Gitlab::ObjectifiedHash] Information about created wiki page. | |
44 | def create_wiki(project, title, content, options = {}) | |
45 | body = { content: content, title: title }.merge(options) | |
46 | post("/projects/#{url_encode project}/wikis", body: body) | |
47 | end | |
48 | ||
49 | # Updates an existing wiki page. At least one parameter is required to update the wiki page. | |
50 | # | |
51 | # @example | |
52 | # Gitlab.update_wiki(6, 'home', { title: 'New title' }) | |
53 | # Gitlab.update_wiki(6, 'home', { title: 'New title', content: 'New Message', format: 'rdoc' }) | |
54 | # | |
55 | # @param [Integer, String] project The ID or name of a project. | |
56 | # @param [String] slug The slug (a unique string) of the wiki page. | |
57 | # @param [Hash] options A customizable set of options. | |
58 | # @option options [String] content The content of the wiki page. | |
59 | # @option options [String] title The title of the wiki page. | |
60 | # @option options [String] format (optional) The format of the wiki page. Available formats are: markdown (default), rdoc, and asciidoc. | |
61 | # @return [Gitlab::ObjectifiedHash] Information about updated wiki page. | |
62 | def update_wiki(project, slug, options = {}) | |
63 | put("/projects/#{url_encode project}/wikis/#{slug}", body: options) | |
64 | end | |
65 | ||
66 | # Deletes a wiki page with a given slug. | |
67 | # | |
68 | # @example | |
69 | # Gitlab.delete_wiki(42, 'foo') | |
70 | # | |
71 | # @param [Integer, String] project The ID or name of a project. | |
72 | # @param [String] slug The slug (a unique string) of the wiki page. | |
73 | # @return [Gitlab::ObjectifiedHash] An empty objectified hash | |
74 | def delete_wiki(project, slug) | |
75 | delete("/projects/#{url_encode project}/wikis/#{slug}") | |
76 | end | |
77 | end | |
78 | end |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | module Gitlab |
1 | 3 | # Wrapper for the Gitlab REST API. |
2 | 4 | class Client < API |
3 | Dir[File.expand_path('../client/*.rb', __FILE__)].each { |f| require f } | |
5 | Dir[File.expand_path('client/*.rb', __dir__)].each { |f| require f } | |
4 | 6 | |
5 | 7 | # Please keep in alphabetical order |
6 | 8 | include AccessRequests |
7 | 9 | include AwardEmojis |
8 | 10 | include Boards |
9 | 11 | include Branches |
12 | include BroadcastMessages | |
10 | 13 | include BuildVariables |
11 | 14 | include Builds |
12 | 15 | include Commits |
27 | 30 | include PipelineSchedules |
28 | 31 | include PipelineTriggers |
29 | 32 | include Pipelines |
33 | include ProjectBadges | |
30 | 34 | include Projects |
35 | include ProtectedTags | |
31 | 36 | include Repositories |
32 | 37 | include RepositoryFiles |
38 | include RepositorySubmodules | |
33 | 39 | include Runners |
34 | 40 | include Services |
35 | 41 | include Sidekiq |
36 | 42 | include Snippets |
37 | 43 | include SystemHooks |
38 | 44 | include Tags |
45 | include Templates | |
39 | 46 | include Todos |
40 | 47 | include Users |
48 | include Versions | |
49 | include Wikis | |
41 | 50 | |
42 | 51 | # Text representation of the client, masking private token. |
43 | 52 | # |
44 | 53 | # @return [String] |
45 | 54 | def inspect |
46 | 55 | inspected = super |
47 | ||
48 | if @private_token | |
49 | inspected = inspected.sub! @private_token, only_show_last_four_chars(@private_token) | |
50 | end | |
51 | ||
56 | inspected.sub! @private_token, only_show_last_four_chars(@private_token) if @private_token | |
52 | 57 | inspected |
53 | 58 | end |
54 | 59 | |
55 | def url_encode(s) | |
56 | URI.encode(s.to_s, /\W/) | |
60 | def url_encode(url) | |
61 | URI.encode(url.to_s, /\W/) | |
57 | 62 | end |
58 | 63 | |
59 | 64 | private |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | require 'gitlab/cli_helpers' |
1 | 3 | module Gitlab |
2 | 4 | # Defines constants and methods related to configuration. |
3 | 5 | module Configuration |
4 | 6 | # An array of valid keys in the options hash when configuring a Gitlab::API. |
5 | VALID_OPTIONS_KEYS = %i(endpoint private_token user_agent sudo httparty).freeze | |
7 | VALID_OPTIONS_KEYS = %i[endpoint private_token user_agent sudo httparty].freeze | |
6 | 8 | |
7 | 9 | # The user agent that will be sent to the API endpoint if none is set. |
8 | DEFAULT_USER_AGENT = "Gitlab Ruby Gem #{Gitlab::VERSION}".freeze | |
10 | DEFAULT_USER_AGENT = "Gitlab Ruby Gem #{Gitlab::VERSION}" | |
9 | 11 | |
10 | 12 | # @private |
11 | 13 | attr_accessor(*VALID_OPTIONS_KEYS) |
12 | 14 | # @private |
13 | alias_method :auth_token=, :private_token= | |
15 | alias auth_token= private_token= | |
14 | 16 | |
15 | 17 | # Sets all configuration options to their default values |
16 | 18 | # when this module is extended. |
43 | 45 | |
44 | 46 | # Allows HTTParty config to be specified in ENV using YAML hash. |
45 | 47 | def get_httparty_config(options) |
46 | return options if options.nil? | |
48 | return if options.nil? | |
47 | 49 | |
48 | 50 | httparty = Gitlab::CLI::Helpers.yaml_load(options) |
51 | raise ArgumentError, 'HTTParty config should be a Hash.' unless httparty.is_a? Hash | |
49 | 52 | |
50 | raise ArgumentError, 'HTTParty config should be a Hash.' unless httparty.is_a? Hash | |
51 | 53 | Gitlab::CLI::Helpers.symbolize_keys httparty |
52 | 54 | end |
53 | 55 | end |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | module Gitlab |
1 | 3 | module Error |
2 | 4 | # Custom error class for rescuing from all Gitlab errors. |
10 | 12 | |
11 | 13 | # Custom error class for rescuing from HTTP response errors. |
12 | 14 | class ResponseError < Error |
13 | POSSIBLE_MESSAGE_KEYS = %i(message error_description error) | |
15 | POSSIBLE_MESSAGE_KEYS = %i[message error_description error].freeze | |
14 | 16 | |
15 | 17 | def initialize(response) |
16 | 18 | @response = response |
56 | 58 | case message |
57 | 59 | when Gitlab::ObjectifiedHash |
58 | 60 | message.to_h.sort.map do |key, val| |
59 | "'#{key}' #{(val.is_a?(Hash) ? val.sort.map { |k, v| "(#{k}: #{v.join(' ')})" } : val).join(' ')}" | |
61 | "'#{key}' #{(val.is_a?(Hash) ? val.sort.map { |k, v| "(#{k}: #{v.join(' ')})" } : [val].flatten).join(' ')}" | |
60 | 62 | end.join(', ') |
61 | 63 | when Array |
62 | 64 | message.join(' ') |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | module Gitlab |
1 | 3 | # Wrapper class of file response. |
2 | 4 | class FileResponse |
3 | HEADER_CONTENT_DISPOSITION = 'Content-Disposition'.freeze | |
5 | HEADER_CONTENT_DISPOSITION = 'Content-Disposition' | |
4 | 6 | |
5 | 7 | attr_reader :filename |
6 | 8 | |
17 | 19 | def to_hash |
18 | 20 | { filename: @filename, data: @file } |
19 | 21 | end |
20 | alias_method :to_h, :to_hash | |
22 | alias to_h to_hash | |
21 | 23 | |
22 | 24 | # @return [String] Formatted string with the class name, object id and filename. |
23 | 25 | def inspect |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | require 'gitlab' |
1 | 3 | require 'gitlab/cli_helpers' |
2 | 4 | |
31 | 33 | # @return [String] |
32 | 34 | def ri_cmd |
33 | 35 | which_ri = `which ri`.chomp |
34 | if which_ri.empty? | |
35 | raise "'ri' tool not found in $PATH. Please install it to use the help." | |
36 | end | |
36 | raise "'ri' tool not found in $PATH. Please install it to use the help." if which_ri.empty? | |
37 | 37 | |
38 | 38 | which_ri |
39 | 39 | end |
46 | 46 | def help_map |
47 | 47 | @help_map ||= begin |
48 | 48 | actions.each_with_object({}) do |action, hsh| |
49 | key = client.method(action). | |
50 | owner.to_s.gsub(/Gitlab::(?:Client::)?/, '') | |
49 | key = client.method(action) | |
50 | .owner.to_s.gsub(/Gitlab::(?:Client::)?/, '') | |
51 | 51 | hsh[key] ||= [] |
52 | 52 | hsh[key] << action.to_s |
53 | 53 | end |
57 | 57 | # Table with available commands. |
58 | 58 | # |
59 | 59 | # @return [Terminal::Table] |
60 | def actions_table(topic=nil) | |
60 | def actions_table(topic = nil) | |
61 | 61 | rows = topic ? help_map[topic] : help_map.keys |
62 | 62 | table do |t| |
63 | 63 | t.title = topic || 'Help Topics' |
72 | 72 | |
73 | 73 | # Returns full namespace of a command (e.g. Gitlab::Client::Branches.cmd) |
74 | 74 | def namespace(cmd) |
75 | method_owners.select { |method| method[:name] == cmd }. | |
76 | map { |method| method[:owner] + '.' + method[:name] }. | |
77 | shift | |
75 | method_owners.select { |method| method[:name] == cmd } | |
76 | .map { |method| method[:owner] + '.' + method[:name] } | |
77 | .shift | |
78 | 78 | end |
79 | 79 | |
80 | 80 | # Massage output from 'ri'. |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | module Gitlab |
1 | 3 | # Converts hashes to the objects. |
2 | 4 | class ObjectifiedHash |
3 | 5 | # Creates a new ObjectifiedHash object. |
4 | 6 | def initialize(hash) |
5 | 7 | @hash = hash |
6 | @data = hash.inject({}) do |data, (key, value)| | |
8 | @data = hash.each_with_object({}) do |(key, value), data| | |
7 | 9 | value = ObjectifiedHash.new(value) if value.is_a? Hash |
8 | 10 | data[key.to_s] = value |
9 | data | |
10 | 11 | end |
11 | 12 | end |
12 | 13 | |
14 | 15 | def to_hash |
15 | 16 | @hash |
16 | 17 | end |
17 | alias_method :to_h, :to_hash | |
18 | alias to_h to_hash | |
18 | 19 | |
19 | 20 | # @return [String] Formatted string with the class name, object id and original hash. |
20 | 21 | def inspect |
23 | 24 | |
24 | 25 | # Delegate to ObjectifiedHash. |
25 | 26 | def method_missing(key) |
26 | @data.key?(key.to_s) ? @data[key.to_s] : nil | |
27 | @data.key?(key.to_s) ? @data[key.to_s] : super | |
27 | 28 | end |
28 | 29 | |
29 | 30 | def respond_to_missing?(method_name, include_private = false) |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | module Gitlab |
1 | 3 | # Parses link header. |
2 | 4 | # |
3 | 5 | # @private |
4 | 6 | class PageLinks |
5 | HEADER_LINK = 'Link'.freeze | |
6 | DELIM_LINKS = ','.freeze | |
7 | LINK_REGEX = /<([^>]+)>; rel=\"([^\"]+)\"/ | |
8 | METAS = %w(last next first prev).freeze | |
7 | HEADER_LINK = 'Link' | |
8 | DELIM_LINKS = ',' | |
9 | LINK_REGEX = /<([^>]+)>; rel=\"([^\"]+)\"/.freeze | |
10 | METAS = %w[last next first prev].freeze | |
9 | 11 | |
10 | 12 | attr_accessor(*METAS) |
11 | 13 | |
12 | 14 | def initialize(headers) |
13 | 15 | link_header = headers[HEADER_LINK] |
14 | 16 | |
15 | if link_header && link_header =~ /(next|first|last|prev)/ | |
16 | extract_links(link_header) | |
17 | end | |
17 | extract_links(link_header) if link_header && link_header =~ /(next|first|last|prev)/ | |
18 | 18 | end |
19 | 19 | |
20 | 20 | private |
22 | 22 | def extract_links(header) |
23 | 23 | header.split(DELIM_LINKS).each do |link| |
24 | 24 | LINK_REGEX.match(link.strip) do |match| |
25 | url, meta = match[1], match[2] | |
25 | url = match[1] | |
26 | meta = match[2] | |
26 | 27 | next if !url || !meta || METAS.index(meta).nil? |
28 | ||
27 | 29 | send("#{meta}=", url) |
28 | 30 | end |
29 | 31 | end |
0 | # frozen_string_literal: true | |
1 | ||
0 | 2 | module Gitlab |
1 | 3 | # Wrapper class of paginated response. |
2 | 4 | class PaginatedResponse |
53 | 55 | response |
54 | 56 | end |
55 | 57 | |
56 | def has_last_page? | |
58 | def last_page? | |
57 | 59 | !(@links.nil? || @links.last.nil?) |
58 | 60 | end |
61 | alias has_last_page? last_page? | |
59 | 62 | |
60 | 63 | def last_page |
61 | 64 | return nil if @client.nil? || !has_last_page? |
65 | ||
62 | 66 | path = @links.last.sub(/#{@client.endpoint}/, '') |
63 | 67 | @client.get(path) |
64 | 68 | end |
65 | 69 | |
66 | def has_first_page? | |
70 | def first_page? | |
67 | 71 | !(@links.nil? || @links.first.nil?) |
68 | 72 | end |
73 | alias has_first_page? first_page? | |
69 | 74 | |
70 | 75 | def first_page |
71 | 76 | return nil if @client.nil? || !has_first_page? |
77 | ||
72 | 78 | path = @links.first.sub(/#{@client.endpoint}/, '') |
73 | 79 | @client.get(path) |
74 | 80 | end |
75 | 81 | |
76 | def has_next_page? | |
82 | def next_page? | |
77 | 83 | !(@links.nil? || @links.next.nil?) |
78 | 84 | end |
85 | alias has_next_page? next_page? | |
79 | 86 | |
80 | 87 | def next_page |
81 | 88 | return nil if @client.nil? || !has_next_page? |