labclient 0.1.4 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/lib/labclient.rb +16 -2
  3. data/lib/labclient/access_levels.rb +24 -30
  4. data/lib/labclient/client.rb +21 -8
  5. data/lib/labclient/commits/project_helpers.rb +4 -0
  6. data/lib/labclient/commits/show.rb +11 -2
  7. data/lib/labclient/common.rb +15 -6
  8. data/lib/labclient/docs.rb +9 -5
  9. data/lib/labclient/feature_flags/create.rb +48 -0
  10. data/lib/labclient/feature_flags/delete.rb +23 -0
  11. data/lib/labclient/feature_flags/feature_flag.rb +35 -0
  12. data/lib/labclient/feature_flags/list.rb +49 -0
  13. data/lib/labclient/files/update.rb +1 -1
  14. data/lib/labclient/generator/generator.rb +10 -0
  15. data/lib/labclient/generator/template_helper.rb +0 -1
  16. data/lib/labclient/groups/clusters/add.rb +46 -0
  17. data/lib/labclient/groups/clusters/client.rb +17 -0
  18. data/lib/labclient/groups/clusters/delete.rb +36 -0
  19. data/lib/labclient/groups/clusters/group_cluster.rb +37 -0
  20. data/lib/labclient/groups/clusters/list.rb +28 -0
  21. data/lib/labclient/groups/clusters/show.rb +29 -0
  22. data/lib/labclient/groups/clusters/update.rb +44 -0
  23. data/lib/labclient/groups/group.rb +14 -1
  24. data/lib/labclient/http.rb +1 -1
  25. data/lib/labclient/issues/issue.rb +17 -0
  26. data/lib/labclient/issues/update.rb +20 -2
  27. data/lib/labclient/jobs/delete.rb +1 -1
  28. data/lib/labclient/jobs/keep.rb +1 -1
  29. data/lib/labclient/jobs/play.rb +1 -1
  30. data/lib/labclient/jobs/trace.rb +2 -2
  31. data/lib/labclient/klass.rb +12 -7
  32. data/lib/labclient/lab_struct.rb +4 -0
  33. data/lib/labclient/notes/epics/create.rb +8 -0
  34. data/lib/labclient/notes/issues/create.rb +8 -0
  35. data/lib/labclient/notes/merge_requests/create.rb +8 -0
  36. data/lib/labclient/overview.rb +61 -4
  37. data/lib/labclient/paginated_response.rb +2 -0
  38. data/lib/labclient/projects/clusters/add.rb +1 -1
  39. data/lib/labclient/projects/clusters/delete.rb +5 -6
  40. data/lib/labclient/projects/clusters/show.rb +2 -2
  41. data/lib/labclient/projects/clusters/update.rb +13 -5
  42. data/lib/labclient/projects/environments/project_environment.rb +10 -0
  43. data/lib/labclient/projects/forks/fork.rb +0 -2
  44. data/lib/labclient/projects/methods.rb +6 -0
  45. data/lib/labclient/projects/reference.rb +1 -0
  46. data/lib/labclient/projects/stars/starrers.rb +0 -2
  47. data/lib/labclient/version.rb +1 -1
  48. metadata +18 -7
@@ -14,7 +14,7 @@ module LabClient
14
14
 
15
15
  # API Methods here have to be explicitly documented / custom helpers
16
16
  # Assume no methods by default
17
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
17
+ # rubocop:disable Metrics/AbcSize
18
18
  def help(help_filter = nil)
19
19
  docs = LabClient::Docs.docs.dig(group_name, 'Reference')
20
20
  unless docs
@@ -27,11 +27,9 @@ module LabClient
27
27
  next unless doc[:options]
28
28
 
29
29
  doc[:options].each do |opt|
30
- if help_filter
31
- next unless (opt[:name] + opt[:text]).include? help_filter.to_s
32
- end
30
+ next if help_filter && !(opt[:name] + opt[:text]).include?(help_filter.to_s)
33
31
 
34
- puts ' ' + opt[:name]
32
+ puts " #{opt[:name]}"
35
33
  puts " #{opt[:text]}\n"
36
34
  end
37
35
  end
