gitlab 4.2.0 → 4.18.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9a9218b2e2622283ff16c91d001d99d9f81e9ee7c6acd285a640553c8c8fd24f
|
4
|
+
data.tar.gz: 7603515dec3c85ea53cbef33acc9131d21605d9eab8f668476c36afa58837b76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec5e891011991391aaa42a86ef3c2506a1541c0c63526c820e1b67bafa17a743d7ce4f00531a074cf982be7b35d2d3a37eeb1ebab8cd619af67680c882dac708
|
7
|
+
data.tar.gz: 7ef86a70f12613923fa0dd59a87164f16cc50d4ebf114fb8bed9756a55b4ddb7363d26c9e3c2f4034c0e32ecda9805bc5577f006cfbb49f6c0d9530e196c7e04
|
data/CHANGELOG.md
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,17 +1,16 @@
|
|
1
1
|
# Gitlab
|
2
2
|
|
3
|
-
[![Build Status](https://img.shields.io/
|
4
|
-
[![
|
5
|
-
[![
|
6
|
-
[![
|
7
|
-
|
8
|
-
|
9
|
-
[
|
10
|
-
[documentation](http://rubydoc.info/gems/gitlab/frames) |
|
3
|
+
[![Build Status](https://img.shields.io/github/workflow/status/NARKOZ/gitlab/CI/master)](https://github.com/NARKOZ/gitlab/actions?query=workflow%3ARuby)
|
4
|
+
[![Inline docs](https://inch-ci.org/github/NARKOZ/gitlab.svg)](https://inch-ci.org/github/NARKOZ/gitlab)
|
5
|
+
[![Gem version](https://img.shields.io/gem/v/gitlab.svg)](https://rubygems.org/gems/gitlab)
|
6
|
+
[![License](https://img.shields.io/badge/license-BSD-red.svg)](https://github.com/NARKOZ/gitlab/blob/master/LICENSE.txt)
|
7
|
+
|
8
|
+
[website](https://narkoz.github.io/gitlab) |
|
9
|
+
[documentation](https://www.rubydoc.info/gems/gitlab/frames) |
|
11
10
|
[gitlab-live](https://github.com/NARKOZ/gitlab-live)
|
12
11
|
|
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
|
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 GitLab API v4.
|
15
14
|
|
16
15
|
## Installation
|
17
16
|
|
@@ -28,13 +27,19 @@ gem 'gitlab'
|
|
28
27
|
# gem 'gitlab', github: 'NARKOZ/gitlab'
|
29
28
|
```
|
30
29
|
|
30
|
+
Mac OS users can install using Homebrew (may not be the latest version):
|
31
|
+
|
32
|
+
```sh
|
33
|
+
brew install gitlab-gem
|
34
|
+
```
|
35
|
+
|
31
36
|
## Usage
|
32
37
|
|
33
38
|
Configuration example:
|
34
39
|
|
35
40
|
```ruby
|
36
41
|
Gitlab.configure do |config|
|
37
|
-
config.endpoint = 'https://example.net/api/v4' # API endpoint URL, default: ENV['GITLAB_API_ENDPOINT']
|
42
|
+
config.endpoint = 'https://example.net/api/v4' # API endpoint URL, default: ENV['GITLAB_API_ENDPOINT'] and falls back to ENV['CI_API_V4_URL']
|
38
43
|
config.private_token = 'qEsq1pt6HJPaNciie3MG' # user's private token or OAuth2 access token, default: ENV['GITLAB_API_PRIVATE_TOKEN']
|
39
44
|
# Optional
|
40
45
|
# config.user_agent = 'Custom User Agent' # user agent, default: 'Gitlab Ruby Gem [version]'
|
@@ -48,8 +53,8 @@ Usage examples:
|
|
48
53
|
|
49
54
|
```ruby
|
50
55
|
# set an API endpoint
|
51
|
-
Gitlab.endpoint = '
|
52
|
-
# => "
|
56
|
+
Gitlab.endpoint = 'https://example.net/api/v4'
|
57
|
+
# => "https://example.net/api/v4"
|
53
58
|
|
54
59
|
# set a user private token
|
55
60
|
Gitlab.private_token = 'qEsq1pt6HJPaNciie3MG'
|
@@ -57,15 +62,23 @@ Gitlab.private_token = 'qEsq1pt6HJPaNciie3MG'
|
|
57
62
|
|
58
63
|
# configure a proxy server
|
59
64
|
Gitlab.http_proxy('proxyhost', 8888)
|
60
|
-
# proxy server
|
65
|
+
# proxy server with basic auth
|
61
66
|
Gitlab.http_proxy('proxyhost', 8888, 'proxyuser', 'strongpasswordhere')
|
67
|
+
# set timeout for responses
|
68
|
+
ENV['GITLAB_API_HTTPARTY_OPTIONS'] = '{read_timeout: 60}'
|
62
69
|
|
63
70
|
# list projects
|
64
71
|
Gitlab.projects(per_page: 5)
|
65
72
|
# => [#<Gitlab::ObjectifiedHash:0x000000023326e0 @data={"id"=>1, "code"=>"brute", "name"=>"Brute", "description"=>nil, "path"=>"brute", "default_branch"=>nil, "owner"=>#<Gitlab::ObjectifiedHash:0x00000002331600 @data={"id"=>1, "email"=>"john@example.com", "name"=>"John Smith", "blocked"=>false, "created_at"=>"2012-09-17T09:41:56Z"}>, "private"=>true, "issues_enabled"=>true, "merge_requests_enabled"=>true, "wall_enabled"=>true, "wiki_enabled"=>true, "created_at"=>"2012-09-17T09:41:56Z"}>, #<Gitlab::ObjectifiedHash:0x000000023450d8 @data={"id"=>2, "code"=>"mozart", "name"=>"Mozart", "description"=>nil, "path"=>"mozart", "default_branch"=>nil, "owner"=>#<Gitlab::ObjectifiedHash:0x00000002344ca0 @data={"id"=>1, "email"=>"john@example.com", "name"=>"John Smith", "blocked"=>false, "created_at"=>"2012-09-17T09:41:56Z"}>, "private"=>true, "issues_enabled"=>true, "merge_requests_enabled"=>true, "wall_enabled"=>true, "wiki_enabled"=>true, "created_at"=>"2012-09-17T09:41:57Z"}>, #<Gitlab::ObjectifiedHash:0x00000002344958 @data={"id"=>3, "code"=>"gitlab", "name"=>"Gitlab", "description"=>nil, "path"=>"gitlab", "default_branch"=>nil, "owner"=>#<Gitlab::ObjectifiedHash:0x000000023447a0 @data={"id"=>1, "email"=>"john@example.com", "name"=>"John Smith", "blocked"=>false, "created_at"=>"2012-09-17T09:41:56Z"}>, "private"=>true, "issues_enabled"=>true, "merge_requests_enabled"=>true, "wall_enabled"=>true, "wiki_enabled"=>true, "created_at"=>"2012-09-17T09:41:58Z"}>]
|
66
73
|
|
67
|
-
# initialize a new client
|
68
|
-
g = Gitlab.client(
|
74
|
+
# initialize a new client with custom headers
|
75
|
+
g = Gitlab.client(
|
76
|
+
endpoint: 'https://example.com/api/v4',
|
77
|
+
private_token: 'qEsq1pt6HJPaNciie3MG',
|
78
|
+
httparty: {
|
79
|
+
headers: { 'Cookie' => 'gitlab_canary=true' }
|
80
|
+
}
|
81
|
+
)
|
69
82
|
# => #<Gitlab::Client:0x00000001e62408 @endpoint="https://api.example.com", @private_token="qEsq1pt6HJPaNciie3MG", @user_agent="Gitlab Ruby Gem 2.0.0">
|
70
83
|
|
71
84
|
# get a user
|
@@ -102,14 +115,14 @@ end
|
|
102
115
|
projects.auto_paginate
|
103
116
|
```
|
104
117
|
|
105
|
-
For more information, refer to [documentation](
|
118
|
+
For more information, refer to [documentation](https://www.rubydoc.info/gems/gitlab/frames).
|
106
119
|
|
107
120
|
## CLI
|
108
121
|
|
109
|
-
It is possible to use this gem as a command line interface to
|
122
|
+
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:
|
110
123
|
```sh
|
111
124
|
export GITLAB_API_ENDPOINT=https://gitlab.yourcompany.com/api/v4
|
112
|
-
export GITLAB_API_PRIVATE_TOKEN=<your private token from /profile/account>
|
125
|
+
export GITLAB_API_PRIVATE_TOKEN=<your private token from /profile/account or /profile/personal_access_tokens in newer version>
|
113
126
|
# This one is optional and can be used to set any HTTParty option you may need
|
114
127
|
# using YAML hash syntax. For example, this is how you would disable SSL
|
115
128
|
# verification (useful if using a self-signed cert).
|
@@ -118,21 +131,21 @@ export GITLAB_API_HTTPARTY_OPTIONS="{verify: false}"
|
|
118
131
|
|
119
132
|
Usage:
|
120
133
|
|
121
|
-
When you want to know which CLI commands are supported, take a look at the client [commands implemented in this gem](
|
134
|
+
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.
|
122
135
|
|
123
136
|
Usage examples:
|
124
137
|
|
125
138
|
```sh
|
126
139
|
# list users
|
127
|
-
# see:
|
140
|
+
# see: https://www.rubydoc.info/gems/gitlab/4.5.0/Gitlab/Client/Users#users-instance_method
|
128
141
|
gitlab users
|
129
142
|
|
130
143
|
# get current user
|
131
|
-
# see:
|
144
|
+
# see: https://www.rubydoc.info/gems/gitlab/4.5.0/Gitlab/Client/Users#user-instance_method
|
132
145
|
gitlab user
|
133
146
|
|
134
147
|
# get a user
|
135
|
-
# see:
|
148
|
+
# see: https://www.rubydoc.info/gems/gitlab/4.5.0/Gitlab/Client/Users#user-instance_method
|
136
149
|
gitlab user 2
|
137
150
|
|
138
151
|
# filter output
|
@@ -144,7 +157,7 @@ gitlab user --except=email,bio
|
|
144
157
|
gitlab user 2 --json
|
145
158
|
|
146
159
|
# passing options hash to a command (use YAML)
|
147
|
-
# see:
|
160
|
+
# see: https://www.rubydoc.info/gems/gitlab/4.5.0/Gitlab/Client/MergeRequests#create_merge_request-instance_method
|
148
161
|
gitlab create_merge_request 4 "New merge request" "{source_branch: 'new_branch', target_branch: 'master', assignee_id: 42}"
|
149
162
|
|
150
163
|
```
|
@@ -171,10 +184,68 @@ gitlab> create_merge_request 4 "New merge request" "{source_branch: 'new_branch'
|
|
171
184
|
```
|
172
185
|
|
173
186
|
Web version is available at https://gitlab-live.herokuapp.com
|
174
|
-
For more information, refer to [website](
|
187
|
+
For more information, refer to [website](https://narkoz.github.io/gitlab).
|
175
188
|
|
176
189
|
## Development
|
177
190
|
|
191
|
+
### With a dockerized GitLab instance
|
192
|
+
|
193
|
+
```shell
|
194
|
+
docker-compose up -d gitlab # Will start the GitLab instance in the background (approx. 3 minutes)
|
195
|
+
```
|
196
|
+
|
197
|
+
After a while, your GitLab instance will be accessible on http://localhost:3000.
|
198
|
+
|
199
|
+
Once you have set your new root password, you can login with the root user.
|
200
|
+
|
201
|
+
You can now setup a personal access token here: http://localhost:3000/profile/personal_access_tokens
|
202
|
+
|
203
|
+
Once you have your token, set the variables to the correct values in the `docker.env` file.
|
204
|
+
|
205
|
+
Then, launch the tool:
|
206
|
+
|
207
|
+
```shell
|
208
|
+
docker-compose run app
|
209
|
+
```
|
210
|
+
|
211
|
+
```ruby
|
212
|
+
Gitlab.users
|
213
|
+
=> [#<Gitlab::ObjectifiedHash:47231290771040 {hash: {"id"=>1, "name"=>"Administrator", "username"=>"root", ...]
|
214
|
+
```
|
215
|
+
|
216
|
+
To launch the specs:
|
217
|
+
|
218
|
+
```shell
|
219
|
+
docker-compose run app rake spec
|
220
|
+
```
|
221
|
+
|
222
|
+
#### Want to use GitLab Enterprise?
|
223
|
+
|
224
|
+
Just change the image from `gitlab/gitlab-ce:latest` to `gitlab/gitlab-ee:latest` in the `docker-compose.yml` file.
|
225
|
+
|
226
|
+
### With an external GitLab instance
|
227
|
+
|
228
|
+
First, set the variables to the correct values in the `docker.env` file.
|
229
|
+
|
230
|
+
Then, launch the tool:
|
231
|
+
|
232
|
+
```shell
|
233
|
+
docker-compose run app
|
234
|
+
```
|
235
|
+
|
236
|
+
```ruby
|
237
|
+
Gitlab.users
|
238
|
+
=> [#<Gitlab::ObjectifiedHash:47231290771040 {hash: {"id"=>1, "name"=>"Administrator", "username"=>"root", ...]
|
239
|
+
```
|
240
|
+
|
241
|
+
To launch the specs,
|
242
|
+
|
243
|
+
```shell
|
244
|
+
docker-compose run app rake spec
|
245
|
+
```
|
246
|
+
|
247
|
+
### Without Docker
|
248
|
+
|
178
249
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
179
250
|
`rake spec` to run the tests. You can also run `bin/console` for an interactive
|
180
251
|
prompt that will allow you to experiment.
|
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/lib/gitlab/api.rb
CHANGED
@@ -1,19 +1,24 @@
|
|
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
|
-
|
13
|
+
# rubocop:disable Lint/MissingSuper
|
14
|
+
def initialize(options = {})
|
12
15
|
options = Gitlab.options.merge(options)
|
13
16
|
(Configuration::VALID_OPTIONS_KEYS + [:auth_token]).each do |key|
|
14
17
|
send("#{key}=", options[key]) if options[key]
|
15
18
|
end
|
16
|
-
|
19
|
+
request_defaults(sudo)
|
20
|
+
self.class.headers 'User-Agent' => user_agent
|
17
21
|
end
|
22
|
+
# rubocop:enable Lint/MissingSuper
|
18
23
|
end
|
19
24
|
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'
|
@@ -6,9 +8,6 @@ require_relative 'shell'
|
|
6
8
|
class Gitlab::CLI
|
7
9
|
extend Helpers
|
8
10
|
|
9
|
-
# If set to true, JSON will be rendered as output
|
10
|
-
@render_json = false
|
11
|
-
|
12
11
|
# Starts a new CLI session.
|
13
12
|
#
|
14
13
|
# @example
|
@@ -17,7 +16,11 @@ class Gitlab::CLI
|
|
17
16
|
#
|
18
17
|
# @param [Array] args The command and it's optional arguments.
|
19
18
|
def self.start(args)
|
20
|
-
command =
|
19
|
+
command = begin
|
20
|
+
args.shift.strip
|
21
|
+
rescue StandardError
|
22
|
+
'help'
|
23
|
+
end
|
21
24
|
run(command, args)
|
22
25
|
end
|
23
26
|
|
@@ -30,13 +33,13 @@ class Gitlab::CLI
|
|
30
33
|
# @param [String] cmd The name of a command.
|
31
34
|
# @param [Array] args The optional arguments for a command.
|
32
35
|
# @return [nil]
|
33
|
-
def self.run(cmd, args=[])
|
36
|
+
def self.run(cmd, args = [])
|
34
37
|
case cmd
|
35
38
|
when 'help'
|
36
39
|
puts help(args.shift) { |out| out.gsub!(/Gitlab\./, 'gitlab ') }
|
37
40
|
when 'info'
|
38
|
-
endpoint = Gitlab.endpoint
|
39
|
-
private_token = Gitlab.private_token
|
41
|
+
endpoint = Gitlab.endpoint || 'not set'
|
42
|
+
private_token = Gitlab.private_token || 'not set'
|
40
43
|
puts "Gitlab endpoint is #{endpoint}"
|
41
44
|
puts "Gitlab private token is #{private_token}"
|
42
45
|
puts "Ruby Version is #{RUBY_VERSION}"
|
@@ -52,19 +55,16 @@ class Gitlab::CLI
|
|
52
55
|
end
|
53
56
|
|
54
57
|
unless valid_command?(cmd)
|
55
|
-
puts
|
58
|
+
puts 'Unknown command. Run `gitlab help` for a list of available commands.'
|
59
|
+
exit(0) if ENV['CI'] # FIXME: workaround to exit with 0 on passed specs
|
56
60
|
exit(1)
|
57
61
|
end
|
58
62
|
|
59
|
-
|
60
|
-
command_args = args[0..-2]
|
61
|
-
else
|
62
|
-
command_args = args
|
63
|
-
end
|
63
|
+
command_args = args.any? && args.last.start_with?('--only=', '--except=') ? args[0..-2] : args
|
64
64
|
|
65
65
|
begin
|
66
66
|
command_args.map! { |arg| symbolize_keys(yaml_load(arg)) }
|
67
|
-
rescue => e
|
67
|
+
rescue StandardError => e
|
68
68
|
puts e.message
|
69
69
|
exit 1
|
70
70
|
end
|
@@ -80,7 +80,7 @@ class Gitlab::CLI
|
|
80
80
|
# Helper method that checks whether we want to get the output as json
|
81
81
|
# @return [nil]
|
82
82
|
def self.render_output(cmd, args, data)
|
83
|
-
if @json_output
|
83
|
+
if defined?(@json_output) && @json_output
|
84
84
|
output_json(cmd, args, data)
|
85
85
|
else
|
86
86
|
output_table(cmd, args, data)
|
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
|
#
|
@@ -37,22 +39,23 @@ class Gitlab::CLI
|
|
37
39
|
#
|
38
40
|
# @return [Array]
|
39
41
|
def required_fields(args)
|
40
|
-
|
41
|
-
args.last.gsub('--only=', '').split(',')
|
42
|
-
else
|
43
|
-
[]
|
44
|
-
end
|
42
|
+
filtered_fields(args, '--only=')
|
45
43
|
end
|
46
44
|
|
47
45
|
# Returns filtered excluded fields.
|
48
46
|
#
|
49
47
|
# @return [Array]
|
50
48
|
def excluded_fields(args)
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
49
|
+
filtered_fields(args, '--except=')
|
50
|
+
end
|
51
|
+
|
52
|
+
# Returns fields filtered by a keyword.
|
53
|
+
#
|
54
|
+
# @return [Array]
|
55
|
+
def filtered_fields(args, key)
|
56
|
+
return [] unless args.any? && args.last.is_a?(String) && args.last.start_with?(key)
|
57
|
+
|
58
|
+
args.last.gsub(key, '').split(',')
|
56
59
|
end
|
57
60
|
|
58
61
|
# Confirms command is valid.
|
@@ -67,21 +70,22 @@ class Gitlab::CLI
|
|
67
70
|
#
|
68
71
|
# @return [String]
|
69
72
|
def confirm_command(cmd)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
73
|
+
return unless cmd.start_with?('remove_', 'delete_')
|
74
|
+
|
75
|
+
puts 'Are you sure? (y/n)'
|
76
|
+
|
77
|
+
if %w[y yes].include?($stdin.gets.to_s.strip.downcase)
|
78
|
+
puts 'Proceeding..'
|
79
|
+
else
|
80
|
+
puts 'Command aborted.'
|
81
|
+
exit(1)
|
78
82
|
end
|
79
83
|
end
|
80
84
|
|
81
85
|
# Gets defined help for a specific command/action.
|
82
86
|
#
|
83
87
|
# @return [String]
|
84
|
-
def help(cmd=nil, &block)
|
88
|
+
def help(cmd = nil, &block)
|
85
89
|
if cmd.nil? || Gitlab::Help.help_map.key?(cmd)
|
86
90
|
Gitlab::Help.actions_table(cmd)
|
87
91
|
else
|
@@ -89,30 +93,30 @@ class Gitlab::CLI
|
|
89
93
|
end
|
90
94
|
end
|
91
95
|
|
92
|
-
# Outputs a nicely formatted table or error
|
96
|
+
# Outputs a nicely formatted table or error message.
|
93
97
|
def output_table(cmd, args, data)
|
94
98
|
case data
|
95
99
|
when Gitlab::ObjectifiedHash, Gitlab::FileResponse
|
96
100
|
puts record_table([data], cmd, args)
|
97
101
|
when Gitlab::PaginatedResponse
|
98
102
|
puts record_table(data, cmd, args)
|
99
|
-
else # probably just an error
|
103
|
+
else # probably just an error message
|
100
104
|
puts data
|
101
105
|
end
|
102
106
|
end
|
103
107
|
|
104
108
|
def output_json(cmd, args, data)
|
105
|
-
if data.empty?
|
109
|
+
if data.respond_to?(:empty?) && data.empty?
|
106
110
|
puts '{}'
|
107
111
|
else
|
108
112
|
hash_result = case data
|
109
|
-
when Gitlab::ObjectifiedHash,Gitlab::FileResponse
|
110
|
-
record_hash([data], cmd, args, true)
|
113
|
+
when Gitlab::ObjectifiedHash, Gitlab::FileResponse
|
114
|
+
record_hash([data], cmd, args, single_value: true)
|
111
115
|
when Gitlab::PaginatedResponse
|
112
116
|
record_hash(data, cmd, args)
|
113
117
|
else
|
114
118
|
{ cmd: cmd, data: data, args: args }
|
115
|
-
|
119
|
+
end
|
116
120
|
puts JSON.pretty_generate(hash_result)
|
117
121
|
end
|
118
122
|
end
|
@@ -135,7 +139,7 @@ class Gitlab::CLI
|
|
135
139
|
keys.each do |key|
|
136
140
|
case value = hash[key]
|
137
141
|
when Hash
|
138
|
-
value = value.
|
142
|
+
value = value.key?('id') ? value['id'] : 'Hash'
|
139
143
|
when StringIO
|
140
144
|
value = 'File'
|
141
145
|
when nil
|
@@ -158,7 +162,7 @@ class Gitlab::CLI
|
|
158
162
|
# @param [Array] args Options passed to the API call
|
159
163
|
# @param [bool] single_value If set to true, a single result should be returned
|
160
164
|
# @return [Hash] Result hash
|
161
|
-
def record_hash(data, cmd, args, single_value
|
165
|
+
def record_hash(data, cmd, args, single_value: false)
|
162
166
|
if data.empty?
|
163
167
|
result = nil
|
164
168
|
else
|
@@ -168,21 +172,21 @@ class Gitlab::CLI
|
|
168
172
|
row = {}
|
169
173
|
|
170
174
|
keys.each do |key|
|
171
|
-
case hash[key]
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
175
|
+
row[key] = case hash[key]
|
176
|
+
when Hash
|
177
|
+
'Hash'
|
178
|
+
when StringIO
|
179
|
+
Base64.encode64(hash[key].read)
|
180
|
+
when nil
|
181
|
+
nil
|
182
|
+
else
|
183
|
+
hash[key]
|
184
|
+
end
|
181
185
|
end
|
182
186
|
|
183
187
|
result.push row
|
184
188
|
end
|
185
|
-
result = result[0] if single_value && result.count
|
189
|
+
result = result[0] if single_value && result.count.positive?
|
186
190
|
end
|
187
191
|
|
188
192
|
{
|
@@ -194,48 +198,46 @@ class Gitlab::CLI
|
|
194
198
|
# Helper function to get rows and keys from data returned from API call
|
195
199
|
def get_keys(args, data)
|
196
200
|
arr = data.map(&:to_h)
|
197
|
-
keys = arr.first.keys.
|
201
|
+
keys = arr.first.keys.sort_by(&:to_s)
|
198
202
|
keys &= required_fields(args) if required_fields(args).any?
|
199
203
|
keys -= excluded_fields(args)
|
200
204
|
[arr, keys]
|
201
205
|
end
|
202
206
|
|
203
207
|
# Helper function to call Gitlab commands with args.
|
204
|
-
def gitlab_helper(cmd, args=[])
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
yield if block_given?
|
210
|
-
end
|
211
|
-
|
212
|
-
data
|
208
|
+
def gitlab_helper(cmd, args = [])
|
209
|
+
args.any? ? Gitlab.send(cmd, *args) : Gitlab.send(cmd)
|
210
|
+
rescue StandardError => e
|
211
|
+
puts e.message
|
212
|
+
yield if block_given?
|
213
213
|
end
|
214
214
|
|
215
215
|
# Convert a hash (recursively) to use symbol hash keys
|
216
216
|
# @return [Hash]
|
217
217
|
def symbolize_keys(hash)
|
218
218
|
if hash.is_a?(Hash)
|
219
|
-
hash = hash.each_with_object({}) do |(key, value),
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
raise "error: cannot convert hash key to symbol: #{key}"
|
224
|
-
end
|
219
|
+
hash = hash.each_with_object({}) do |(key, value), new_hash|
|
220
|
+
new_hash[key.to_sym] = symbolize_keys(value)
|
221
|
+
rescue NoMethodError
|
222
|
+
raise "Error: cannot convert hash key to symbol: #{key}"
|
225
223
|
end
|
226
224
|
end
|
227
225
|
|
228
226
|
hash
|
229
227
|
end
|
230
228
|
|
229
|
+
# Check if arg is a color in 6-digit hex notation with leading '#' sign
|
230
|
+
def hex_color?(arg)
|
231
|
+
pattern = /\A#\h{6}\Z/
|
232
|
+
|
233
|
+
pattern.match(arg)
|
234
|
+
end
|
235
|
+
|
231
236
|
# YAML::load on a single argument
|
232
237
|
def yaml_load(arg)
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
raise "error: Argument is not valid YAML syntax: #{arg}"
|
237
|
-
end
|
238
|
-
yaml
|
238
|
+
hex_color?(arg) ? arg : YAML.safe_load(arg)
|
239
|
+
rescue Psych::SyntaxError
|
240
|
+
raise "Error: Argument is not valid YAML syntax: #{arg}"
|
239
241
|
end
|
240
242
|
end
|
241
243
|
end
|