gitlab 4.2.0 → 4.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +4 -2
- data/LICENSE.txt +1 -1
- data/README.md +96 -25
- data/exe/gitlab +5 -1
- data/lib/gitlab/api.rb +8 -3
- data/lib/gitlab/cli.rb +15 -15
- data/lib/gitlab/cli_helpers.rb +63 -61
- data/lib/gitlab/client/access_requests.rb +103 -0
- data/lib/gitlab/client/application_settings.rb +172 -0
- data/lib/gitlab/client/avatar.rb +21 -0
- data/lib/gitlab/client/award_emojis.rb +5 -3
- data/lib/gitlab/client/boards.rb +62 -4
- data/lib/gitlab/client/branches.rb +53 -14
- data/lib/gitlab/client/broadcast_messages.rb +75 -0
- data/lib/gitlab/client/build_variables.rb +78 -9
- data/lib/gitlab/client/builds.rb +13 -11
- data/lib/gitlab/client/commits.rb +89 -19
- data/lib/gitlab/client/container_registry.rb +85 -0
- data/lib/gitlab/client/deployments.rb +34 -0
- data/lib/gitlab/client/environments.rb +5 -3
- data/lib/gitlab/client/epic_issues.rb +23 -0
- data/lib/gitlab/client/epics.rb +73 -0
- data/lib/gitlab/client/events.rb +60 -0
- data/lib/gitlab/client/features.rb +48 -0
- data/lib/gitlab/client/group_badges.rb +88 -0
- data/lib/gitlab/client/group_boards.rb +141 -0
- data/lib/gitlab/client/group_labels.rb +88 -0
- data/lib/gitlab/client/group_milestones.rb +94 -0
- data/lib/gitlab/client/groups.rb +197 -17
- data/lib/gitlab/client/issue_links.rb +48 -0
- data/lib/gitlab/client/issues.rb +98 -4
- data/lib/gitlab/client/jobs.rb +96 -8
- data/lib/gitlab/client/keys.rb +13 -0
- data/lib/gitlab/client/labels.rb +7 -5
- data/lib/gitlab/client/lint.rb +19 -0
- data/lib/gitlab/client/markdown.rb +23 -0
- data/lib/gitlab/client/merge_request_approvals.rb +265 -0
- data/lib/gitlab/client/merge_requests.rb +237 -9
- data/lib/gitlab/client/milestones.rb +19 -5
- data/lib/gitlab/client/namespaces.rb +4 -2
- data/lib/gitlab/client/notes.rb +58 -12
- data/lib/gitlab/client/pipeline_schedules.rb +147 -0
- data/lib/gitlab/client/pipeline_triggers.rb +12 -10
- data/lib/gitlab/client/pipelines.rb +40 -3
- data/lib/gitlab/client/project_badges.rb +85 -0
- data/lib/gitlab/client/project_clusters.rb +83 -0
- data/lib/gitlab/client/project_release_links.rb +76 -0
- data/lib/gitlab/client/project_releases.rb +79 -0
- data/lib/gitlab/client/projects.rb +280 -47
- data/lib/gitlab/client/protected_tags.rb +59 -0
- data/lib/gitlab/client/remote_mirrors.rb +51 -0
- data/lib/gitlab/client/repositories.rb +60 -6
- data/lib/gitlab/client/repository_files.rb +23 -5
- data/lib/gitlab/client/repository_submodules.rb +27 -0
- data/lib/gitlab/client/resource_label_events.rb +82 -0
- data/lib/gitlab/client/resource_state_events.rb +57 -0
- data/lib/gitlab/client/runners.rb +111 -15
- data/lib/gitlab/client/search.rb +66 -0
- data/lib/gitlab/client/services.rb +4 -1
- data/lib/gitlab/client/sidekiq.rb +39 -0
- data/lib/gitlab/client/snippets.rb +8 -4
- data/lib/gitlab/client/system_hooks.rb +9 -7
- data/lib/gitlab/client/tags.rb +15 -14
- data/lib/gitlab/client/templates.rb +100 -0
- data/lib/gitlab/client/todos.rb +7 -5
- data/lib/gitlab/client/user_snippets.rb +114 -0
- data/lib/gitlab/client/users.rb +166 -30
- data/lib/gitlab/client/versions.rb +18 -0
- data/lib/gitlab/client/wikis.rb +79 -0
- data/lib/gitlab/client.rb +49 -12
- data/lib/gitlab/configuration.rb +8 -6
- data/lib/gitlab/error.rb +74 -5
- data/lib/gitlab/file_response.rb +5 -3
- data/lib/gitlab/help.rb +19 -20
- data/lib/gitlab/objectified_hash.rb +27 -10
- data/lib/gitlab/page_links.rb +11 -9
- data/lib/gitlab/paginated_response.rb +37 -24
- data/lib/gitlab/request.rb +42 -53
- data/lib/gitlab/shell.rb +11 -12
- data/lib/gitlab/shell_history.rb +11 -13
- data/lib/gitlab/version.rb +3 -1
- data/lib/gitlab.rb +19 -8
- metadata +50 -395
- data/.gitignore +0 -22
- data/.travis.yml +0 -8
- data/CONTRIBUTING.md +0 -195
- data/Gemfile +0 -4
- data/Rakefile +0 -9
- data/bin/console +0 -10
- data/bin/setup +0 -6
- data/gitlab.gemspec +0 -31
- data/spec/fixtures/board_list.json +0 -1
- data/spec/fixtures/board_lists.json +0 -1
- data/spec/fixtures/boards.json +0 -1
- data/spec/fixtures/branch.json +0 -1
- data/spec/fixtures/branch_delete.json +0 -3
- data/spec/fixtures/branches.json +0 -1
- data/spec/fixtures/build.json +0 -38
- data/spec/fixtures/build_artifacts.json +0 -0
- data/spec/fixtures/build_cancel.json +0 -24
- data/spec/fixtures/build_erase.json +0 -24
- data/spec/fixtures/build_retry.json +0 -24
- data/spec/fixtures/builds.json +0 -78
- data/spec/fixtures/builds_commits.json +0 -64
- data/spec/fixtures/compare_merge_request_diff.json +0 -31
- data/spec/fixtures/empty.json +0 -0
- data/spec/fixtures/environment.json +0 -6
- data/spec/fixtures/environments.json +0 -14
- data/spec/fixtures/error_already_exists.json +0 -1
- data/spec/fixtures/error_project_not_found.json +0 -1
- data/spec/fixtures/get_repository_file.json +0 -1
- data/spec/fixtures/group.json +0 -60
- data/spec/fixtures/group_create.json +0 -1
- data/spec/fixtures/group_create_with_description.json +0 -1
- data/spec/fixtures/group_delete.json +0 -1
- data/spec/fixtures/group_member.json +0 -1
- data/spec/fixtures/group_member_delete.json +0 -1
- data/spec/fixtures/group_member_edit.json +0 -1
- data/spec/fixtures/group_members.json +0 -1
- data/spec/fixtures/group_projects.json +0 -44
- data/spec/fixtures/group_search.json +0 -2
- data/spec/fixtures/groups.json +0 -2
- data/spec/fixtures/issue.json +0 -1
- data/spec/fixtures/issue_award_emoji.json +0 -16
- data/spec/fixtures/issue_award_emojis.json +0 -34
- data/spec/fixtures/issues.json +0 -1
- data/spec/fixtures/job.json +0 -43
- data/spec/fixtures/job_trace.json +0 -1
- data/spec/fixtures/jobs.json +0 -91
- data/spec/fixtures/key.json +0 -1
- data/spec/fixtures/keys.json +0 -1
- data/spec/fixtures/label.json +0 -1
- data/spec/fixtures/label_unsubscribe.json +0 -1
- data/spec/fixtures/labels.json +0 -1
- data/spec/fixtures/merge_request.json +0 -1
- data/spec/fixtures/merge_request_award_emoji.json +0 -16
- data/spec/fixtures/merge_request_award_emojis.json +0 -34
- data/spec/fixtures/merge_request_changes.json +0 -1
- data/spec/fixtures/merge_request_closes_issues.json +0 -1
- data/spec/fixtures/merge_request_comment.json +0 -1
- data/spec/fixtures/merge_request_comments.json +0 -1
- data/spec/fixtures/merge_request_commits.json +0 -1
- data/spec/fixtures/merge_requests.json +0 -1
- data/spec/fixtures/milestone.json +0 -1
- data/spec/fixtures/milestone_issues.json +0 -1
- data/spec/fixtures/milestone_merge_requests.json +0 -1
- data/spec/fixtures/milestones.json +0 -1
- data/spec/fixtures/namespaces.json +0 -1
- data/spec/fixtures/note.json +0 -1
- data/spec/fixtures/note_award_emoji.json +0 -16
- data/spec/fixtures/note_award_emojis.json +0 -18
- data/spec/fixtures/notes.json +0 -1
- data/spec/fixtures/pipeline.json +0 -23
- data/spec/fixtures/pipeline_cancel.json +0 -23
- data/spec/fixtures/pipeline_create.json +0 -23
- data/spec/fixtures/pipeline_jobs.json +0 -91
- data/spec/fixtures/pipeline_retry.json +0 -23
- data/spec/fixtures/pipelines.json +0 -48
- data/spec/fixtures/project.json +0 -1
- data/spec/fixtures/project_commit.json +0 -13
- data/spec/fixtures/project_commit_comment.json +0 -1
- data/spec/fixtures/project_commit_comments.json +0 -1
- data/spec/fixtures/project_commit_create.json +0 -22
- data/spec/fixtures/project_commit_diff.json +0 -10
- data/spec/fixtures/project_commit_status.json +0 -42
- data/spec/fixtures/project_commits.json +0 -1
- data/spec/fixtures/project_edit.json +0 -21
- data/spec/fixtures/project_events.json +0 -1
- data/spec/fixtures/project_for_user.json +0 -1
- data/spec/fixtures/project_fork.json +0 -50
- data/spec/fixtures/project_fork_link.json +0 -1
- data/spec/fixtures/project_forked_for_user.json +0 -50
- data/spec/fixtures/project_hook.json +0 -1
- data/spec/fixtures/project_hooks.json +0 -1
- data/spec/fixtures/project_issues.json +0 -1
- data/spec/fixtures/project_key.json +0 -6
- data/spec/fixtures/project_keys.json +0 -6
- data/spec/fixtures/project_runner_enable.json +0 -7
- data/spec/fixtures/project_runners.json +0 -16
- data/spec/fixtures/project_search.json +0 -1
- data/spec/fixtures/project_star.json +0 -44
- data/spec/fixtures/project_tag_annotated.json +0 -1
- data/spec/fixtures/project_tag_lightweight.json +0 -1
- data/spec/fixtures/project_tags.json +0 -1
- data/spec/fixtures/project_unstar.json +0 -44
- data/spec/fixtures/project_update_commit_status.json +0 -20
- data/spec/fixtures/projects.json +0 -1
- data/spec/fixtures/push_rule.json +0 -1
- data/spec/fixtures/raw_file.json +0 -2
- data/spec/fixtures/release_create.json +0 -1
- data/spec/fixtures/release_update.json +0 -1
- data/spec/fixtures/repository_file.json +0 -1
- data/spec/fixtures/run_trigger.json +0 -1
- data/spec/fixtures/runner.json +0 -26
- data/spec/fixtures/runner_delete.json +0 -7
- data/spec/fixtures/runner_edit.json +0 -26
- data/spec/fixtures/runners.json +0 -16
- data/spec/fixtures/runners_all.json +0 -30
- data/spec/fixtures/service.json +0 -1
- data/spec/fixtures/session.json +0 -1
- data/spec/fixtures/shell_history.json +0 -2
- data/spec/fixtures/snippet.json +0 -1
- data/spec/fixtures/snippet_award_emoji.json +0 -16
- data/spec/fixtures/snippet_award_emojis.json +0 -34
- data/spec/fixtures/snippet_content.json +0 -3
- data/spec/fixtures/snippets.json +0 -1
- data/spec/fixtures/system_hook.json +0 -1
- data/spec/fixtures/system_hooks.json +0 -1
- data/spec/fixtures/tag.json +0 -1
- data/spec/fixtures/tag_create.json +0 -1
- data/spec/fixtures/tag_create_with_description.json +0 -1
- data/spec/fixtures/tag_delete.json +0 -1
- data/spec/fixtures/tags.json +0 -1
- data/spec/fixtures/team_member.json +0 -1
- data/spec/fixtures/team_members.json +0 -1
- data/spec/fixtures/todo.json +0 -73
- data/spec/fixtures/todos.json +0 -148
- data/spec/fixtures/tree.json +0 -1
- data/spec/fixtures/trigger.json +0 -10
- data/spec/fixtures/triggers.json +0 -12
- data/spec/fixtures/user.json +0 -1
- data/spec/fixtures/user_block_unblock.json +0 -1
- data/spec/fixtures/user_email.json +0 -1
- data/spec/fixtures/user_emails.json +0 -1
- data/spec/fixtures/user_search.json +0 -1
- data/spec/fixtures/users.json +0 -1
- data/spec/fixtures/variable.json +0 -4
- data/spec/fixtures/variables.json +0 -10
- data/spec/gitlab/cli_helpers_spec.rb +0 -57
- data/spec/gitlab/cli_spec.rb +0 -119
- data/spec/gitlab/client/award_emojis_spec.rb +0 -391
- data/spec/gitlab/client/boards_spec.rb +0 -94
- data/spec/gitlab/client/branches_spec.rb +0 -116
- data/spec/gitlab/client/build_variables_spec.rb +0 -86
- data/spec/gitlab/client/builds_spec.rb +0 -148
- data/spec/gitlab/client/client_spec.rb +0 -11
- data/spec/gitlab/client/commits_spec.rb +0 -168
- data/spec/gitlab/client/environments_spec.rb +0 -132
- data/spec/gitlab/client/groups_spec.rb +0 -195
- data/spec/gitlab/client/issues_spec.rb +0 -186
- data/spec/gitlab/client/jobs_spec.rb +0 -135
- data/spec/gitlab/client/keys_spec.rb +0 -19
- data/spec/gitlab/client/labels_spec.rb +0 -100
- data/spec/gitlab/client/merge_requests_spec.rb +0 -224
- data/spec/gitlab/client/milestones_spec.rb +0 -98
- data/spec/gitlab/client/namespaces_spec.rb +0 -22
- data/spec/gitlab/client/notes_spec.rb +0 -333
- data/spec/gitlab/client/pipeline_triggers_spec.rb +0 -157
- data/spec/gitlab/client/pipelines_spec.rb +0 -95
- data/spec/gitlab/client/projects_spec.rb +0 -613
- data/spec/gitlab/client/repositories_spec.rb +0 -94
- data/spec/gitlab/client/repository_files_spec.rb +0 -95
- data/spec/gitlab/client/runners_spec.rb +0 -185
- data/spec/gitlab/client/services_spec.rb +0 -55
- data/spec/gitlab/client/snippets_spec.rb +0 -100
- data/spec/gitlab/client/system_hooks_spec.rb +0 -69
- data/spec/gitlab/client/tags_spec.rb +0 -109
- data/spec/gitlab/client/todos_spec.rb +0 -45
- data/spec/gitlab/client/users_spec.rb +0 -418
- data/spec/gitlab/error_spec.rb +0 -45
- data/spec/gitlab/file_response_spec.rb +0 -33
- data/spec/gitlab/help_spec.rb +0 -46
- data/spec/gitlab/objectified_hash_spec.rb +0 -48
- data/spec/gitlab/page_links_spec.rb +0 -16
- data/spec/gitlab/paginated_response_spec.rb +0 -60
- data/spec/gitlab/request_spec.rb +0 -73
- data/spec/gitlab/shell_history_spec.rb +0 -53
- data/spec/gitlab/shell_spec.rb +0 -80
- data/spec/gitlab_spec.rb +0 -97
- data/spec/spec_helper.rb +0 -74
data/lib/gitlab/request.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'httparty'
|
|
2
4
|
require 'json'
|
|
3
5
|
|
|
@@ -6,8 +8,9 @@ module Gitlab
|
|
|
6
8
|
class Request
|
|
7
9
|
include HTTParty
|
|
8
10
|
format :json
|
|
11
|
+
maintain_method_across_redirects true
|
|
9
12
|
headers 'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded'
|
|
10
|
-
parser
|
|
13
|
+
parser(proc { |body, _| parse(body) })
|
|
11
14
|
|
|
12
15
|
attr_accessor :private_token, :endpoint
|
|
13
16
|
|
|
@@ -23,61 +26,49 @@ module Gitlab
|
|
|
23
26
|
true
|
|
24
27
|
elsif !body
|
|
25
28
|
false
|
|
26
|
-
elsif body.nil?
|
|
27
|
-
false
|
|
28
29
|
else
|
|
29
|
-
raise Error::Parsing
|
|
30
|
+
raise Error::Parsing, "Couldn't parse a response body"
|
|
30
31
|
end
|
|
31
32
|
end
|
|
32
33
|
|
|
33
34
|
# Decodes a JSON response into Ruby object.
|
|
34
35
|
def self.decode(response)
|
|
35
|
-
JSON.load
|
|
36
|
+
response ? JSON.load(response) : {}
|
|
36
37
|
rescue JSON::ParserError
|
|
37
|
-
raise Error::Parsing
|
|
38
|
+
raise Error::Parsing, 'The response is not a valid JSON'
|
|
38
39
|
end
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
validate self.class.get(@endpoint + path, options)
|
|
44
|
-
end
|
|
41
|
+
%w[get post put delete].each do |method|
|
|
42
|
+
define_method method do |path, options = {}|
|
|
43
|
+
params = options.dup
|
|
45
44
|
|
|
46
|
-
|
|
47
|
-
set_httparty_config(options)
|
|
48
|
-
set_authorization_header(options)
|
|
49
|
-
validate self.class.post(@endpoint + path, options)
|
|
50
|
-
end
|
|
45
|
+
httparty_config(params)
|
|
51
46
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
end
|
|
47
|
+
unless params[:unauthenticated]
|
|
48
|
+
params[:headers] ||= {}
|
|
49
|
+
params[:headers].merge!(authorization_header)
|
|
50
|
+
end
|
|
57
51
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
52
|
+
retries_left = params[:ratelimit_retries] || 3
|
|
53
|
+
begin
|
|
54
|
+
response = self.class.send(method, endpoint + path, params)
|
|
55
|
+
validate response
|
|
56
|
+
rescue Gitlab::Error::TooManyRequests => e
|
|
57
|
+
retries_left -= 1
|
|
58
|
+
raise e if retries_left.zero?
|
|
59
|
+
|
|
60
|
+
wait_time = response.headers['Retry-After'] || 2
|
|
61
|
+
sleep(wait_time.to_i)
|
|
62
|
+
retry
|
|
63
|
+
end
|
|
64
|
+
end
|
|
62
65
|
end
|
|
63
66
|
|
|
64
67
|
# Checks the response code for common errors.
|
|
65
68
|
# Returns parsed response for successful requests.
|
|
66
69
|
def validate(response)
|
|
67
|
-
error_klass =
|
|
68
|
-
|
|
69
|
-
when 401 then Error::Unauthorized
|
|
70
|
-
when 403 then Error::Forbidden
|
|
71
|
-
when 404 then Error::NotFound
|
|
72
|
-
when 405 then Error::MethodNotAllowed
|
|
73
|
-
when 409 then Error::Conflict
|
|
74
|
-
when 422 then Error::Unprocessable
|
|
75
|
-
when 500 then Error::InternalServerError
|
|
76
|
-
when 502 then Error::BadGateway
|
|
77
|
-
when 503 then Error::ServiceUnavailable
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
fail error_klass.new(response) if error_klass
|
|
70
|
+
error_klass = Error::STATUS_MAPPINGS[response.code]
|
|
71
|
+
raise error_klass, response if error_klass
|
|
81
72
|
|
|
82
73
|
parsed = response.parsed_response
|
|
83
74
|
parsed.client = self if parsed.respond_to?(:client=)
|
|
@@ -87,33 +78,31 @@ module Gitlab
|
|
|
87
78
|
|
|
88
79
|
# Sets a base_uri and default_params for requests.
|
|
89
80
|
# @raise [Error::MissingCredentials] if endpoint not set.
|
|
90
|
-
def
|
|
81
|
+
def request_defaults(sudo = nil)
|
|
82
|
+
raise Error::MissingCredentials, 'Please set an endpoint to API' unless endpoint
|
|
83
|
+
|
|
91
84
|
self.class.default_params sudo: sudo
|
|
92
|
-
raise Error::MissingCredentials.new("Please set an endpoint to API") unless @endpoint
|
|
93
85
|
self.class.default_params.delete(:sudo) if sudo.nil?
|
|
94
86
|
end
|
|
95
87
|
|
|
96
88
|
private
|
|
97
89
|
|
|
98
|
-
#
|
|
90
|
+
# Returns an Authorization header hash
|
|
99
91
|
#
|
|
100
|
-
# @param [Hash] options A customizable set of options.
|
|
101
|
-
# @option options [Boolean] :unauthenticated true if the API call does not require user authentication.
|
|
102
92
|
# @raise [Error::MissingCredentials] if private_token and auth_token are not set.
|
|
103
|
-
def
|
|
104
|
-
unless
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
end
|
|
93
|
+
def authorization_header
|
|
94
|
+
raise Error::MissingCredentials, 'Please provide a private_token or auth_token for user' unless private_token
|
|
95
|
+
|
|
96
|
+
if private_token.size < 21
|
|
97
|
+
{ 'PRIVATE-TOKEN' => private_token }
|
|
98
|
+
else
|
|
99
|
+
{ 'Authorization' => "Bearer #{private_token}" }
|
|
111
100
|
end
|
|
112
101
|
end
|
|
113
102
|
|
|
114
103
|
# Set HTTParty configuration
|
|
115
104
|
# @see https://github.com/jnunemaker/httparty
|
|
116
|
-
def
|
|
105
|
+
def httparty_config(options)
|
|
117
106
|
options.merge!(httparty) if httparty
|
|
118
107
|
end
|
|
119
108
|
end
|
data/lib/gitlab/shell.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'gitlab'
|
|
2
4
|
require 'gitlab/help'
|
|
3
5
|
require 'gitlab/cli_helpers'
|
|
@@ -15,7 +17,7 @@ class Gitlab::Shell
|
|
|
15
17
|
trap('INT') { quit_shell } # capture ctrl-c
|
|
16
18
|
setup
|
|
17
19
|
|
|
18
|
-
while buffer = Readline.readline('gitlab> ')
|
|
20
|
+
while (buffer = Readline.readline('gitlab> '))
|
|
19
21
|
begin
|
|
20
22
|
parse_input buffer
|
|
21
23
|
|
|
@@ -34,7 +36,7 @@ class Gitlab::Shell
|
|
|
34
36
|
data = execute command, arguments
|
|
35
37
|
output_table command, arguments, data
|
|
36
38
|
end
|
|
37
|
-
rescue => e
|
|
39
|
+
rescue StandardError => e
|
|
38
40
|
puts e.message
|
|
39
41
|
end
|
|
40
42
|
end
|
|
@@ -46,7 +48,7 @@ class Gitlab::Shell
|
|
|
46
48
|
buf = Shellwords.shellwords(buffer)
|
|
47
49
|
|
|
48
50
|
@command = buf.shift
|
|
49
|
-
@arguments = buf.count
|
|
51
|
+
@arguments = buf.count.positive? ? buf : []
|
|
50
52
|
end
|
|
51
53
|
|
|
52
54
|
def setup
|
|
@@ -62,14 +64,11 @@ class Gitlab::Shell
|
|
|
62
64
|
end
|
|
63
65
|
|
|
64
66
|
# Execute a given command with arguements
|
|
65
|
-
def execute(cmd=command, args=arguments)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
fail "Unknown command: #{cmd}. " \
|
|
71
|
-
"See the 'help' for a list of valid commands."
|
|
72
|
-
end
|
|
67
|
+
def execute(cmd = command, args = arguments)
|
|
68
|
+
raise "Unknown command: #{cmd}. See the 'help' for a list of valid commands." unless actions.include?(cmd.to_sym)
|
|
69
|
+
|
|
70
|
+
confirm_command(cmd)
|
|
71
|
+
gitlab_helper(cmd, args)
|
|
73
72
|
end
|
|
74
73
|
|
|
75
74
|
def quit_shell
|
|
@@ -80,5 +79,5 @@ class Gitlab::Shell
|
|
|
80
79
|
def history
|
|
81
80
|
@history ||= History.new
|
|
82
81
|
end
|
|
83
|
-
end
|
|
82
|
+
end
|
|
84
83
|
end
|
data/lib/gitlab/shell_history.rb
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class Gitlab::Shell
|
|
2
4
|
class History
|
|
3
5
|
DEFAULT_HISTFILESIZE = 200
|
|
4
6
|
DEFAULT_FILE_PATH = File.join(Dir.home, '.gitlab_shell_history')
|
|
5
7
|
|
|
6
|
-
def initialize(options={})
|
|
8
|
+
def initialize(options = {})
|
|
7
9
|
@file_path = options[:file_path] || DEFAULT_FILE_PATH
|
|
8
10
|
Readline::HISTORY.clear
|
|
9
11
|
end
|
|
@@ -13,13 +15,13 @@ class Gitlab::Shell
|
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
def save
|
|
16
|
-
lines.each { |line| history_file
|
|
18
|
+
lines.each { |line| history_file&.puts line }
|
|
17
19
|
end
|
|
18
20
|
|
|
19
21
|
def push(line)
|
|
20
22
|
Readline::HISTORY << line
|
|
21
23
|
end
|
|
22
|
-
|
|
24
|
+
alias << push
|
|
23
25
|
|
|
24
26
|
def lines
|
|
25
27
|
Readline::HISTORY.to_a.last(max_lines)
|
|
@@ -28,12 +30,8 @@ class Gitlab::Shell
|
|
|
28
30
|
private
|
|
29
31
|
|
|
30
32
|
def history_file
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
else
|
|
34
|
-
@history_file = File.open(history_file_path, 'w', 0600).tap do |file|
|
|
35
|
-
file.sync = true
|
|
36
|
-
end
|
|
33
|
+
@history_file ||= File.open(history_file_path, 'w', 0o600).tap do |file|
|
|
34
|
+
file.sync = true
|
|
37
35
|
end
|
|
38
36
|
rescue Errno::EACCES
|
|
39
37
|
warn 'History not saved; unable to open your history file for writing.'
|
|
@@ -44,12 +42,12 @@ class Gitlab::Shell
|
|
|
44
42
|
File.expand_path(@file_path)
|
|
45
43
|
end
|
|
46
44
|
|
|
47
|
-
def read_from_file
|
|
45
|
+
def read_from_file(&block)
|
|
48
46
|
path = history_file_path
|
|
49
47
|
|
|
50
|
-
File.foreach(path
|
|
51
|
-
rescue =>
|
|
52
|
-
warn "History file not loaded: #{
|
|
48
|
+
File.foreach(path, &block) if File.exist?(path)
|
|
49
|
+
rescue StandardError => e
|
|
50
|
+
warn "History file not loaded: #{e.message}"
|
|
53
51
|
end
|
|
54
52
|
|
|
55
53
|
def max_lines
|
data/lib/gitlab/version.rb
CHANGED
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,31 @@ 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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
if Gem::Version.new(RUBY_VERSION).release >= Gem::Version.new('3.0.0')
|
|
25
|
+
def self.method_missing(method, *args, **keywargs, &block)
|
|
26
|
+
return super unless client.respond_to?(method)
|
|
27
|
+
|
|
28
|
+
client.send(method, *args, **keywargs, &block)
|
|
29
|
+
end
|
|
30
|
+
else
|
|
31
|
+
def self.method_missing(method, *args, &block)
|
|
32
|
+
return super unless client.respond_to?(method)
|
|
33
|
+
|
|
34
|
+
client.send(method, *args, &block)
|
|
35
|
+
end
|
|
26
36
|
end
|
|
27
37
|
|
|
28
38
|
# Delegate to Gitlab::Client
|
|
29
|
-
def respond_to_missing?(method_name, include_private = false)
|
|
39
|
+
def self.respond_to_missing?(method_name, include_private = false)
|
|
30
40
|
client.respond_to?(method_name) || super
|
|
31
41
|
end
|
|
32
42
|
|
|
33
43
|
# Delegate to HTTParty.http_proxy
|
|
34
|
-
def self.http_proxy(address=nil, port=nil, username=nil, password=nil)
|
|
44
|
+
def self.http_proxy(address = nil, port = nil, username = nil, password = nil)
|
|
35
45
|
Gitlab::Request.http_proxy(address, port, username, password)
|
|
36
46
|
end
|
|
37
47
|
|
|
@@ -39,7 +49,8 @@ module Gitlab
|
|
|
39
49
|
#
|
|
40
50
|
# @return [Array<Symbol>]
|
|
41
51
|
def self.actions
|
|
42
|
-
hidden =
|
|
52
|
+
hidden =
|
|
53
|
+
/endpoint|private_token|auth_token|user_agent|sudo|get|post|put|\Adelete\z|validate\z|request_defaults|httparty/
|
|
43
54
|
(Gitlab::Client.instance_methods - Object.methods).reject { |e| e[hidden] }
|
|
44
55
|
end
|
|
45
56
|
end
|