@@ -39,7 +37,7 @@ module LabClient
39
37
  # Ignore Output
40
38
  nil
41
39
  end
42
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
40
+ # rubocop:enable Metrics/AbcSize
43
41
 
44
42
  # Documented API Methods
45
43
  def api_methods
@@ -63,7 +61,12 @@ module LabClient
63
61
 
64
62
  # TODO: Combine all of these?
65
63
  def collect_project_id(position = 1)
66
- response.path.split('/')[position]
64
+ # Check if Path / Pagination will be blank
65
+ if response.path.nil?
66
+ response.request.base_url.split(@client.base_url, 2)[position]
67
+ else
68
+ response.path.split('/')[position]
69
+ end
67
70
  end
68
71
 
69
72
  alias collect_group_id collect_project_id
@@ -97,6 +100,7 @@ module LabClient
97
100
  self
98
101
  end
99
102
 
103
+ # rubocop:disable Lint/MissingSuper
100
104
  def initialize(hash = nil, response = nil, client = nil)
101
105
  @client = client
102
106
  @response = response
@@ -107,6 +111,7 @@ module LabClient
107
111
  @table[k] = v
108
112
  end
109
113
  end
114
+ # rubocop:enable Lint/MissingSuper
110
115
 
111
116
  # Forward response success
112
117
  def success?
@@ -13,5 +13,9 @@ module LabClient
13
13
  def as_json(*args)
14
14
  super.as_json['table']
15
15
  end
16
+
17
+ def slice(*opts)
18
+ to_h.slice(*opts)
19
+ end
16
20
  end
17
21
  end
@@ -11,6 +11,14 @@ module LabClient
11
11
  DOC
12
12
  end
13
13
 
14
+ doc 'Epics' do
15
+ desc 'Via Epic'
16
+ example <<~DOC
17
+ epic = client.epics.show(16, 2)
18
+ epic.note_create(body: 'There!')
19
+ DOC
20
+ end
21
+
14
22
  doc 'Epics' do
15
23
  markdown <<~DOC
16
24
  | Attribute | Type | Required | Description |
@@ -11,6 +11,14 @@ module LabClient
11
11
  DOC
12
12
  end
13
13
 
14
+ doc 'Issues' do
15
+ desc 'Via Issue'
16
+ example <<~DOC
17
+ issue = client.issues.show(16, 1)
18
+ issue.note_create(body: 'There!')
19
+ DOC
20
+ end
21
+
14
22
  doc 'Issues' do
15
23
  markdown <<~DOC
16
24
  | Attribute | Type | Required | Description |
@@ -11,6 +11,14 @@ module LabClient
11
11
  DOC
12
12
  end
13
13
 
14
+ doc 'Merge Request' do
15
+ desc 'Via Merge Request'
16
+ example <<~DOC
17
+ merge_request = client.merge_requests.show(16, 2)
18
+ merge_request.note_create(body: 'There!')
19
+ DOC
20
+ end
21
+
14
22
  doc 'Merge Requests' do
15
23
  markdown <<~DOC
16
24
  | Attribute | Type | Required | Description |
@@ -7,11 +7,24 @@ module LabClient
7
7
 
8
8
  doc 'Overview' do
9
9
  title 'About'
10
- desc <<~DOC
11
- Labclient is another Gitlab API Gem. A focus on ease of use and helpers and snippets.
10
+ markdown <<~DOC
11
+ LabClient is a Gitlab API Gem. Focusing on ease of use, documentation, helpers, and snippets.
12
+
13
+ - Objects for resources (User, Project)
14
+ - Method Chaining ( project.branch(:master).pipelines )
15
+
16
+ Lots of Helpers
17
+
18
+ - Pagination
19
+ - IRB/Pry
20
+ - Setup: credentials file, profiles, and prompt
21
+ - Permission Levels
22
+ - Curl generator
12
23
 
13
- <a href="https://github.com/NARKOZ/gitlab">Gitlab</a> is an excellent gem, and is nearly complete in its implementation. While this is still a work in progress and you are looking for general use you should use it.
24
+ Here is a quick whirlwind example of some of the features:
14
25
  DOC
26
+
27
+ demo '350689'
15
28
  end
16
29
 
