gitlab-akerl 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.prospectus +11 -0
- data/.travis.yml +8 -0
- data/CHANGELOG.md +229 -0
- data/CONTRIBUTING.md +195 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +24 -0
- data/README.md +192 -0
- data/Rakefile +9 -0
- data/bin/console +10 -0
- data/bin/setup +6 -0
- data/exe/gitlab +7 -0
- data/gitlab-akerl.gemspec +31 -0
- data/lib/gitlab.rb +45 -0
- data/lib/gitlab/api.rb +19 -0
- data/lib/gitlab/cli.rb +89 -0
- data/lib/gitlab/cli_helpers.rb +241 -0
- data/lib/gitlab/client.rb +48 -0
- data/lib/gitlab/client/branches.rb +91 -0
- data/lib/gitlab/client/build_triggers.rb +51 -0
- data/lib/gitlab/client/build_variables.rb +66 -0
- data/lib/gitlab/client/builds.rb +106 -0
- data/lib/gitlab/client/commits.rb +121 -0
- data/lib/gitlab/client/groups.rb +144 -0
- data/lib/gitlab/client/issues.rb +113 -0
- data/lib/gitlab/client/labels.rb +57 -0
- data/lib/gitlab/client/merge_requests.rb +168 -0
- data/lib/gitlab/client/milestones.rb +78 -0
- data/lib/gitlab/client/namespaces.rb +20 -0
- data/lib/gitlab/client/notes.rb +161 -0
- data/lib/gitlab/client/pipelines.rb +68 -0
- data/lib/gitlab/client/projects.rb +471 -0
- data/lib/gitlab/client/repositories.rb +78 -0
- data/lib/gitlab/client/repository_files.rb +88 -0
- data/lib/gitlab/client/runners.rb +115 -0
- data/lib/gitlab/client/services.rb +50 -0
- data/lib/gitlab/client/snippets.rb +91 -0
- data/lib/gitlab/client/system_hooks.rb +59 -0
- data/lib/gitlab/client/tags.rb +96 -0
- data/lib/gitlab/client/users.rb +250 -0
- data/lib/gitlab/configuration.rb +55 -0
- data/lib/gitlab/error.rb +85 -0
- data/lib/gitlab/file_response.rb +46 -0
- data/lib/gitlab/help.rb +95 -0
- data/lib/gitlab/objectified_hash.rb +34 -0
- data/lib/gitlab/page_links.rb +33 -0
- data/lib/gitlab/paginated_response.rb +97 -0
- data/lib/gitlab/request.rb +117 -0
- data/lib/gitlab/shell.rb +84 -0
- data/lib/gitlab/shell_history.rb +59 -0
- data/lib/gitlab/version.rb +3 -0
- data/spec/fixtures/branch.json +1 -0
- data/spec/fixtures/branch_delete.json +3 -0
- data/spec/fixtures/branches.json +1 -0
- data/spec/fixtures/build.json +38 -0
- data/spec/fixtures/build_artifacts.json +0 -0
- data/spec/fixtures/build_cancel.json +24 -0
- data/spec/fixtures/build_erase.json +24 -0
- data/spec/fixtures/build_retry.json +24 -0
- data/spec/fixtures/builds.json +78 -0
- data/spec/fixtures/builds_commits.json +64 -0
- data/spec/fixtures/compare_merge_request_diff.json +31 -0
- data/spec/fixtures/error_already_exists.json +1 -0
- data/spec/fixtures/error_project_not_found.json +1 -0
- data/spec/fixtures/get_repository_file.json +1 -0
- data/spec/fixtures/git_hook.json +1 -0
- data/spec/fixtures/group.json +60 -0
- data/spec/fixtures/group_create.json +1 -0
- data/spec/fixtures/group_create_with_description.json +1 -0
- data/spec/fixtures/group_delete.json +1 -0
- data/spec/fixtures/group_member.json +1 -0
- data/spec/fixtures/group_member_delete.json +1 -0
- data/spec/fixtures/group_member_edit.json +1 -0
- data/spec/fixtures/group_members.json +1 -0
- data/spec/fixtures/group_projects.json +44 -0
- data/spec/fixtures/group_search.json +2 -0
- data/spec/fixtures/groups.json +2 -0
- data/spec/fixtures/issue.json +1 -0
- data/spec/fixtures/issues.json +1 -0
- data/spec/fixtures/key.json +1 -0
- data/spec/fixtures/keys.json +1 -0
- data/spec/fixtures/label.json +1 -0
- data/spec/fixtures/labels.json +1 -0
- data/spec/fixtures/merge_request.json +1 -0
- data/spec/fixtures/merge_request_changes.json +1 -0
- data/spec/fixtures/merge_request_comment.json +1 -0
- data/spec/fixtures/merge_request_comments.json +1 -0
- data/spec/fixtures/merge_request_commits.json +1 -0
- data/spec/fixtures/merge_requests.json +1 -0
- data/spec/fixtures/milestone.json +1 -0
- data/spec/fixtures/milestone_issues.json +1 -0
- data/spec/fixtures/milestones.json +1 -0
- data/spec/fixtures/namespaces.json +1 -0
- data/spec/fixtures/note.json +1 -0
- data/spec/fixtures/notes.json +1 -0
- data/spec/fixtures/pipeline.json +23 -0
- data/spec/fixtures/pipeline_cancel.json +23 -0
- data/spec/fixtures/pipeline_create.json +23 -0
- data/spec/fixtures/pipeline_retry.json +23 -0
- data/spec/fixtures/pipelines.json +48 -0
- data/spec/fixtures/project.json +1 -0
- data/spec/fixtures/project_commit.json +13 -0
- data/spec/fixtures/project_commit_comment.json +1 -0
- data/spec/fixtures/project_commit_comments.json +1 -0
- data/spec/fixtures/project_commit_diff.json +10 -0
- data/spec/fixtures/project_commit_status.json +42 -0
- data/spec/fixtures/project_commits.json +1 -0
- data/spec/fixtures/project_edit.json +21 -0
- data/spec/fixtures/project_events.json +1 -0
- data/spec/fixtures/project_for_user.json +1 -0
- data/spec/fixtures/project_fork.json +50 -0
- data/spec/fixtures/project_fork_link.json +1 -0
- data/spec/fixtures/project_forked_for_user.json +50 -0
- data/spec/fixtures/project_hook.json +1 -0
- data/spec/fixtures/project_hooks.json +1 -0
- data/spec/fixtures/project_issues.json +1 -0
- data/spec/fixtures/project_key.json +6 -0
- data/spec/fixtures/project_keys.json +6 -0
- data/spec/fixtures/project_runner_enable.json +7 -0
- data/spec/fixtures/project_runners.json +16 -0
- data/spec/fixtures/project_search.json +1 -0
- data/spec/fixtures/project_star.json +44 -0
- data/spec/fixtures/project_tag_annotated.json +1 -0
- data/spec/fixtures/project_tag_lightweight.json +1 -0
- data/spec/fixtures/project_tags.json +1 -0
- data/spec/fixtures/project_unstar.json +44 -0
- data/spec/fixtures/project_update_commit_status.json +20 -0
- data/spec/fixtures/projects.json +1 -0
- data/spec/fixtures/raw_file.json +2 -0
- data/spec/fixtures/release_create.json +1 -0
- data/spec/fixtures/release_update.json +1 -0
- data/spec/fixtures/repository_file.json +1 -0
- data/spec/fixtures/runner.json +26 -0
- data/spec/fixtures/runner_delete.json +7 -0
- data/spec/fixtures/runner_edit.json +26 -0
- data/spec/fixtures/runners.json +16 -0
- data/spec/fixtures/runners_all.json +30 -0
- data/spec/fixtures/service.json +1 -0
- data/spec/fixtures/session.json +1 -0
- data/spec/fixtures/shell_history.json +2 -0
- data/spec/fixtures/snippet.json +1 -0
- data/spec/fixtures/snippet_content.json +3 -0
- data/spec/fixtures/snippets.json +1 -0
- data/spec/fixtures/system_hook.json +1 -0
- data/spec/fixtures/system_hooks.json +1 -0
- data/spec/fixtures/tag.json +1 -0
- data/spec/fixtures/tag_create.json +1 -0
- data/spec/fixtures/tag_create_with_description.json +1 -0
- data/spec/fixtures/tag_delete.json +1 -0
- data/spec/fixtures/tags.json +1 -0
- data/spec/fixtures/team_member.json +1 -0
- data/spec/fixtures/team_members.json +1 -0
- data/spec/fixtures/tree.json +1 -0
- data/spec/fixtures/trigger.json +7 -0
- data/spec/fixtures/triggers.json +16 -0
- data/spec/fixtures/user.json +1 -0
- data/spec/fixtures/user_block_unblock.json +1 -0
- data/spec/fixtures/user_email.json +1 -0
- data/spec/fixtures/user_emails.json +1 -0
- data/spec/fixtures/user_search.json +1 -0
- data/spec/fixtures/users.json +1 -0
- data/spec/fixtures/variable.json +4 -0
- data/spec/fixtures/variables.json +10 -0
- data/spec/gitlab/cli_helpers_spec.rb +57 -0
- data/spec/gitlab/cli_spec.rb +110 -0
- data/spec/gitlab/client/branches_spec.rb +99 -0
- data/spec/gitlab/client/build_triggers_spec.rb +67 -0
- data/spec/gitlab/client/build_variables_spec.rb +86 -0
- data/spec/gitlab/client/builds_spec.rb +148 -0
- data/spec/gitlab/client/client_spec.rb +11 -0
- data/spec/gitlab/client/commits_spec.rb +137 -0
- data/spec/gitlab/client/groups_spec.rb +197 -0
- data/spec/gitlab/client/issues_spec.rb +138 -0
- data/spec/gitlab/client/labels_spec.rb +68 -0
- data/spec/gitlab/client/merge_requests_spec.rb +177 -0
- data/spec/gitlab/client/milestones_spec.rb +82 -0
- data/spec/gitlab/client/namespaces_spec.rb +22 -0
- data/spec/gitlab/client/notes_spec.rb +205 -0
- data/spec/gitlab/client/pipelines_spec.rb +95 -0
- data/spec/gitlab/client/projects_spec.rb +603 -0
- data/spec/gitlab/client/repositories_spec.rb +109 -0
- data/spec/gitlab/client/repository_files_spec.rb +62 -0
- data/spec/gitlab/client/runners_spec.rb +185 -0
- data/spec/gitlab/client/services_spec.rb +55 -0
- data/spec/gitlab/client/snippets_spec.rb +100 -0
- data/spec/gitlab/client/system_hooks_spec.rb +69 -0
- data/spec/gitlab/client/tags_spec.rb +109 -0
- data/spec/gitlab/client/users_spec.rb +418 -0
- data/spec/gitlab/error_spec.rb +45 -0
- data/spec/gitlab/file_response_spec.rb +33 -0
- data/spec/gitlab/help_spec.rb +46 -0
- data/spec/gitlab/objectified_hash_spec.rb +48 -0
- data/spec/gitlab/page_links_spec.rb +16 -0
- data/spec/gitlab/paginated_response_spec.rb +60 -0
- data/spec/gitlab/request_spec.rb +73 -0
- data/spec/gitlab/shell_history_spec.rb +53 -0
- data/spec/gitlab/shell_spec.rb +80 -0
- data/spec/gitlab_spec.rb +97 -0
- data/spec/spec_helper.rb +74 -0
- metadata +476 -0
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Copyright (c) 2012-2015 Nihad Abbasov <mail@narkoz.me>
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
1. Redistributions of source code must retain the above copyright notice,
|
8
|
+
this list of conditions and the following disclaimer.
|
9
|
+
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
12
|
+
and/or other materials provided with the distribution.
|
13
|
+
|
14
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
15
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
16
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
17
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
18
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
19
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
20
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
21
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
22
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
23
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
24
|
+
POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,192 @@
|
|
1
|
+
## Fork info
|
2
|
+
|
3
|
+
This is a fork of the upstream gitlab gem to cut a new release, as the latest upstream release doesn't support Ruby 2.4.0. The only changes I've made:
|
4
|
+
|
5
|
+
* Settings Gitlab::VERSION to 4.0.0
|
6
|
+
* Updating badge icons to not point to upstream project
|
7
|
+
* Set gemspec name to "gitlab-akerl"
|
8
|
+
* Added a .prospectus file to track deps
|
9
|
+
|
10
|
+
# Gitlab
|
11
|
+
|
12
|
+
[![Gem Version](https://img.shields.io/gem/v/basiccache.svg)](https://rubygems.org/gems/basiccache)
|
13
|
+
[![Dependency Status](https://img.shields.io/gemnasium/akerl/basiccache.svg)](https://gemnasium.com/akerl/basiccache)
|
14
|
+
[![License](https://img.shields.io/badge/license-BSD-green.svg)](https://github.com/akerl/gitlab/blob/master/LICENSE.txt)
|
15
|
+
|
16
|
+
[website](http://narkoz.github.io/gitlab) |
|
17
|
+
[documentation](http://rubydoc.info/gems/gitlab/frames) |
|
18
|
+
[gitlab-live](https://github.com/NARKOZ/gitlab-live)
|
19
|
+
|
20
|
+
Gitlab is a Ruby wrapper and CLI for the [GitLab API](https://docs.gitlab.com/ce/api/README.html) for Ruby 2.0+.
|
21
|
+
|
22
|
+
## Installation
|
23
|
+
|
24
|
+
Install it from rubygems:
|
25
|
+
|
26
|
+
```sh
|
27
|
+
gem install gitlab
|
28
|
+
```
|
29
|
+
|
30
|
+
Or add to a Gemfile:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
gem 'gitlab'
|
34
|
+
# gem 'gitlab', github: 'NARKOZ/gitlab'
|
35
|
+
```
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
|
39
|
+
Configuration example:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
Gitlab.configure do |config|
|
43
|
+
config.endpoint = 'https://example.net/api/v3' # API endpoint URL, default: ENV['GITLAB_API_ENDPOINT']
|
44
|
+
config.private_token = 'qEsq1pt6HJPaNciie3MG' # user's private token or OAuth2 access token, default: ENV['GITLAB_API_PRIVATE_TOKEN']
|
45
|
+
# Optional
|
46
|
+
# config.user_agent = 'Custom User Agent' # user agent, default: 'Gitlab Ruby Gem [version]'
|
47
|
+
# config.sudo = 'user' # username for sudo mode, default: nil
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
(Note: If you are using GitLab.com's hosted service, your endpoint will be `https://gitlab.com/api/v3`)
|
52
|
+
|
53
|
+
Usage examples:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
# set an API endpoint
|
57
|
+
Gitlab.endpoint = 'http://example.net/api/v3'
|
58
|
+
# => "http://example.net/api/v3"
|
59
|
+
|
60
|
+
# set a user private token
|
61
|
+
Gitlab.private_token = 'qEsq1pt6HJPaNciie3MG'
|
62
|
+
# => "qEsq1pt6HJPaNciie3MG"
|
63
|
+
|
64
|
+
# configure a proxy server
|
65
|
+
Gitlab.http_proxy('proxyhost', 8888)
|
66
|
+
# proxy server w/ basic auth
|
67
|
+
Gitlab.http_proxy('proxyhost', 8888, 'proxyuser', 'strongpasswordhere')
|
68
|
+
|
69
|
+
# list projects
|
70
|
+
Gitlab.projects(per_page: 5)
|
71
|
+
# => [#<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"}>]
|
72
|
+
|
73
|
+
# initialize a new client
|
74
|
+
g = Gitlab.client(endpoint: 'https://api.example.com', private_token: 'qEsq1pt6HJPaNciie3MG')
|
75
|
+
# => #<Gitlab::Client:0x00000001e62408 @endpoint="https://api.example.com", @private_token="qEsq1pt6HJPaNciie3MG", @user_agent="Gitlab Ruby Gem 2.0.0">
|
76
|
+
|
77
|
+
# get a user
|
78
|
+
user = g.user
|
79
|
+
# => #<Gitlab::ObjectifiedHash:0x00000002217990 @data={"id"=>1, "email"=>"john@example.com", "name"=>"John Smith", "bio"=>nil, "skype"=>"", "linkedin"=>"", "twitter"=>"john", "dark_scheme"=>false, "theme_id"=>1, "blocked"=>false, "created_at"=>"2012-09-17T09:41:56Z"}>
|
80
|
+
|
81
|
+
# get a user's email
|
82
|
+
user.email
|
83
|
+
# => "john@example.com"
|
84
|
+
|
85
|
+
# set a sudo mode to perform API calls as another user
|
86
|
+
Gitlab.sudo = 'other_user'
|
87
|
+
# => "other_user"
|
88
|
+
|
89
|
+
# disable a sudo mode
|
90
|
+
Gitlab.sudo = nil
|
91
|
+
# => nil
|
92
|
+
|
93
|
+
# a paginated response
|
94
|
+
projects = Gitlab.projects(per_page: 5)
|
95
|
+
|
96
|
+
# check existence of the next page
|
97
|
+
projects.has_next_page?
|
98
|
+
|
99
|
+
# retrieve the next page
|
100
|
+
projects.next_page
|
101
|
+
|
102
|
+
# iterate all projects
|
103
|
+
projects.auto_paginate do |project|
|
104
|
+
# do something
|
105
|
+
end
|
106
|
+
|
107
|
+
# retrieve all projects as an array
|
108
|
+
projects.auto_paginate
|
109
|
+
```
|
110
|
+
|
111
|
+
For more information, refer to [documentation](http://rubydoc.info/gems/gitlab/frames).
|
112
|
+
|
113
|
+
## CLI
|
114
|
+
|
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
|
+
```sh
|
117
|
+
export GITLAB_API_ENDPOINT=https://gitlab.yourcompany.com/api/v3
|
118
|
+
export GITLAB_API_PRIVATE_TOKEN=<your private token from /profile/account>
|
119
|
+
# This one is optional and can be used to set any HTTParty option you may need
|
120
|
+
# using YAML hash syntax. For example, this is how you would disable SSL
|
121
|
+
# verification (useful if using a self-signed cert).
|
122
|
+
export GITLAB_API_HTTPARTY_OPTIONS="{verify: false}"
|
123
|
+
```
|
124
|
+
|
125
|
+
Usage:
|
126
|
+
|
127
|
+
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
|
+
|
129
|
+
Usage examples:
|
130
|
+
|
131
|
+
```sh
|
132
|
+
# list users
|
133
|
+
# see: http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client/Users#users-instance_method
|
134
|
+
gitlab users
|
135
|
+
|
136
|
+
# get current user
|
137
|
+
# see: http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client/Users#user-instance_method
|
138
|
+
gitlab user
|
139
|
+
|
140
|
+
# get a user
|
141
|
+
# see: http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client/Users#user-instance_method
|
142
|
+
gitlab user 2
|
143
|
+
|
144
|
+
# filter output
|
145
|
+
gitlab user --only=id,username
|
146
|
+
|
147
|
+
gitlab user --except=email,bio
|
148
|
+
|
149
|
+
# get a user and render result as json
|
150
|
+
gitlab user 2 --json
|
151
|
+
|
152
|
+
# passing options hash to a command (use YAML)
|
153
|
+
# see: http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client/MergeRequests#create_merge_request-instance_method
|
154
|
+
gitlab create_merge_request 4 "New merge request" "{source_branch: 'new_branch', target_branch: 'master', assignee_id: 42}"
|
155
|
+
|
156
|
+
```
|
157
|
+
|
158
|
+
## CLI Shell
|
159
|
+
|
160
|
+
Usage examples:
|
161
|
+
|
162
|
+
```sh
|
163
|
+
# start shell session
|
164
|
+
gitlab shell
|
165
|
+
|
166
|
+
# list available commands
|
167
|
+
gitlab> help
|
168
|
+
|
169
|
+
# list groups
|
170
|
+
gitlab> groups
|
171
|
+
|
172
|
+
# protect a branch
|
173
|
+
gitlab> protect_branch 1 master
|
174
|
+
|
175
|
+
# passing options hash to a command (use YAML)
|
176
|
+
gitlab> create_merge_request 4 "New merge request" "{source_branch: 'new_branch', target_branch: 'master', assignee_id: 42}"
|
177
|
+
```
|
178
|
+
|
179
|
+
Web version is available at https://gitlab-live.herokuapp.com
|
180
|
+
For more information, refer to [website](http://narkoz.github.io/gitlab).
|
181
|
+
|
182
|
+
## Development
|
183
|
+
|
184
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
185
|
+
`rake spec` to run the tests. You can also run `bin/console` for an interactive
|
186
|
+
prompt that will allow you to experiment.
|
187
|
+
|
188
|
+
For more information see [CONTRIBUTING.md](https://github.com/NARKOZ/gitlab/blob/master/CONTRIBUTING.md).
|
189
|
+
|
190
|
+
## License
|
191
|
+
|
192
|
+
Released under the BSD 2-clause license. See LICENSE.txt for details.
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
data/exe/gitlab
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gitlab/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "gitlab-akerl"
|
8
|
+
gem.version = Gitlab::VERSION
|
9
|
+
gem.authors = ["Nihad Abbasov"]
|
10
|
+
gem.email = ["mail@narkoz.me"]
|
11
|
+
gem.description = %q{Ruby client and CLI for GitLab API}
|
12
|
+
gem.summary = %q{A Ruby wrapper and CLI for the GitLab API}
|
13
|
+
gem.homepage = "https://github.com/narkoz/gitlab"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.bindir = "exe"
|
17
|
+
gem.executables = gem.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
gem.license = "BSD"
|
21
|
+
|
22
|
+
gem.required_ruby_version = ">= 2.0.0"
|
23
|
+
|
24
|
+
gem.add_runtime_dependency 'httparty', '~> 0.14.0'
|
25
|
+
gem.add_runtime_dependency 'terminal-table', '1.7.1'
|
26
|
+
|
27
|
+
gem.add_development_dependency 'pry'
|
28
|
+
gem.add_development_dependency 'rake'
|
29
|
+
gem.add_development_dependency 'rspec'
|
30
|
+
gem.add_development_dependency 'webmock'
|
31
|
+
end
|
data/lib/gitlab.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'gitlab/version'
|
2
|
+
require 'gitlab/objectified_hash'
|
3
|
+
require 'gitlab/configuration'
|
4
|
+
require 'gitlab/error'
|
5
|
+
require 'gitlab/page_links'
|
6
|
+
require 'gitlab/paginated_response'
|
7
|
+
require 'gitlab/file_response'
|
8
|
+
require 'gitlab/request'
|
9
|
+
require 'gitlab/api'
|
10
|
+
require 'gitlab/client'
|
11
|
+
|
12
|
+
module Gitlab
|
13
|
+
extend Configuration
|
14
|
+
|
15
|
+
# Alias for Gitlab::Client.new
|
16
|
+
#
|
17
|
+
# @return [Gitlab::Client]
|
18
|
+
def self.client(options={})
|
19
|
+
Gitlab::Client.new(options)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Delegate to Gitlab::Client
|
23
|
+
def self.method_missing(method, *args, &block)
|
24
|
+
return super unless client.respond_to?(method)
|
25
|
+
client.send(method, *args, &block)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Delegate to Gitlab::Client
|
29
|
+
def respond_to_missing?(method_name, include_private = false)
|
30
|
+
client.respond_to?(method_name) || super
|
31
|
+
end
|
32
|
+
|
33
|
+
# Delegate to HTTParty.http_proxy
|
34
|
+
def self.http_proxy(address=nil, port=nil, username=nil, password=nil)
|
35
|
+
Gitlab::Request.http_proxy(address, port, username, password)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns an unsorted array of available client methods.
|
39
|
+
#
|
40
|
+
# @return [Array<Symbol>]
|
41
|
+
def self.actions
|
42
|
+
hidden = /endpoint|private_token|auth_token|user_agent|sudo|get|post|put|\Adelete\z|validate|set_request_defaults|httparty/
|
43
|
+
(Gitlab::Client.instance_methods - Object.methods).reject { |e| e[hidden] }
|
44
|
+
end
|
45
|
+
end
|
data/lib/gitlab/api.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Gitlab
|
2
|
+
# @private
|
3
|
+
class API < Request
|
4
|
+
# @private
|
5
|
+
attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
|
6
|
+
# @private
|
7
|
+
alias_method :auth_token=, :private_token=
|
8
|
+
|
9
|
+
# Creates a new API.
|
10
|
+
# @raise [Error:MissingCredentials]
|
11
|
+
def initialize(options={})
|
12
|
+
options = Gitlab.options.merge(options)
|
13
|
+
(Configuration::VALID_OPTIONS_KEYS + [:auth_token]).each do |key|
|
14
|
+
send("#{key}=", options[key]) if options[key]
|
15
|
+
end
|
16
|
+
set_request_defaults(@sudo)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/gitlab/cli.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'gitlab'
|
2
|
+
require 'terminal-table/import'
|
3
|
+
require_relative 'cli_helpers'
|
4
|
+
require_relative 'shell'
|
5
|
+
|
6
|
+
class Gitlab::CLI
|
7
|
+
extend Helpers
|
8
|
+
|
9
|
+
# If set to true, JSON will be rendered as output
|
10
|
+
@render_json = false
|
11
|
+
|
12
|
+
# Starts a new CLI session.
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# Gitlab::CLI.start(['help'])
|
16
|
+
# Gitlab::CLI.start(['help', 'issues'])
|
17
|
+
#
|
18
|
+
# @param [Array] args The command and it's optional arguments.
|
19
|
+
def self.start(args)
|
20
|
+
command = args.shift.strip rescue 'help'
|
21
|
+
run(command, args)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Processes a CLI command and outputs a result to the stream (stdout).
|
25
|
+
#
|
26
|
+
# @example
|
27
|
+
# Gitlab::CLI.run('help')
|
28
|
+
# Gitlab::CLI.run('help', ['issues'])
|
29
|
+
#
|
30
|
+
# @param [String] cmd The name of a command.
|
31
|
+
# @param [Array] args The optional arguments for a command.
|
32
|
+
# @return [nil]
|
33
|
+
def self.run(cmd, args=[])
|
34
|
+
case cmd
|
35
|
+
when 'help'
|
36
|
+
puts help(args.shift) { |out| out.gsub!(/Gitlab\./, 'gitlab ') }
|
37
|
+
when 'info'
|
38
|
+
endpoint = Gitlab.endpoint ? Gitlab.endpoint : 'not set'
|
39
|
+
private_token = Gitlab.private_token ? Gitlab.private_token : 'not set'
|
40
|
+
puts "Gitlab endpoint is #{endpoint}"
|
41
|
+
puts "Gitlab private token is #{private_token}"
|
42
|
+
puts "Ruby Version is #{RUBY_VERSION}"
|
43
|
+
puts "Gitlab Ruby Gem #{Gitlab::VERSION}"
|
44
|
+
when '-v', '--version'
|
45
|
+
puts "Gitlab Ruby Gem #{Gitlab::VERSION}"
|
46
|
+
when 'shell'
|
47
|
+
Gitlab::Shell.start
|
48
|
+
else
|
49
|
+
if args.include? '--json'
|
50
|
+
@json_output = true
|
51
|
+
args.delete '--json'
|
52
|
+
end
|
53
|
+
|
54
|
+
unless valid_command?(cmd)
|
55
|
+
puts "Unknown command. Run `gitlab help` for a list of available commands."
|
56
|
+
exit(1)
|
57
|
+
end
|
58
|
+
|
59
|
+
if args.any? && (args.last.start_with?('--only=') || args.last.start_with?('--except='))
|
60
|
+
command_args = args[0..-2]
|
61
|
+
else
|
62
|
+
command_args = args
|
63
|
+
end
|
64
|
+
|
65
|
+
begin
|
66
|
+
command_args.map! { |arg| symbolize_keys(yaml_load(arg)) }
|
67
|
+
rescue => e
|
68
|
+
puts e.message
|
69
|
+
exit 1
|
70
|
+
end
|
71
|
+
|
72
|
+
confirm_command(cmd)
|
73
|
+
|
74
|
+
data = gitlab_helper(cmd, command_args) { exit(1) }
|
75
|
+
|
76
|
+
render_output(cmd, args, data)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Helper method that checks whether we want to get the output as json
|
81
|
+
# @return [nil]
|
82
|
+
def self.render_output(cmd, args, data)
|
83
|
+
if @json_output
|
84
|
+
output_json(cmd, args, data)
|
85
|
+
else
|
86
|
+
output_table(cmd, args, data)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|