labclient 0.1.5 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) 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 +22 -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 +4 -4
  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 +8 -2
  25. data/lib/labclient/issues/issue.rb +10 -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/overview.rb +68 -4
  34. data/lib/labclient/paginated_response.rb +2 -0
  35. data/lib/labclient/projects/clusters/add.rb +1 -1
  36. data/lib/labclient/projects/clusters/delete.rb +5 -6
  37. data/lib/labclient/projects/clusters/show.rb +2 -2
  38. data/lib/labclient/projects/clusters/update.rb +13 -5
  39. data/lib/labclient/projects/environments/project_environment.rb +10 -0
  40. data/lib/labclient/projects/environments/stop.rb +1 -1
  41. data/lib/labclient/projects/forks/fork.rb +0 -2
  42. data/lib/labclient/projects/methods.rb +6 -0
  43. data/lib/labclient/projects/reference.rb +1 -0
  44. data/lib/labclient/projects/stars/starrers.rb +0 -2
  45. data/lib/labclient/version.rb +1 -1
  46. metadata +17 -6
@@ -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
@@ -8,11 +8,20 @@ module LabClient
8
8
  doc 'Overview' do
9
9
  title 'About'
10
10
  markdown <<~DOC
11
- Labclient is another Gitlab API Gem. A focus on ease of use and helpers and snippets.
11
+ LabClient is a Gitlab API Gem. Focusing on ease of use, documentation, helpers, and snippets.
12
12
 
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.
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
14
23
 
15
- Here's a quick whirlwind example of some of the features:
24
+ Here is a quick whirlwind example of some of the features:
16
25
  DOC
17
26
 
18
27
  demo '350689'
@@ -93,6 +102,17 @@ module LabClient
93
102
  DOC
94
103
  end
95
104
 
105
+ doc 'Authentication' do
106
+ title 'OAuth Authorization'
107
+ desc 'Use OAuth access tokens to make requests to the API on behalf of a user. '
108
+ example <<~DOC
109
+ client = LabClient::Client.new(
110
+ url: 'https://gitlab.labclient',
111
+ token: 'gitlab oauth token',
112
+ token_type: 'Authorization'
113
+ )
114
+ DOC
115
+ end
96
116
  doc 'Pagination' do
97
117
  desc 'Pagination is enabled by default if not specified. Can be explicitly enabled or disabled'
98
118
  example <<~DOC
@@ -206,16 +226,21 @@ module LabClient
206
226
  doc 'Other' do
207
227
  title 'Common Helpers'
208
228
  markdown <<~DOC
209
- The main api namespaces have a `help` and an `api_methods` methods. These will print out available methods and examples
229
+ The main api namespaces have a `help` and an `api_methods` methods. These will print out available methods and examples.
230
+
231
+ These each accept a filter argument
210
232
  DOC
211
233
 
212
234
  result <<~DOC
235
+ # General Help / Available Methods
213
236
  client.help
214
237
  client.api_methods
215
238
 
239
+ # Show Project specific Methods
216
240
  client.projects.api_methods
217
241
  # => [:show, :list, :create]
218
242
 
243
+ # Show Users specific help
219
244
  client.users.help
220
245
  Users
221
246
  Available Methods
@@ -230,6 +255,26 @@ module LabClient
230
255
  User
231
256
  - client.users.show(5)
232
257
  - client.users.show(5)
258
+
259
+ # General Help Filter
260
+ client.help :protect
261
+ Available Methods
262
+ - protected_branches protected_environments protected_tags
263
+
264
+ # Projects Help Filter
265
+ client.projects.help :cluster
266
+ Projects
267
+ Available Methods
268
+ - clusters
269
+
270
+ # Project Object Help
271
+ project = client.projects.show(16)
272
+ project.help
273
+
274
+ # Project Object Help Filter
275
+ project.help :member
276
+
277
+
233
278
  DOC
234
279
  end
235
280
 
@@ -248,6 +293,9 @@ module LabClient
248
293
  # Awesome Print all details
249
294
  project.valid_group_project_levels
250
295
  # => [:guest, :reporter, :developer, :maintainer, :owner]
296
+
297
+ # Select Data from objects with `slice`
298
+ project.slice(:readme_url, :owner)
251
299
  DOC
252
300
  end
253
301
 
@@ -291,6 +339,22 @@ module LabClient
291
339
  DOC
292
340
  end
293
341
 
342
+ doc 'Other' do
343
+ title 'Quiet'
344
+ desc 'Error messages by default are printed to STDOUT. This can be supressed via the :quiet setting'
345
+
346
+ example <<~DOC
347
+ client = LabClient::Client.new(
348
+ url: 'https://gitlab.labclient',
349
+ token: 'gitlab api token',
350
+ quiet: true
351
+ )
352
+
353
+ # Or after the init
354
+ client.settings[:quiet] = true
355
+ DOC
356
+ end
357
+
294
358
  doc 'Other' do
295
359
  title 'Curl'
296
360
  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'
@@ -21,7 +21,7 @@ module LabClient
21
21
  project_id = format_id(project_id)
22
22
  environment_id = format_id(environment_id)
23
23
 
24
- client.request(:get, "projects/#{project_id}/environments/#{environment_id}/stop", nil)
24
+ client.request(:post, "projects/#{project_id}/environments/#{environment_id}/stop", nil)
25
25
  end
26
26
  end
27
27
  end
@@ -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.5'.freeze
2
+ VERSION = '0.3.2'.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.5
4
+ version: 0.3.2
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-08-14 00:00:00.000000000 Z
11
+ date: 2021-01-01 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