17
30
  doc 'Overview' do
@@ -202,16 +215,21 @@ module LabClient
202
215
  doc 'Other' do
203
216
  title 'Common Helpers'
204
217
  markdown <<~DOC
205
- The main api namespaces have a `help` and an `api_methods` methods. These will print out available methods and examples
218
+ The main api namespaces have a `help` and an `api_methods` methods. These will print out available methods and examples.
219
+
220
+ These each accept a filter argument
206
221
  DOC
207
222
 
208
223
  result <<~DOC
224
+ # General Help / Available Methods
209
225
  client.help
210
226
  client.api_methods
211
227
 
228
+ # Show Project specific Methods
212
229
  client.projects.api_methods
213
230
  # => [:show, :list, :create]
214
231
 
232
+ # Show Users specific help
215
233
  client.users.help
216
234
  Users
217
235
  Available Methods
@@ -226,6 +244,26 @@ module LabClient
226
244
  User
227
245
  - client.users.show(5)
228
246
  - client.users.show(5)
247
+
248
+ # General Help Filter
249
+ client.help :protect
250
+ Available Methods
251
+ - protected_branches protected_environments protected_tags
252
+
253
+ # Projects Help Filter
254
+ client.projects.help :cluster
255
+ Projects
256
+ Available Methods
257
+ - clusters
258
+
259
+ # Project Object Help
260
+ project = client.projects.show(16)
261
+ project.help
262
+
263
+ # Project Object Help Filter
264
+ project.help :member
265
+
266
+
229
267
  DOC
230
268
  end
231
269
 
@@ -244,6 +282,9 @@ module LabClient
244
282
  # Awesome Print all details
245
283
  project.valid_group_project_levels
246
284
  # => [:guest, :reporter, :developer, :maintainer, :owner]
285
+
286
+ # Select Data from objects with `slice`
287
+ project.slice(:readme_url, :owner)
247
288
  DOC
248
289
  end
249
290
 
@@ -287,6 +328,22 @@ module LabClient
287
328
  DOC
288
329
  end
289
330
 
331
+ doc 'Other' do
332
+ title 'Quiet'
333
+ desc 'Error messages by default are printed to STDOUT. This can be supressed via the :quiet setting'
334
+
335
+ example <<~DOC
336
+ client = LabClient::Client.new(
337
+ url: 'https://gitlab.labclient',
338
+ token: 'gitlab api token',
339
+ quiet: true
340
+ )
341
+
342
+ # Or after the init
343
+ client.settings[:quiet] = true
344
+ DOC
345
+ end
346
+
290
347
  doc 'Other' do
291
348
  title 'Curl'
292
349
  desc 'Sometimes you just wana have a curl example to test or send someone'
@@ -40,7 +40,9 @@ module LabClient
40
40
  DOC
41
41
  end
42
42
 
43
+ # rubocop:disable Lint/MissingSuper
43
44
  def respond_to_missing?(method_name, include_private = false); end
45
+ # rubocop:enable Lint/MissingSuper
44
46
 
45
47
  def each_page(&block)
46
48
  yield @array # This will eventually be the whole list
@@ -27,7 +27,7 @@ module LabClient
27
27
  | --------- | ---- | -------- | ----------- |
28
28
  | name | string | yes | The name of the cluster |
29
29
  | domain | string | no | The base domain of the cluster |
30
- | management_project_id | integer | no | The ID of the [management project](../user/clusters/management_project.md) for the cluster |
30
+ | management_project_id | integer | no | The ID of the management project for the cluster |
31
31
  | enabled | boolean | no | Determines if cluster is active or not, defaults to true |
32
32
  | managed | boolean | no | Determines if GitLab will manage namespaces and service accounts for this cluster, defaults to true |
33
33
  | platform_kubernetes_attributes[api_url] | string | yes | The URL to access the Kubernetes API |
@@ -11,11 +11,10 @@ module LabClient
11
11
 
12
12
  doc 'Delete' do
13
13
  markdown <<~DOC
