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.
Files changed (271) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +4 -2
  3. data/LICENSE.txt +1 -1
  4. data/README.md +96 -25
  5. data/exe/gitlab +5 -1
  6. data/lib/gitlab/api.rb +8 -3
  7. data/lib/gitlab/cli.rb +15 -15
  8. data/lib/gitlab/cli_helpers.rb +63 -61
  9. data/lib/gitlab/client/access_requests.rb +103 -0
  10. data/lib/gitlab/client/application_settings.rb +172 -0
  11. data/lib/gitlab/client/avatar.rb +21 -0
  12. data/lib/gitlab/client/award_emojis.rb +5 -3
  13. data/lib/gitlab/client/boards.rb +62 -4
  14. data/lib/gitlab/client/branches.rb +53 -14
  15. data/lib/gitlab/client/broadcast_messages.rb +75 -0
  16. data/lib/gitlab/client/build_variables.rb +78 -9
  17. data/lib/gitlab/client/builds.rb +13 -11
  18. data/lib/gitlab/client/commits.rb +89 -19
  19. data/lib/gitlab/client/container_registry.rb +85 -0
  20. data/lib/gitlab/client/deployments.rb +34 -0
  21. data/lib/gitlab/client/environments.rb +5 -3
  22. data/lib/gitlab/client/epic_issues.rb +23 -0
  23. data/lib/gitlab/client/epics.rb +73 -0
  24. data/lib/gitlab/client/events.rb +60 -0
  25. data/lib/gitlab/client/features.rb +48 -0
  26. data/lib/gitlab/client/group_badges.rb +88 -0
  27. data/lib/gitlab/client/group_boards.rb +141 -0
  28. data/lib/gitlab/client/group_labels.rb +88 -0
  29. data/lib/gitlab/client/group_milestones.rb +94 -0
  30. data/lib/gitlab/client/groups.rb +197 -17
  31. data/lib/gitlab/client/issue_links.rb +48 -0
  32. data/lib/gitlab/client/issues.rb +98 -4
  33. data/lib/gitlab/client/jobs.rb +96 -8
  34. data/lib/gitlab/client/keys.rb +13 -0
  35. data/lib/gitlab/client/labels.rb +7 -5
  36. data/lib/gitlab/client/lint.rb +19 -0
  37. data/lib/gitlab/client/markdown.rb +23 -0
  38. data/lib/gitlab/client/merge_request_approvals.rb +265 -0
  39. data/lib/gitlab/client/merge_requests.rb +237 -9
  40. data/lib/gitlab/client/milestones.rb +19 -5
  41. data/lib/gitlab/client/namespaces.rb +4 -2
  42. data/lib/gitlab/client/notes.rb +58 -12
  43. data/lib/gitlab/client/pipeline_schedules.rb +147 -0
  44. data/lib/gitlab/client/pipeline_triggers.rb +12 -10
  45. data/lib/gitlab/client/pipelines.rb +40 -3
  46. data/lib/gitlab/client/project_badges.rb +85 -0
  47. data/lib/gitlab/client/project_clusters.rb +83 -0
  48. data/lib/gitlab/client/project_release_links.rb +76 -0
  49. data/lib/gitlab/client/project_releases.rb +79 -0
  50. data/lib/gitlab/client/projects.rb +280 -47
  51. data/lib/gitlab/client/protected_tags.rb +59 -0
  52. data/lib/gitlab/client/remote_mirrors.rb +51 -0
  53. data/lib/gitlab/client/repositories.rb +60 -6
  54. data/lib/gitlab/client/repository_files.rb +23 -5
  55. data/lib/gitlab/client/repository_submodules.rb +27 -0
  56. data/lib/gitlab/client/resource_label_events.rb +82 -0
  57. data/lib/gitlab/client/resource_state_events.rb +57 -0
  58. data/lib/gitlab/client/runners.rb +111 -15
  59. data/lib/gitlab/client/search.rb +66 -0
  60. data/lib/gitlab/client/services.rb +4 -1
  61. data/lib/gitlab/client/sidekiq.rb +39 -0
  62. data/lib/gitlab/client/snippets.rb +8 -4
  63. data/lib/gitlab/client/system_hooks.rb +9 -7
  64. data/lib/gitlab/client/tags.rb +15 -14
  65. data/lib/gitlab/client/templates.rb +100 -0
  66. data/lib/gitlab/client/todos.rb +7 -5
  67. data/lib/gitlab/client/user_snippets.rb +114 -0
  68. data/lib/gitlab/client/users.rb +166 -30
  69. data/lib/gitlab/client/versions.rb +18 -0
  70. data/lib/gitlab/client/wikis.rb +79 -0
  71. data/lib/gitlab/client.rb +49 -12
  72. data/lib/gitlab/configuration.rb +8 -6
  73. data/lib/gitlab/error.rb +74 -5
  74. data/lib/gitlab/file_response.rb +5 -3
  75. data/lib/gitlab/help.rb +19 -20
  76. data/lib/gitlab/objectified_hash.rb +27 -10
  77. data/lib/gitlab/page_links.rb +11 -9
  78. data/lib/gitlab/paginated_response.rb +37 -24
  79. data/lib/gitlab/request.rb +42 -53
  80. data/lib/gitlab/shell.rb +11 -12
  81. data/lib/gitlab/shell_history.rb +11 -13
  82. data/lib/gitlab/version.rb +3 -1
  83. data/lib/gitlab.rb +19 -8
  84. metadata +50 -395
  85. data/.gitignore +0 -22
  86. data/.travis.yml +0 -8
  87. data/CONTRIBUTING.md +0 -195
  88. data/Gemfile +0 -4
  89. data/Rakefile +0 -9
  90. data/bin/console +0 -10
  91. data/bin/setup +0 -6
  92. data/gitlab.gemspec +0 -31
  93. data/spec/fixtures/board_list.json +0 -1
  94. data/spec/fixtures/board_lists.json +0 -1
  95. data/spec/fixtures/boards.json +0 -1
  96. data/spec/fixtures/branch.json +0 -1
  97. data/spec/fixtures/branch_delete.json +0 -3
  98. data/spec/fixtures/branches.json +0 -1
  99. data/spec/fixtures/build.json +0 -38
  100. data/spec/fixtures/build_artifacts.json +0 -0
  101. data/spec/fixtures/build_cancel.json +0 -24
  102. data/spec/fixtures/build_erase.json +0 -24
  103. data/spec/fixtures/build_retry.json +0 -24
  104. data/spec/fixtures/builds.json +0 -78
  105. data/spec/fixtures/builds_commits.json +0 -64
  106. data/spec/fixtures/compare_merge_request_diff.json +0 -31
  107. data/spec/fixtures/empty.json +0 -0
  108. data/spec/fixtures/environment.json +0 -6
  109. data/spec/fixtures/environments.json +0 -14
  110. data/spec/fixtures/error_already_exists.json +0 -1
  111. data/spec/fixtures/error_project_not_found.json +0 -1
  112. data/spec/fixtures/get_repository_file.json +0 -1
  113. data/spec/fixtures/group.json +0 -60
  114. data/spec/fixtures/group_create.json +0 -1
  115. data/spec/fixtures/group_create_with_description.json +0 -1
  116. data/spec/fixtures/group_delete.json +0 -1
  117. data/spec/fixtures/group_member.json +0 -1
  118. data/spec/fixtures/group_member_delete.json +0 -1
  119. data/spec/fixtures/group_member_edit.json +0 -1
  120. data/spec/fixtures/group_members.json +0 -1
  121. data/spec/fixtures/group_projects.json +0 -44
  122. data/spec/fixtures/group_search.json +0 -2
  123. data/spec/fixtures/groups.json +0 -2
  124. data/spec/fixtures/issue.json +0 -1
  125. data/spec/fixtures/issue_award_emoji.json +0 -16
  126. data/spec/fixtures/issue_award_emojis.json +0 -34
  127. data/spec/fixtures/issues.json +0 -1
  128. data/spec/fixtures/job.json +0 -43
  129. data/spec/fixtures/job_trace.json +0 -1
  130. data/spec/fixtures/jobs.json +0 -91
  131. data/spec/fixtures/key.json +0 -1
  132. data/spec/fixtures/keys.json +0 -1
  133. data/spec/fixtures/label.json +0 -1
  134. data/spec/fixtures/label_unsubscribe.json +0 -1
  135. data/spec/fixtures/labels.json +0 -1
  136. data/spec/fixtures/merge_request.json +0 -1
  137. data/spec/fixtures/merge_request_award_emoji.json +0 -16
  138. data/spec/fixtures/merge_request_award_emojis.json +0 -34
  139. data/spec/fixtures/merge_request_changes.json +0 -1
  140. data/spec/fixtures/merge_request_closes_issues.json +0 -1
  141. data/spec/fixtures/merge_request_comment.json +0 -1
  142. data/spec/fixtures/merge_request_comments.json +0 -1
  143. data/spec/fixtures/merge_request_commits.json +0 -1
  144. data/spec/fixtures/merge_requests.json +0 -1
  145. data/spec/fixtures/milestone.json +0 -1
  146. data/spec/fixtures/milestone_issues.json +0 -1
  147. data/spec/fixtures/milestone_merge_requests.json +0 -1
  148. data/spec/fixtures/milestones.json +0 -1
  149. data/spec/fixtures/namespaces.json +0 -1
  150. data/spec/fixtures/note.json +0 -1
  151. data/spec/fixtures/note_award_emoji.json +0 -16
  152. data/spec/fixtures/note_award_emojis.json +0 -18
  153. data/spec/fixtures/notes.json +0 -1
  154. data/spec/fixtures/pipeline.json +0 -23
  155. data/spec/fixtures/pipeline_cancel.json +0 -23
  156. data/spec/fixtures/pipeline_create.json +0 -23
  157. data/spec/fixtures/pipeline_jobs.json +0 -91
  158. data/spec/fixtures/pipeline_retry.json +0 -23
  159. data/spec/fixtures/pipelines.json +0 -48
  160. data/spec/fixtures/project.json +0 -1
  161. data/spec/fixtures/project_commit.json +0 -13
  162. data/spec/fixtures/project_commit_comment.json +0 -1
  163. data/spec/fixtures/project_commit_comments.json +0 -1
  164. data/spec/fixtures/project_commit_create.json +0 -22
  165. data/spec/fixtures/project_commit_diff.json +0 -10
  166. data/spec/fixtures/project_commit_status.json +0 -42
  167. data/spec/fixtures/project_commits.json +0 -1
  168. data/spec/fixtures/project_edit.json +0 -21
  169. data/spec/fixtures/project_events.json +0 -1
  170. data/spec/fixtures/project_for_user.json +0 -1
  171. data/spec/fixtures/project_fork.json +0 -50
  172. data/spec/fixtures/project_fork_link.json +0 -1
  173. data/spec/fixtures/project_forked_for_user.json +0 -50
  174. data/spec/fixtures/project_hook.json +0 -1
  175. data/spec/fixtures/project_hooks.json +0 -1
  176. data/spec/fixtures/project_issues.json +0 -1
  177. data/spec/fixtures/project_key.json +0 -6
  178. data/spec/fixtures/project_keys.json +0 -6
  179. data/spec/fixtures/project_runner_enable.json +0 -7
  180. data/spec/fixtures/project_runners.json +0 -16
  181. data/spec/fixtures/project_search.json +0 -1
  182. data/spec/fixtures/project_star.json +0 -44
  183. data/spec/fixtures/project_tag_annotated.json +0 -1
  184. data/spec/fixtures/project_tag_lightweight.json +0 -1
  185. data/spec/fixtures/project_tags.json +0 -1
  186. data/spec/fixtures/project_unstar.json +0 -44
  187. data/spec/fixtures/project_update_commit_status.json +0 -20
  188. data/spec/fixtures/projects.json +0 -1
  189. data/spec/fixtures/push_rule.json +0 -1
  190. data/spec/fixtures/raw_file.json +0 -2
  191. data/spec/fixtures/release_create.json +0 -1
  192. data/spec/fixtures/release_update.json +0 -1
  193. data/spec/fixtures/repository_file.json +0 -1
  194. data/spec/fixtures/run_trigger.json +0 -1
  195. data/spec/fixtures/runner.json +0 -26
  196. data/spec/fixtures/runner_delete.json +0 -7
  197. data/spec/fixtures/runner_edit.json +0 -26
  198. data/spec/fixtures/runners.json +0 -16
  199. data/spec/fixtures/runners_all.json +0 -30
  200. data/spec/fixtures/service.json +0 -1
  201. data/spec/fixtures/session.json +0 -1
  202. data/spec/fixtures/shell_history.json +0 -2
  203. data/spec/fixtures/snippet.json +0 -1
  204. data/spec/fixtures/snippet_award_emoji.json +0 -16
  205. data/spec/fixtures/snippet_award_emojis.json +0 -34
  206. data/spec/fixtures/snippet_content.json +0 -3
  207. data/spec/fixtures/snippets.json +0 -1
  208. data/spec/fixtures/system_hook.json +0 -1
  209. data/spec/fixtures/system_hooks.json +0 -1
  210. data/spec/fixtures/tag.json +0 -1
  211. data/spec/fixtures/tag_create.json +0 -1
  212. data/spec/fixtures/tag_create_with_description.json +0 -1
  213. data/spec/fixtures/tag_delete.json +0 -1
  214. data/spec/fixtures/tags.json +0 -1
  215. data/spec/fixtures/team_member.json +0 -1
  216. data/spec/fixtures/team_members.json +0 -1
  217. data/spec/fixtures/todo.json +0 -73
  218. data/spec/fixtures/todos.json +0 -148
  219. data/spec/fixtures/tree.json +0 -1
  220. data/spec/fixtures/trigger.json +0 -10
  221. data/spec/fixtures/triggers.json +0 -12
  222. data/spec/fixtures/user.json +0 -1
  223. data/spec/fixtures/user_block_unblock.json +0 -1
  224. data/spec/fixtures/user_email.json +0 -1
  225. data/spec/fixtures/user_emails.json +0 -1
  226. data/spec/fixtures/user_search.json +0 -1
  227. data/spec/fixtures/users.json +0 -1
  228. data/spec/fixtures/variable.json +0 -4
  229. data/spec/fixtures/variables.json +0 -10
  230. data/spec/gitlab/cli_helpers_spec.rb +0 -57
  231. data/spec/gitlab/cli_spec.rb +0 -119
  232. data/spec/gitlab/client/award_emojis_spec.rb +0 -391
  233. data/spec/gitlab/client/boards_spec.rb +0 -94
  234. data/spec/gitlab/client/branches_spec.rb +0 -116
  235. data/spec/gitlab/client/build_variables_spec.rb +0 -86
  236. data/spec/gitlab/client/builds_spec.rb +0 -148
  237. data/spec/gitlab/client/client_spec.rb +0 -11
  238. data/spec/gitlab/client/commits_spec.rb +0 -168
  239. data/spec/gitlab/client/environments_spec.rb +0 -132
  240. data/spec/gitlab/client/groups_spec.rb +0 -195
  241. data/spec/gitlab/client/issues_spec.rb +0 -186
  242. data/spec/gitlab/client/jobs_spec.rb +0 -135
  243. data/spec/gitlab/client/keys_spec.rb +0 -19
  244. data/spec/gitlab/client/labels_spec.rb +0 -100
  245. data/spec/gitlab/client/merge_requests_spec.rb +0 -224
  246. data/spec/gitlab/client/milestones_spec.rb +0 -98
  247. data/spec/gitlab/client/namespaces_spec.rb +0 -22
  248. data/spec/gitlab/client/notes_spec.rb +0 -333
  249. data/spec/gitlab/client/pipeline_triggers_spec.rb +0 -157
  250. data/spec/gitlab/client/pipelines_spec.rb +0 -95
  251. data/spec/gitlab/client/projects_spec.rb +0 -613
  252. data/spec/gitlab/client/repositories_spec.rb +0 -94
  253. data/spec/gitlab/client/repository_files_spec.rb +0 -95
  254. data/spec/gitlab/client/runners_spec.rb +0 -185
  255. data/spec/gitlab/client/services_spec.rb +0 -55
  256. data/spec/gitlab/client/snippets_spec.rb +0 -100
  257. data/spec/gitlab/client/system_hooks_spec.rb +0 -69
  258. data/spec/gitlab/client/tags_spec.rb +0 -109
  259. data/spec/gitlab/client/todos_spec.rb +0 -45
  260. data/spec/gitlab/client/users_spec.rb +0 -418
  261. data/spec/gitlab/error_spec.rb +0 -45
  262. data/spec/gitlab/file_response_spec.rb +0 -33
  263. data/spec/gitlab/help_spec.rb +0 -46
  264. data/spec/gitlab/objectified_hash_spec.rb +0 -48
  265. data/spec/gitlab/page_links_spec.rb +0 -16
  266. data/spec/gitlab/paginated_response_spec.rb +0 -60
  267. data/spec/gitlab/request_spec.rb +0 -73
  268. data/spec/gitlab/shell_history_spec.rb +0 -53
  269. data/spec/gitlab/shell_spec.rb +0 -80
  270. data/spec/gitlab_spec.rb +0 -97
  271. data/spec/spec_helper.rb +0 -74
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2fd8bd1d12fdceba122d4fd99e3df259c399e629
4
- data.tar.gz: dd195a082fc9a572a22ff4074306891ccc9553a1
2
+ SHA256:
3
+ metadata.gz: 9a9218b2e2622283ff16c91d001d99d9f81e9ee7c6acd285a640553c8c8fd24f
4
+ data.tar.gz: 7603515dec3c85ea53cbef33acc9131d21605d9eab8f668476c36afa58837b76
5
5
  SHA512:
