gitlab 4.5.0 → 4.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/stale.yml +18 -0
- data/.rubocop_todo.yml +46 -0
- data/Gemfile +2 -0
- data/README.md +22 -22
- data/Rakefile +3 -5
- data/bin/console +1 -0
- data/exe/gitlab +5 -1
- data/gitlab.gemspec +9 -6
- data/lib/gitlab.rb +6 -3
- data/lib/gitlab/api.rb +5 -3
- data/lib/gitlab/cli.rb +11 -5
- data/lib/gitlab/cli_helpers.rb +31 -22
- data/lib/gitlab/client.rb +7 -8
- data/lib/gitlab/client/access_requests.rb +100 -93
- data/lib/gitlab/client/award_emojis.rb +127 -127
- data/lib/gitlab/client/boards.rb +82 -82
- data/lib/gitlab/client/branches.rb +89 -89
- data/lib/gitlab/client/build_variables.rb +117 -117
- data/lib/gitlab/client/builds.rb +98 -98
- data/lib/gitlab/client/commits.rb +154 -154
- data/lib/gitlab/client/deployments.rb +29 -29
- data/lib/gitlab/client/environments.rb +80 -80
- data/lib/gitlab/client/events.rb +54 -54
- data/lib/gitlab/client/group_milestones.rb +85 -86
- data/lib/gitlab/client/groups.rb +178 -178
- data/lib/gitlab/client/issues.rb +195 -196
- data/lib/gitlab/client/jobs.rb +150 -150
- data/lib/gitlab/client/keys.rb +14 -14
- data/lib/gitlab/client/labels.rb +79 -79
- data/lib/gitlab/client/merge_request_approvals.rb +102 -102
- data/lib/gitlab/client/merge_requests.rb +281 -256
- data/lib/gitlab/client/milestones.rb +85 -85
- data/lib/gitlab/client/namespaces.rb +18 -18
- data/lib/gitlab/client/notes.rb +260 -260
- data/lib/gitlab/client/pipeline_schedules.rb +123 -123
- data/lib/gitlab/client/pipeline_triggers.rb +93 -93
- data/lib/gitlab/client/pipelines.rb +62 -62
- data/lib/gitlab/client/projects.rb +526 -505
- data/lib/gitlab/client/repositories.rb +68 -55
- data/lib/gitlab/client/repository_files.rb +103 -103
- data/lib/gitlab/client/runners.rb +113 -115
- data/lib/gitlab/client/services.rb +46 -45
- data/lib/gitlab/client/sidekiq.rb +32 -32
- data/lib/gitlab/client/snippets.rb +86 -86
- data/lib/gitlab/client/system_hooks.rb +57 -57
- data/lib/gitlab/client/tags.rb +87 -88
- data/lib/gitlab/client/todos.rb +41 -41
- data/lib/gitlab/client/users.rb +242 -228
- data/lib/gitlab/client/versions.rb +16 -0
- data/lib/gitlab/configuration.rb +7 -5
- data/lib/gitlab/error.rb +3 -1
- data/lib/gitlab/file_response.rb +4 -2
- data/lib/gitlab/help.rb +9 -9
- data/lib/gitlab/objectified_hash.rb +5 -4
- data/lib/gitlab/page_links.rb +9 -7
- data/lib/gitlab/paginated_response.rb +14 -4
- data/lib/gitlab/request.rb +8 -5
- data/lib/gitlab/shell.rb +6 -4
- data/lib/gitlab/shell_history.rb +7 -5
- data/lib/gitlab/version.rb +3 -1
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2abe85ce03f9110e9d7c55e516487e125898a960de1c8f69ce752b12851a026
|
4
|
+
data.tar.gz: 9bda4675dc3a8e1c408ba68c366a14855f4456660001bff17bba98f06de9ca42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be06faf90e256343833177899f3064af39042cb7e299364f499cc29a0d903b62219d0dc80cf8588b956a424c43f01d58d28fd7bdba69609b5cf3c23a495f44f0
|
7
|
+
data.tar.gz: 412245730f19b0adc1f4fff19dd0e39373f7810ec00991e0303bf3287ac3f5d6b0dc2d132af93a09a272b254dc4c73fdadd29b2926e9e1761f55f66f4ef75f5e
|
data/.github/stale.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Number of days of inactivity before an issue becomes stale
|
2
|
+
daysUntilStale: 90
|
3
|
+
# Number of days of inactivity before a stale issue is closed
|
4
|
+
daysUntilClose: 10
|
5
|
+
# Issues with these labels will never be considered stale
|
6
|
+
exemptLabels:
|
7
|
+
- pinned
|
8
|
+
- security
|
9
|
+
- contribution welcome
|
10
|
+
# Label to use when marking an issue as stale
|
11
|
+
staleLabel: stale
|
12
|
+
# Comment to post when marking an issue as stale. Set to `false` to disable
|
13
|
+
markComment: >
|
14
|
+
This issue has been automatically marked as stale because it has not had
|
15
|
+
recent activity. It will be closed if no further activity occurs. Thank you
|
16
|
+
for your contributions.
|
17
|
+
# Comment to post when closing a stale issue. Set to `false` to disable
|
18
|
+
closeComment: false
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2018-10-10 10:25:27 +0400 using RuboCop version 0.59.2.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
Lint/UriEscapeUnescape:
|
11
|
+
Exclude:
|
12
|
+
- 'lib/gitlab/client.rb'
|
13
|
+
|
14
|
+
# Offense count: 5
|
15
|
+
Metrics/AbcSize:
|
16
|
+
Max: 34
|
17
|
+
|
18
|
+
# Offense count: 4
|
19
|
+
Metrics/CyclomaticComplexity:
|
20
|
+
Max: 14
|
21
|
+
|
22
|
+
# Offense count: 10
|
23
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
24
|
+
Metrics/MethodLength:
|
25
|
+
Max: 34
|
26
|
+
|
27
|
+
# Offense count: 2
|
28
|
+
# Configuration parameters: CountComments.
|
29
|
+
Metrics/ModuleLength:
|
30
|
+
Max: 165
|
31
|
+
|
32
|
+
# Offense count: 2
|
33
|
+
# Configuration parameters: CountKeywordArgs.
|
34
|
+
Metrics/ParameterLists:
|
35
|
+
Max: 6
|
36
|
+
|
37
|
+
# Offense count: 1
|
38
|
+
Metrics/PerceivedComplexity:
|
39
|
+
Max: 10
|
40
|
+
|
41
|
+
# Offense count: 1
|
42
|
+
# Cop supports --auto-correct.
|
43
|
+
# Configuration parameters: AutoCorrect.
|
44
|
+
Security/JSONLoad:
|
45
|
+
Exclude:
|
46
|
+
- 'lib/gitlab/request.rb'
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
# Gitlab
|
2
2
|
|
3
3
|
[![Build Status](https://img.shields.io/travis/NARKOZ/gitlab.svg)](https://travis-ci.org/NARKOZ/gitlab)
|
4
|
-
[![
|
5
|
-
[![Inline docs](
|
4
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/2e310b334b1b5db4a7e1/maintainability)](https://codeclimate.com/github/NARKOZ/gitlab)
|
5
|
+
[![Inline docs](https://inch-ci.org/github/NARKOZ/gitlab.svg)](https://inch-ci.org/github/NARKOZ/gitlab)
|
6
6
|
[![Gem version](https://img.shields.io/gem/v/gitlab.svg)](https://rubygems.org/gems/gitlab)
|
7
7
|
[![License](https://img.shields.io/badge/license-BSD-red.svg)](https://github.com/NARKOZ/gitlab/blob/master/LICENSE.txt)
|
8
8
|
|
9
|
-
[website](
|
10
|
-
[documentation](
|
9
|
+
[website](https://narkoz.github.io/gitlab) |
|
10
|
+
[documentation](https://rubydoc.info/gems/gitlab/frames) |
|
11
11
|
[gitlab-live](https://github.com/NARKOZ/gitlab-live)
|
12
12
|
|
13
13
|
Gitlab is a Ruby wrapper and CLI for the [GitLab API](https://docs.gitlab.com/ce/api/README.html).
|
14
|
-
As of version `4.0.0` this gem only supports Ruby 2.0+ and
|
14
|
+
As of version `4.0.0` this gem only supports Ruby 2.0+ and GitLab API v4.
|
15
15
|
|
16
16
|
## Installation
|
17
17
|
|
@@ -54,8 +54,8 @@ Usage examples:
|
|
54
54
|
|
55
55
|
```ruby
|
56
56
|
# set an API endpoint
|
57
|
-
Gitlab.endpoint = '
|
58
|
-
# => "
|
57
|
+
Gitlab.endpoint = 'https://example.net/api/v4'
|
58
|
+
# => "https://example.net/api/v4"
|
59
59
|
|
60
60
|
# set a user private token
|
61
61
|
Gitlab.private_token = 'qEsq1pt6HJPaNciie3MG'
|
@@ -63,7 +63,7 @@ Gitlab.private_token = 'qEsq1pt6HJPaNciie3MG'
|
|
63
63
|
|
64
64
|
# configure a proxy server
|
65
65
|
Gitlab.http_proxy('proxyhost', 8888)
|
66
|
-
# proxy server
|
66
|
+
# proxy server with basic auth
|
67
67
|
Gitlab.http_proxy('proxyhost', 8888, 'proxyuser', 'strongpasswordhere')
|
68
68
|
|
69
69
|
# list projects
|
@@ -108,11 +108,11 @@ end
|
|
108
108
|
projects.auto_paginate
|
109
109
|
```
|
110
110
|
|
111
|
-
For more information, refer to [documentation](
|
111
|
+
For more information, refer to [documentation](https://rubydoc.info/gems/gitlab/frames).
|
112
112
|
|
113
113
|
## CLI
|
114
114
|
|
115
|
-
It is possible to use this gem as a command line interface to
|
115
|
+
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
116
|
```sh
|
117
117
|
export GITLAB_API_ENDPOINT=https://gitlab.yourcompany.com/api/v4
|
118
118
|
export GITLAB_API_PRIVATE_TOKEN=<your private token from /profile/account>
|
@@ -124,21 +124,21 @@ export GITLAB_API_HTTPARTY_OPTIONS="{verify: false}"
|
|
124
124
|
|
125
125
|
Usage:
|
126
126
|
|
127
|
-
When you want to know which CLI commands are supported, take a look at the client [commands implemented in this gem](
|
127
|
+
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.
|
128
128
|
|
129
129
|
Usage examples:
|
130
130
|
|
131
131
|
```sh
|
132
132
|
# list users
|
133
|
-
# see:
|
133
|
+
# see: https://www.rubydoc.info/gems/gitlab/4.5.0/Gitlab/Client/Users#users-instance_method
|
134
134
|
gitlab users
|
135
135
|
|
136
136
|
# get current user
|
137
|
-
# see:
|
137
|
+
# see: https://www.rubydoc.info/gems/gitlab/4.5.0/Gitlab/Client/Users#user-instance_method
|
138
138
|
gitlab user
|
139
139
|
|
140
140
|
# get a user
|
141
|
-
# see:
|
141
|
+
# see: https://www.rubydoc.info/gems/gitlab/4.5.0/Gitlab/Client/Users#user-instance_method
|
142
142
|
gitlab user 2
|
143
143
|
|
144
144
|
# filter output
|
@@ -150,7 +150,7 @@ gitlab user --except=email,bio
|
|
150
150
|
gitlab user 2 --json
|
151
151
|
|
152
152
|
# passing options hash to a command (use YAML)
|
153
|
-
# see:
|
153
|
+
# see: https://www.rubydoc.info/gems/gitlab/4.5.0/Gitlab/Client/MergeRequests#create_merge_request-instance_method
|
154
154
|
gitlab create_merge_request 4 "New merge request" "{source_branch: 'new_branch', target_branch: 'master', assignee_id: 42}"
|
155
155
|
|
156
156
|
```
|
@@ -177,17 +177,17 @@ gitlab> create_merge_request 4 "New merge request" "{source_branch: 'new_branch'
|
|
177
177
|
```
|
178
178
|
|
179
179
|
Web version is available at https://gitlab-live.herokuapp.com
|
180
|
-
For more information, refer to [website](
|
180
|
+
For more information, refer to [website](https://narkoz.github.io/gitlab).
|
181
181
|
|
182
182
|
## Development
|
183
183
|
|
184
|
-
### With a dockerized
|
184
|
+
### With a dockerized GitLab instance
|
185
185
|
|
186
186
|
```shell
|
187
|
-
docker-compose up -d gitlab # Will start the
|
187
|
+
docker-compose up -d gitlab # Will start the GitLab instance in the background (approx. 3 minutes)
|
188
188
|
```
|
189
189
|
|
190
|
-
After a while, your
|
190
|
+
After a while, your GitLab instance will be accessible on http://localhost:3000.
|
191
191
|
|
192
192
|
Once you have set your new root password, you can login with the root user.
|
193
193
|
|
@@ -206,17 +206,17 @@ Gitlab.users
|
|
206
206
|
=> [#<Gitlab::ObjectifiedHash:47231290771040 {hash: {"id"=>1, "name"=>"Administrator", "username"=>"root", ...]
|
207
207
|
```
|
208
208
|
|
209
|
-
To launch the specs
|
209
|
+
To launch the specs:
|
210
210
|
|
211
211
|
```shell
|
212
212
|
docker-compose run app rake spec
|
213
213
|
```
|
214
214
|
|
215
|
-
#### Want to use
|
215
|
+
#### Want to use GitLab Enterprise?
|
216
216
|
|
217
217
|
Just change the image from `gitlab/gitlab-ce:latest` to `gitlab/gitlab-ee:latest` in the `docker-compose.yml` file.
|
218
218
|
|
219
|
-
### With an external
|
219
|
+
### With an external GitLab instance
|
220
220
|
|
221
221
|
First, set the variables to the correct values in the `docker.env` file.
|
222
222
|
|
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bundler/gem_tasks'
|
2
4
|
|
3
5
|
require 'rspec/core/rake_task'
|
@@ -10,8 +12,4 @@ RuboCop::RakeTask.new(:rubocop) do |task|
|
|
10
12
|
task.options = ['-D', '--parallel']
|
11
13
|
end
|
12
14
|
|
13
|
-
|
14
|
-
task default: :rubocop
|
15
|
-
else
|
16
|
-
task default: :spec
|
17
|
-
end
|
15
|
+
task default: :spec
|
data/bin/console
CHANGED
data/exe/gitlab
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
$LOAD_PATH.unshift File.expand_path('
|
4
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
|
5
|
+
|
6
|
+
# Exit cleanly from an early interrupt
|
7
|
+
Signal.trap('INT') { exit 1 }
|
4
8
|
|
5
9
|
require 'gitlab/cli'
|
6
10
|
|
data/gitlab.gemspec
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
5
|
require 'gitlab/version'
|
4
6
|
|
@@ -11,16 +13,17 @@ Gem::Specification.new do |gem|
|
|
11
13
|
gem.summary = 'A Ruby wrapper and CLI for the GitLab API'
|
12
14
|
gem.homepage = 'https://github.com/narkoz/gitlab'
|
13
15
|
|
14
|
-
gem.files = `git ls-files`.split($/)
|
15
|
-
|
16
|
-
%w[Dockerfile docker-compose.yml docker.env .travis.yml
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
.grep_v(/^spec/) -
|
18
|
+
%w[Dockerfile docker-compose.yml docker.env .travis.yml
|
19
|
+
.rubocop.yml .dockerignore]
|
17
20
|
gem.bindir = 'exe'
|
18
21
|
gem.executables = gem.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
22
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
23
|
gem.require_paths = ['lib']
|
21
24
|
gem.license = 'BSD'
|
22
25
|
|
23
|
-
gem.required_ruby_version = '>= 2.
|
26
|
+
gem.required_ruby_version = '>= 2.3'
|
24
27
|
|
25
28
|
gem.add_runtime_dependency 'httparty', '>= 0.14.0'
|
26
29
|
gem.add_runtime_dependency 'terminal-table', '>= 1.5.1'
|
@@ -28,6 +31,6 @@ Gem::Specification.new do |gem|
|
|
28
31
|
gem.add_development_dependency 'pry'
|
29
32
|
gem.add_development_dependency 'rake'
|
30
33
|
gem.add_development_dependency 'rspec'
|
31
|
-
gem.add_development_dependency 'webmock'
|
32
34
|
gem.add_development_dependency 'rubocop'
|
35
|
+
gem.add_development_dependency 'webmock'
|
33
36
|
end
|
data/lib/gitlab.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'gitlab/version'
|
2
4
|
require 'gitlab/objectified_hash'
|
3
5
|
require 'gitlab/configuration'
|
@@ -15,23 +17,24 @@ module Gitlab
|
|
15
17
|
# Alias for Gitlab::Client.new
|
16
18
|
#
|
17
19
|
# @return [Gitlab::Client]
|
18
|
-
def self.client(options={})
|
20
|
+
def self.client(options = {})
|
19
21
|
Gitlab::Client.new(options)
|
20
22
|
end
|
21
23
|
|
22
24
|
# Delegate to Gitlab::Client
|
23
25
|
def self.method_missing(method, *args, &block)
|
24
26
|
return super unless client.respond_to?(method)
|
27
|
+
|
25
28
|
client.send(method, *args, &block)
|
26
29
|
end
|
27
30
|
|
28
31
|
# Delegate to Gitlab::Client
|
29
|
-
def self.respond_to_missing?(method_name, include_private=false)
|
32
|
+
def self.respond_to_missing?(method_name, include_private = false)
|
30
33
|
client.respond_to?(method_name) || super
|
31
34
|
end
|
32
35
|
|
33
36
|
# Delegate to HTTParty.http_proxy
|
34
|
-
def self.http_proxy(address=nil, port=nil, username=nil, password=nil)
|
37
|
+
def self.http_proxy(address = nil, port = nil, username = nil, password = nil)
|
35
38
|
Gitlab::Request.http_proxy(address, port, username, password)
|
36
39
|
end
|
37
40
|
|
data/lib/gitlab/api.rb
CHANGED
@@ -1,19 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Gitlab
|
2
4
|
# @private
|
3
5
|
class API < Request
|
4
6
|
# @private
|
5
7
|
attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
|
6
8
|
# @private
|
7
|
-
|
9
|
+
alias auth_token= private_token=
|
8
10
|
|
9
11
|
# Creates a new API.
|
10
12
|
# @raise [Error:MissingCredentials]
|
11
|
-
def initialize(options={})
|
13
|
+
def initialize(options = {})
|
12
14
|
options = Gitlab.options.merge(options)
|
13
15
|
(Configuration::VALID_OPTIONS_KEYS + [:auth_token]).each do |key|
|
14
16
|
send("#{key}=", options[key]) if options[key]
|
15
17
|
end
|
16
|
-
request_defaults(
|
18
|
+
request_defaults(sudo)
|
17
19
|
self.class.headers 'User-Agent' => user_agent
|
18
20
|
end
|
19
21
|
end
|
data/lib/gitlab/cli.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'gitlab'
|
2
4
|
require 'terminal-table/import'
|
3
5
|
require_relative 'cli_helpers'
|
@@ -17,7 +19,11 @@ class Gitlab::CLI
|
|
17
19
|
#
|
18
20
|
# @param [Array] args The command and it's optional arguments.
|
19
21
|
def self.start(args)
|
20
|
-
command =
|
22
|
+
command = begin
|
23
|
+
args.shift.strip
|
24
|
+
rescue StandardError
|
25
|
+
'help'
|
26
|
+
end
|
21
27
|
run(command, args)
|
22
28
|
end
|
23
29
|
|
@@ -30,13 +36,13 @@ class Gitlab::CLI
|
|
30
36
|
# @param [String] cmd The name of a command.
|
31
37
|
# @param [Array] args The optional arguments for a command.
|
32
38
|
# @return [nil]
|
33
|
-
def self.run(cmd, args=[])
|
39
|
+
def self.run(cmd, args = [])
|
34
40
|
case cmd
|
35
41
|
when 'help'
|
36
42
|
puts help(args.shift) { |out| out.gsub!(/Gitlab\./, 'gitlab ') }
|
37
43
|
when 'info'
|
38
|
-
endpoint = Gitlab.endpoint
|
39
|
-
private_token = Gitlab.private_token
|
44
|
+
endpoint = Gitlab.endpoint || 'not set'
|
45
|
+
private_token = Gitlab.private_token || 'not set'
|
40
46
|
puts "Gitlab endpoint is #{endpoint}"
|
41
47
|
puts "Gitlab private token is #{private_token}"
|
42
48
|
puts "Ruby Version is #{RUBY_VERSION}"
|
@@ -60,7 +66,7 @@ class Gitlab::CLI
|
|
60
66
|
|
61
67
|
begin
|
62
68
|
command_args.map! { |arg| symbolize_keys(yaml_load(arg)) }
|
63
|
-
rescue => e
|
69
|
+
rescue StandardError => e
|
64
70
|
puts e.message
|
65
71
|
exit 1
|
66
72
|
end
|
data/lib/gitlab/cli_helpers.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'yaml'
|
2
4
|
require 'json'
|
3
5
|
require 'base64'
|
@@ -5,7 +7,7 @@ require 'base64'
|
|
5
7
|
class Gitlab::CLI
|
6
8
|
# Defines methods related to CLI output and formatting.
|
7
9
|
module Helpers
|
8
|
-
|
10
|
+
module_function
|
9
11
|
|
10
12
|
# Returns actions available to CLI & Shell
|
11
13
|
#
|
@@ -71,7 +73,7 @@ class Gitlab::CLI
|
|
71
73
|
|
72
74
|
puts 'Are you sure? (y/n)'
|
73
75
|
|
74
|
-
if %w
|
76
|
+
if %w[y yes].include?($stdin.gets.to_s.strip.downcase)
|
75
77
|
puts 'Proceeding..'
|
76
78
|
else
|
77
79
|
puts 'Command aborted.'
|
@@ -82,7 +84,7 @@ class Gitlab::CLI
|
|
82
84
|
# Gets defined help for a specific command/action.
|
83
85
|
#
|
84
86
|
# @return [String]
|
85
|
-
def help(cmd=nil, &block)
|
87
|
+
def help(cmd = nil, &block)
|
86
88
|
if cmd.nil? || Gitlab::Help.help_map.key?(cmd)
|
87
89
|
Gitlab::Help.actions_table(cmd)
|
88
90
|
else
|
@@ -90,14 +92,14 @@ class Gitlab::CLI
|
|
90
92
|
end
|
91
93
|
end
|
92
94
|
|
93
|
-
# Outputs a nicely formatted table or error
|
95
|
+
# Outputs a nicely formatted table or error message.
|
94
96
|
def output_table(cmd, args, data)
|
95
97
|
case data
|
96
98
|
when Gitlab::ObjectifiedHash, Gitlab::FileResponse
|
97
99
|
puts record_table([data], cmd, args)
|
98
100
|
when Gitlab::PaginatedResponse
|
99
101
|
puts record_table(data, cmd, args)
|
100
|
-
else # probably just an error
|
102
|
+
else # probably just an error message
|
101
103
|
puts data
|
102
104
|
end
|
103
105
|
end
|
@@ -159,7 +161,7 @@ class Gitlab::CLI
|
|
159
161
|
# @param [Array] args Options passed to the API call
|
160
162
|
# @param [bool] single_value If set to true, a single result should be returned
|
161
163
|
# @return [Hash] Result hash
|
162
|
-
def record_hash(data, cmd, args, single_value=false)
|
164
|
+
def record_hash(data, cmd, args, single_value = false)
|
163
165
|
if data.empty?
|
164
166
|
result = nil
|
165
167
|
else
|
@@ -169,21 +171,21 @@ class Gitlab::CLI
|
|
169
171
|
row = {}
|
170
172
|
|
171
173
|
keys.each do |key|
|
172
|
-
case hash[key]
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
174
|
+
row[key] = case hash[key]
|
175
|
+
when Hash
|
176
|
+
'Hash'
|
177
|
+
when StringIO
|
178
|
+
Base64.encode64(hash[key].read)
|
179
|
+
when nil
|
180
|
+
nil
|
181
|
+
else
|
182
|
+
hash[key]
|
183
|
+
end
|
182
184
|
end
|
183
185
|
|
184
186
|
result.push row
|
185
187
|
end
|
186
|
-
result = result[0] if single_value && result.count
|
188
|
+
result = result[0] if single_value && result.count.positive?
|
187
189
|
end
|
188
190
|
|
189
191
|
{
|
@@ -202,10 +204,10 @@ class Gitlab::CLI
|
|
202
204
|
end
|
203
205
|
|
204
206
|
# Helper function to call Gitlab commands with args.
|
205
|
-
def gitlab_helper(cmd, args=[])
|
207
|
+
def gitlab_helper(cmd, args = [])
|
206
208
|
begin
|
207
209
|
data = args.any? ? Gitlab.send(cmd, *args) : Gitlab.send(cmd)
|
208
|
-
rescue => e
|
210
|
+
rescue StandardError => e
|
209
211
|
puts e.message
|
210
212
|
yield if block_given?
|
211
213
|
end
|
@@ -217,9 +219,9 @@ class Gitlab::CLI
|
|
217
219
|
# @return [Hash]
|
218
220
|
def symbolize_keys(hash)
|
219
221
|
if hash.is_a?(Hash)
|
220
|
-
hash = hash.each_with_object({}) do |(key, value),
|
222
|
+
hash = hash.each_with_object({}) do |(key, value), new_hash|
|
221
223
|
begin
|
222
|
-
|
224
|
+
new_hash[key.to_sym] = symbolize_keys(value)
|
223
225
|
rescue NoMethodError
|
224
226
|
raise "Error: cannot convert hash key to symbol: #{key}"
|
225
227
|
end
|
@@ -229,9 +231,16 @@ class Gitlab::CLI
|
|
229
231
|
hash
|
230
232
|
end
|
231
233
|
|
234
|
+
# Check if arg is a color in 6-digit hex notation with leading '#' sign
|
235
|
+
def hex_color?(arg)
|
236
|
+
pattern = /\A#\h{6}\Z/
|
237
|
+
|
238
|
+
pattern.match(arg)
|
239
|
+
end
|
240
|
+
|
232
241
|
# YAML::load on a single argument
|
233
242
|
def yaml_load(arg)
|
234
|
-
YAML.safe_load(arg)
|
243
|
+
hex_color?(arg) ? arg : YAML.safe_load(arg)
|
235
244
|
rescue Psych::SyntaxError
|
236
245
|
raise "Error: Argument is not valid YAML syntax: #{arg}"
|
237
246
|
end
|