14
- | Attribute | Type | Required | Description |
15
- | ---------- | ----- | --------- | ------------ |
16
- | url | String | yes | The URL of the remote repository to be clustered. |
17
- | enabled | Boolean | no | Determines if the cluster is enabled. |
18
- | only_protected_branches| Boolean | no | Determines if only protected branches are clustered. |
14
+ | Attribute | Type | Required | Description |
15
+ | --------- | ---- | -------- | ----------- |
16
+ | `id` | integer | yes | The ID of the project owned by the authenticated user |
17
+ | `cluster_id` | integer | yes | The ID of the cluster |
19
18
  DOC
20
19
  end
21
20
 
@@ -23,7 +22,7 @@ module LabClient
23
22
  desc 'Via ProjectCluster [Params]'
24
23
  example <<~DOC
25
24
  cluster = client.projects.clusters.list(310).first
26
- cluster.update(enabled: false)
25
+ cluster.delete
27
26
  DOC
28
27
  end
29
28
 
@@ -12,10 +12,10 @@ module LabClient
12
12
  end
13
13
 
14
14
  doc 'Show' do
15
- desc 'Via Project'
15
+ desc 'Via Project [Cluster ID]'
16
16
  example <<~DOC
17
17
  project = client.projects.show(16)
18
- project.clusters
18
+ project.cluster(cluster_id)
19
19
  DOC
20
20
  end
21
21
 
@@ -11,11 +11,19 @@ module LabClient
11
11
 
12
12
  doc 'Update' do
13
13
  markdown <<~DOC
14
- | Attribute | Type | Required | Description |
15
- | ---------- | ----- | --------- | ------------ |
16
- | url | String | yes | The URL of the remote repository to be clustered. |
17
- | enabled | Boolean | no | Determines if the cluster is enabled. |
18
- | only_protected_branches| Boolean | no | Determines if only protected branches are clustered. |
14
+ | Attribute | Type | Required | Description |
15
+ | --------- | ---- | -------- | ----------- |
16
+ | name | string | yes | The name of the cluster |
17
+ | domain | string | no | The base domain of the cluster |
18
+ | management_project_id | integer | no | The ID of the management project for the cluster |
19
+ | platform_kubernetes_attributes[api_url] | string | yes | The URL to access the Kubernetes API |
20
+ | platform_kubernetes_attributes[token] | string | yes | The token to authenticate against Kubernetes |
21
+ | platform_kubernetes_attributes[ca_cert] | string | no | TLS certificate. Required if API is using a self-signed TLS certificate. |
22
+ | platform_kubernetes_attributes[namespace] | string | no | The unique namespace related to the project |
23
+ | environment_scope | string | no | The associated environment to the cluster. Defaults to * **(PREMIUM)** |
24
+
25
+ `name`, `api_url`, `ca_cert` and `token` can only be updated if the cluster was added through the
26
+ “Add existing Kubernetes cluster” option or through the “Add existing cluster to project” endpoint.
19
27
  DOC
20
28
  end
21
29
 
@@ -24,6 +24,14 @@ module LabClient
24
24
  client.projects.environments.delete(project_id, id)
25
25
  end
26
26
 
27
+ def show
28
+ project_id = collect_project_id
29
+
30
+ update_self client.projects.environments.show(project_id, id)
31
+ end
32
+
33
+ alias reload show
34
+
27
35
  def stop
28
36
  project_id = collect_project_id
29
37
 
@@ -35,6 +43,8 @@ module LabClient
35
43
  help do
36
44
  subtitle 'ProjectEnvironment'
37
45
  option 'project', 'Show Project'
46
+ option 'show', 'Collect/reload environment'
47
+ option 'reload', 'Collect/reload environment'
38
48
  option 'update', 'Update this environment [Hash]'
39
49
  option 'delete', 'Delete this environment'
40
50
  option 'stop', 'Stop this environment'
@@ -2,8 +2,6 @@
2
2
  module LabClient
3
3
  # Specifics
4
4
  class Projects < Common
5
- @group_name = 'Project Forks'
6
-
7
5
  doc 'Create' do
8
6
  desc 'Forks a project into the user namespace of the authenticated user or the one provided.'
9
7
  example 'client.projects.fork(299)'
@@ -476,6 +476,8 @@ module LabClient
476
476
  client.projects.environments.show(id, environment_id)
477
477
  end
478
478
 