6
- metadata.gz: 0edc2245a554decf8c18723979c256e6e7926d67521fa9ffeef11508b3bad1501e31ea3fe7ba91c1e9a5efe98a66149e6be3f2adcb25199c3118e5e6bde9b847
7
- data.tar.gz: 12aa581f975cd5bbc7cebe3fb75eef20d1fb87eab9119af485c3a2158779a673cd0c1da74ee4a0d91f05adfe582a35f906e7679f2fd4650f65b5c04167926c28
6
+ metadata.gz: ec5e891011991391aaa42a86ef3c2506a1541c0c63526c820e1b67bafa17a743d7ce4f00531a074cf982be7b35d2d3a37eeb1ebab8cd619af67680c882dac708
7
+ data.tar.gz: 7ef86a70f12613923fa0dd59a87164f16cc50d4ebf114fb8bed9756a55b4ddb7363d26c9e3c2f4034c0e32ecda9805bc5577f006cfbb49f6c0d9530e196c7e04
data/CHANGELOG.md CHANGED
@@ -1,6 +1,8 @@
1
- ## Change Log
1
+ ## CHANGELOG
2
2
 
3
- ### Unreleased
3
+ ### Newer releases
4
+
5
+ Please see: https://github.com/NARKOZ/gitlab/releases
4
6
 
5
7
  ### 4.2.0 (13/07/2017)
6
8
  - Use `url_encode` in all `Commit` resources (@grodowski)
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012-2015 Nihad Abbasov <mail@narkoz.me>
1
+ Copyright (c) 2012-2020 Nihad Abbasov <nihad@42na.in>
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without
data/README.md CHANGED
@@ -1,17 +1,16 @@
1
1
  # Gitlab
2
2
 
3
- [![Build Status](https://img.shields.io/travis/NARKOZ/gitlab.svg?style=flat)](https://travis-ci.org/NARKOZ/gitlab)
4
- [![Code Climate](https://img.shields.io/codeclimate/github/NARKOZ/gitlab.svg?style=flat)](https://codeclimate.com/github/NARKOZ/gitlab)
5
- [![Inline docs](http://inch-ci.org/github/NARKOZ/gitlab.svg?style=flat)](https://inch-ci.org/github/NARKOZ/gitlab)
6
- [![Gem version](https://img.shields.io/gem/v/gitlab.svg?style=flat)](https://rubygems.org/gems/gitlab)
7
- [![License](https://img.shields.io/badge/license-BSD-red.svg?style=flat)](https://github.com/NARKOZ/gitlab/blob/master/LICENSE.txt)
8
-
9
- [website](http://narkoz.github.io/gitlab) |
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 will only support Ruby 2.0+ and Gitlab API v4.
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 = 'http://example.net/api/v4'
52
- # => "http://example.net/api/v4"
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 w/ basic auth
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(endpoint: 'https://api.example.com', private_token: 'qEsq1pt6HJPaNciie3MG')
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](http://rubydoc.info/gems/gitlab/frames).
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 gitlab. In order to make that work you need to set a few environment variables:
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](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.
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: http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client/Users#users-instance_method
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: http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client/Users#user-instance_method
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: http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client/Users#user-instance_method
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: http://www.rubydoc.info/gems/gitlab/3.4.0/Gitlab/Client/MergeRequests#create_merge_request-instance_method
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](http://narkoz.github.io/gitlab).
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('../../lib', __FILE__)
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
- alias_method :auth_token=, :private_token=
9
+ alias auth_token= private_token=
8
10
 
9
11
  # Creates a new API.
10
12
  # @raise [Error:MissingCredentials]
11
- def initialize(options={})
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
- set_request_defaults(@sudo)
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 = args.shift.strip rescue 'help'
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 ? Gitlab.endpoint : 'not set'
39
- private_token = Gitlab.private_token ? Gitlab.private_token : 'not set'
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 "Unknown command. Run `gitlab help` for a list of available commands."
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
- 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
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)
@@ -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
- extend self
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
- if args.any? && args.last.is_a?(String) && args.last.start_with?('--only=')
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
- if args.any? && args.last.is_a?(String) && args.last.start_with?('--except=')
52
- args.last.gsub('--except=', '').split(',')
53
- else
54
- []
55
- end
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
- if cmd.start_with?('remove_') || cmd.start_with?('delete_')
71
- puts "Are you sure? (y/n)"
72
- if %w(y yes).include?($stdin.gets.to_s.strip.downcase)
73
- puts 'Proceeding..'
74
- else
75
- puts 'Command aborted.'
76
- exit(1)
77
- end
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 msg.
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 msg
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
- end
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.has_key?('id') ? value['id'] : 'Hash'
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=false)
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
- when Hash
173
- row[key] = 'Hash'
174
- when StringIO
175
- row[key] = Base64.encode64(hash[key].read)
176
- when nil
177
- row[key] = nil
178
- else
179
- row[key] = hash[key]
180
- end
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 > 0
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.sort { |x, y| x.to_s <=> y.to_s }
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
- begin
206
- data = args.any? ? Gitlab.send(cmd, *args) : Gitlab.send(cmd)
207
- rescue => e
208
- puts e.message
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), newhash|
220
- begin
221
- newhash[key.to_sym] = symbolize_keys(value)
222
- rescue NoMethodError
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
- begin
234
- yaml = YAML.load(arg)
235
- rescue Psych::SyntaxError
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