479
+ alias environment environment_show
480
+
479
481
  def environment_create(query)
480
482
  client.projects.environments.create(id, query)
481
483
  end
@@ -707,6 +709,10 @@ module LabClient
707
709
  client.projects.clusters.list(id)
708
710
  end
709
711
 
712
+ def cluster(cluster_id)
713
+ client.projects.clusters.show(id, cluster_id)
714
+ end
715
+
710
716
  # Reload
711
717
  def reload
712
718
  update_self client.projects.show(id)
@@ -139,6 +139,7 @@ module LabClient
139
139
 
140
140
  # Commits
141
141
  option 'commits', 'List Commits [Hash]'
142
+ option 'commit', 'Show Commit [String/Commit Sha]'
142
143
  option 'commit_create', 'Create new commit [Hash]'
143
144
  option 'commit_refs', 'Get all references (from branches or tags) a commit is pushed to. [Commit ID, Scope]'
144
145
  option 'commit_cherry_pick', 'Cherry picks a commit to a target branch. [Commit ID, Branch]'
@@ -2,8 +2,6 @@
2
2
  module LabClient
3
3
  # Specifics
4
4
  class Projects < Common
5
- @group_name = 'Project Stars'
6
-
7
5
  doc 'Starrers' do
8
6
  desc 'List the users who starred the specified project. [user id]'
9
7
  example 'client.projects.starrers(5)'
@@ -1,3 +1,3 @@
1
1
  module LabClient
2
- VERSION = '0.1.4'.freeze
2
+ VERSION = '0.3.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: labclient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Davin Walker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-28 00:00:00.000000000 Z
11
+ date: 2020-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -210,16 +210,16 @@ dependencies:
210
210
  name: rubocop
211
211
  requirement: !ruby/object:Gem::Requirement
212
212
  requirements:
213
- - - "~>"
213
+ - - "<"
214
214
  - !ruby/object:Gem::Version
215
- version: '0.82'
215
+ version: 0.91.0
216
216
  type: :development
217
217
  prerelease: false
218
218
  version_requirements: !ruby/object:Gem::Requirement
219
219
  requirements:
220
- - - "~>"
220
+ - - "<"
221
221
  - !ruby/object:Gem::Version
222
- version: '0.82'
222
+ version: 0.91.0
223
223
  - !ruby/object:Gem::Dependency
224
224
  name: simplecov
225
225
  requirement: !ruby/object:Gem::Requirement
@@ -398,6 +398,10 @@ files:
398
398
  - lib/labclient/events/list.rb
399
399
  - lib/labclient/events/project.rb
400
400
  - lib/labclient/events/user.rb
401
+ - lib/labclient/feature_flags/create.rb
402
+ - lib/labclient/feature_flags/delete.rb
403
+ - lib/labclient/feature_flags/feature_flag.rb
404
+ - lib/labclient/feature_flags/list.rb
401
405
  - lib/labclient/files/create.rb
402
406
  - lib/labclient/files/delete.rb
403
407
  - lib/labclient/files/show.rb
@@ -423,6 +427,13 @@ files:
423
427
  - lib/labclient/groups/badges/preview.rb
424
428
  - lib/labclient/groups/badges/show.rb
425
429
  - lib/labclient/groups/badges/update.rb
430
+ - lib/labclient/groups/clusters/add.rb
431
+ - lib/labclient/groups/clusters/client.rb
432
+ - lib/labclient/groups/clusters/delete.rb
433
+ - lib/labclient/groups/clusters/group_cluster.rb
434
+ - lib/labclient/groups/clusters/list.rb
435
+ - lib/labclient/groups/clusters/show.rb
436
+ - lib/labclient/groups/clusters/update.rb
426
437
  - lib/labclient/groups/create.rb
427
438
  - lib/labclient/groups/delete.rb
428
439
  - lib/labclient/groups/group.rb
@@ -902,7 +913,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
902
913
  - !ruby/object:Gem::Version
903
914
  version: '0'
904
915
  requirements: []
905
- rubygems_version: 3.0.3
916
+ rubygems_version: 3.1.4
906
917
  signing_key:
907
918
  specification_version: 4
908
919
  summary: Gitlab API Client