labclient 0.1.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/lib/labclient.rb +19 -3
  3. data/lib/labclient/access_levels.rb +24 -30
  4. data/lib/labclient/client.rb +54 -7
  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/files/update.rb +1 -1
  10. data/lib/labclient/generator/generator.rb +7 -7
  11. data/lib/labclient/generator/template_helper.rb +0 -1
  12. data/lib/labclient/generator/wizard.rb +6 -2
  13. data/lib/labclient/groups/clusters/add.rb +46 -0
  14. data/lib/labclient/groups/clusters/client.rb +17 -0
  15. data/lib/labclient/groups/clusters/delete.rb +36 -0
  16. data/lib/labclient/groups/clusters/group_cluster.rb +37 -0
  17. data/lib/labclient/groups/clusters/list.rb +28 -0
  18. data/lib/labclient/groups/clusters/show.rb +29 -0
  19. data/lib/labclient/groups/clusters/update.rb +44 -0
  20. data/lib/labclient/groups/group.rb +14 -1
  21. data/lib/labclient/http.rb +1 -1
  22. data/lib/labclient/issues/issue.rb +17 -0
  23. data/lib/labclient/issues/update.rb +20 -2
  24. data/lib/labclient/jobs/delete.rb +1 -1
  25. data/lib/labclient/jobs/keep.rb +1 -1
  26. data/lib/labclient/jobs/play.rb +1 -1
  27. data/lib/labclient/jobs/trace.rb +2 -2
  28. data/lib/labclient/klass.rb +6 -6
  29. data/lib/labclient/lab_struct.rb +4 -0
  30. data/lib/labclient/members/member.rb +1 -0
  31. data/lib/labclient/notes/epics/create.rb +8 -0
  32. data/lib/labclient/notes/issues/create.rb +8 -0
  33. data/lib/labclient/notes/merge_requests/create.rb +8 -0
  34. data/lib/labclient/overview.rb +104 -12
  35. data/lib/labclient/paginated_response.rb +2 -0
  36. data/lib/labclient/projects/clusters/add.rb +1 -1
  37. data/lib/labclient/projects/clusters/delete.rb +5 -6
  38. data/lib/labclient/projects/clusters/show.rb +2 -2
  39. data/lib/labclient/projects/clusters/update.rb +13 -5
  40. data/lib/labclient/projects/environments/project_environment.rb +10 -0
  41. data/lib/labclient/projects/forks/fork.rb +0 -2
  42. data/lib/labclient/projects/methods.rb +23 -0
  43. data/lib/labclient/projects/reference.rb +7 -0
  44. data/lib/labclient/projects/stars/starrers.rb +0 -2
  45. data/lib/labclient/protected_branches/protect.rb +6 -5
  46. data/lib/labclient/protected_environments/list.rb +29 -0
  47. data/lib/labclient/protected_environments/protect.rb +53 -0
  48. data/lib/labclient/protected_environments/protected_environment.rb +22 -0
  49. data/lib/labclient/protected_environments/show.rb +24 -0
  50. data/lib/labclient/protected_environments/unprotect.rb +31 -0
  51. data/lib/labclient/users/membership.rb +62 -0
  52. data/lib/labclient/users/memberships.rb +8 -3
  53. data/lib/labclient/users/user.rb +1 -1
  54. data/lib/labclient/version.rb +1 -1
  55. metadata +19 -6
@@ -0,0 +1,17 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Inspect Helper
4
+ class GroupClusters < Common
5
+ include ClassHelpers
6
+ end
7
+ end
8
+
9
+ # Top namespace
10
+ module LabClient
11
+ # Specifics
12
+ class Groups < Common
13
+ def clusters
14
+ GroupClusters.new(client)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,36 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Specifics
4
+ class GroupClusters < Common
5
+ doc 'Delete' do
6
+ desc 'Deletes an existing group cluster. [Project ID, Mirror ID, Params]'
7
+ example 'client.group.clusters.update(310, 3, enabled: true)'
8
+
9
+ result '=> #<GroupCluster id: 3, name: planet bob>'
10
+ end
11
+
12
+ doc 'Delete' do
13
+ markdown <<~DOC
14
+ | Attribute | Type | Required | Description |
15
+ | ---------- | ----- | --------- | ------------ |
16
+ | `id` | integer/string | yes | The ID or URL-encoded path of the group |
17
+ | `cluster_id` | integer | yes | The ID of the cluster |
18
+ DOC
19
+ end
20
+
21
+ doc 'Delete' do
22
+ desc 'Via GroupCluster [Params]'
23
+ example <<~DOC
24
+ cluster = client.groups.clusters.list(310).first
25
+ cluster.delete
26
+ DOC
27
+ end
28
+
29
+ def delete(group_id, cluster_id)
30
+ group_id = format_id(group_id)
31
+ cluster_id = format_id(cluster_id)
32
+
33
+ client.request(:delete, "groups/#{group_id}/clusters/#{cluster_id}", GroupCluster)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,37 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Inspect Helper
4
+ class GroupCluster < Klass
5
+ include ClassHelpers
6
+ def inspect
7
+ "#<GroupCluster id: #{id}, name: #{name}>"
8
+ end
9
+
10
+ def group
11
+ group_id = collect_group_id
12
+ client.groups.show group_id
13
+ end
14
+
15
+ def update(query)
16
+ group_id = collect_group_id
17
+
18
+ update_self client.groups.clusters.update(group_id, id, query)
19
+ end
20
+
21
+ def delete
22
+ group_id = collect_group_id
23
+
24
+ client.groups.clusters.delete(group_id, id)
25
+ end
26
+
27
+ date_time_attrs %i[created_at]
28
+ user_attrs %i[uster]
29
+
30
+ help do
31
+ subtitle 'GroupCluster'
32
+ option 'group', 'Show Group'
33
+ option 'update', 'Update this Cluster [Hash]'
34
+ option 'delete', 'Delete cluster'
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,28 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Specifics
4
+ class GroupClusters < Common
5
+ doc 'List' do
6
+ desc 'Returns a list of group clusters. [Group ID]'
7
+ example 'client.groups.clusters.list(16)'
8
+
9
+ result <<~DOC
10
+ => #<GroupCluster id: 1, name: cluster-5>]
11
+ DOC
12
+ end
13
+
14
+ doc 'List' do
15
+ desc 'Via Group'
16
+ example <<~DOC
17
+ group = client.groups.show(16)
18
+ group.clusters
19
+ DOC
20
+ end
21
+
22
+ def list(group_id)
23
+ group_id = format_id(group_id)
24
+
25
+ client.request(:get, "groups/#{group_id}/clusters", GroupCluster)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,29 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Specifics
4
+ class GroupClusters < Common
5
+ doc 'Show' do
6
+ desc 'Gets a single group cluster. [Group ID, Cluster ID]'
7
+ example 'client.groups.clusters.list(16)'
8
+
9
+ result <<~DOC
10
+ => #<GroupCluster id: 1, name: cluster-5>
11
+ DOC
12
+ end
13
+
14
+ doc 'Show' do
15
+ desc 'Via Group'
16
+ example <<~DOC
17
+ group = client.groups.show(16)
18
+ group.cluster(cluster_id)
19
+ DOC
20
+ end
21
+
22
+ def show(group_id, cluster_id)
23
+ cluster_id = format_id(cluster_id)
24
+ group_id = format_id(group_id)
25
+
26
+ client.request(:get, "groups/#{group_id}/clusters/#{cluster_id}", GroupCluster)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,44 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Specifics
4
+ class GroupClusters < Common
5
+ doc 'Update' do
6
+ desc 'Updates an existing group cluster. [Group ID, Cluster ID, Hash]'
7
+ example 'client.groups.clusters.update(310, 3, name: "Sweet")'
8
+
9
+ result '=> #<GroupCluster id: 3, name: Sweet>'
10
+ end
11
+
12
+ doc 'Update' do
13
+ markdown <<~DOC
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
+ | environment_scope | string | no | The associated environment to the cluster. Defaults to * **(PREMIUM)** |
23
+
24
+ `name`, `api_url`, `ca_cert` and `token` can only be updated if the cluster was added through the
25
+ “Add existing Kubernetes cluster” option or through the “Add existing cluster to project” endpoint.
26
+ DOC
27
+ end
28
+
29
+ doc 'Update' do
30
+ desc 'Via GroupCluster [Params]'
31
+ example <<~DOC
32
+ cluster = client.groups.clusters.list(310).first
33
+ cluster.update(name: 'bump')
34
+ DOC
35
+ end
36
+
37
+ def update(group_id, cluster_id, query)
38
+ group_id = format_id(group_id)
39
+ cluster_id = format_id(cluster_id)
40
+
41
+ client.request(:put, "groups/#{group_id}/clusters/#{cluster_id}", GroupCluster, query)
42
+ end
43
+ end
44
+ end
@@ -42,7 +42,7 @@ module LabClient
42
42
 
43
43
  def projects(query = {})
44
44
  # Details Query Includes Projects
45
- if query.empty? && !@table.dig(:projects).blank?
45
+ if query.empty? && !@table[:projects].blank?
46
46
  @table[:projects].map { |project| LabClient::Project.new(project, response, client) }
47
47
  else
48
48
  client.groups.projects(id, query)
@@ -151,6 +151,15 @@ module LabClient
151
151
  client.groups.badges.delete(id, badge_id)
152
152
  end
153
153
 
154
+ # Group Clusters
155
+ def clusters
156
+ client.groups.clusters.list(id)
157
+ end
158
+
159
+ def cluster(cluster_id)
160
+ client.groups.clusters.show(id, cluster_id)
161
+ end
162
+
154
163
  # Group Epics
155
164
  def epics
156
165
  client.epics.list(id)
@@ -295,6 +304,10 @@ module LabClient
295
304
  option 'badge_show', 'Show specific badge from group [Badge ID]'
296
305
  option 'badge_update', 'Update group badge [Badge ID, Hash]'
297
306
 
307
+ # Clusters
308
+ option 'clusters', "List this group's clusters"
309
+ option 'cluster', 'Show specific cluster from group [Cluster ID]'
310
+
298
311
  # Epics
299
312
  option 'epics', "List this group's epics"
300
313
  option 'epic_create', 'Create group epic [Hash]'
@@ -73,7 +73,7 @@ module Typhoeus
73
73
  def process_body
74
74
  if body.empty?
75
75
  nil
76
- elsif headers['content-type'] == 'text/plain'
76
+ elsif headers['content-type']&.include? 'text/plain'
77
77
  body
78
78
  else
79
79
  Oj.load(body, mode: :compat, object_class: LabClient::LabStruct)
@@ -14,6 +14,16 @@ module LabClient
14
14
  # User Fields
15
15
  user_attrs %i[closed_by author assignee]
16
16
 
17
+ # Via State Events
18
+ def close
19
+ client.issues.update(project_id, iid, state_event: :close)
20
+ end
21
+
22
+ # Via State Events
23
+ def reopen
24
+ client.issues.update(project_id, iid, state_event: :reopen)
25
+ end
26
+
17
27
  def update(query)
18
28
  client.issues.update(project_id, iid, query)
19
29
  end
@@ -96,6 +106,13 @@ module LabClient
96
106
  update_self client.issues.show(project_id, iid)
97
107
  end
98
108
 
109
+ def project
110
+ # If from List Project ID isn't stored
111
+ project_id = collect_project_id if project_id.nil?
112
+
113
+ client.projects.show(project_id)
114
+ end
115
+
99
116
  help do
100
117
  subtitle 'Issue'
101
118
  option 'update', 'Update issue (accepts hash).'
@@ -18,19 +18,37 @@ module LabClient
18
18
  |-------------------------------------------|----------------|----------|--------------|
19
19
  | title | string | no | The title of an issue |
20
20
  | description | string | no | The description of an issue. Limited to 1,048,576 characters. |
21
+
22
+
21
23
  DOC
22
24
  end
23
25
 
24
26
  doc 'Update' do
25
- desc 'Close Ticket'
27
+ title 'Close / Reopen'
28
+ markdown <<~DOC
29
+ Closing/Reopening of issues is handled via state_events. Either :close, or :reopen. The issue objects themselves also have helpers `reopen` `close`.
30
+ DOC
31
+
26
32
  example 'client.issues.update(5, 1, state_event: :close)'
27
33
  end
28
34
 
35
+ doc 'Update' do
36
+ example 'client.issues.update(5, 1, state_event: :reopen)'
37
+ end
38
+
39
+ doc 'Update' do
40
+ desc 'Through Issue Object'
41
+ example <<~DOC
42
+ issue = client.issues.show(5,1)
43
+ issue.close
44
+ DOC
45
+ end
46
+
29
47
  doc 'Update' do
30
48
  desc 'Through Issue Object'
31
49
  example <<~DOC
32
50
  issue = client.issues.show(5,1)
33
- issue.update(title: "Dew it!")
51
+ issue.reopen
34
52
  DOC
35
53
  end
36
54
 
@@ -3,7 +3,7 @@ module LabClient
3
3
  # Specifics
4
4
  class Jobs < Common
5
5
  doc 'Update' do
6
- title 'Retry'
6
+ title 'Delete'
7
7
  desc 'Delete artifacts of a job. [Project ID, Job ID]'
8
8
  example 'client.jobs.delete(264, 14)'
9
9
  end
@@ -3,7 +3,7 @@ module LabClient
3
3
  # Specifics
4
4
  class Jobs < Common
5
5
  doc 'Update' do
6
- title 'Retry'
6
+ title 'Keep'
7
7
  desc 'Prevents artifacts from being deleted when expiration is set. [Project ID, Job ID]'
8
8
  example 'client.jobs.keep(264, 14)'
9
9
  end
@@ -3,7 +3,7 @@ module LabClient
3
3
  # Specifics
4
4
  class Jobs < Common
5
5
  doc 'Update' do
6
- title 'Retry'
6
+ title 'Play'
7
7
  desc 'Triggers a manual action to start a job. [Project ID, Job ID]'
8
8
  example 'client.jobs.play(264, 14)'
9
9
  end
@@ -20,14 +20,14 @@ module LabClient
20
20
  desc 'via Job'
21
21
  example <<~DOC
22
22
  job = client.jobs.show(264,1)
23
- job.trace
23
+ job.trace #=> String
24
24
  DOC
25
25
  end
26
26
 
27
27
  def trace(project_id, job_id)
28
28
  job_id = format_id(job_id)
29
29
  project_id = format_id(project_id)
30
- puts client.request(:get, "projects/#{project_id}/jobs/#{job_id}/trace")
30
+ client.request(:get, "projects/#{project_id}/jobs/#{job_id}/trace")
31
31
  end
32
32
  end
33
33
  end
@@ -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
@@ -97,6 +95,7 @@ module LabClient
97
95
  self
98
96
  end
99
97
 
98
+ # rubocop:disable Lint/MissingSuper
100
99
  def initialize(hash = nil, response = nil, client = nil)
101
100
  @client = client
102
101
  @response = response
@@ -107,6 +106,7 @@ module LabClient
107
106
  @table[k] = v
108
107
  end
109
108
  end
109
+ # rubocop:enable Lint/MissingSuper
110
110
 
111
111
  # Forward response success
112
112
  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
@@ -51,6 +51,7 @@ module LabClient
51
51
  option 'level', 'Humanized symbol of access level. e.g. :developer'
52
52
  option 'user', 'Collect user object.'
53
53
  option '<permission>?', 'True/False evaluation each guest?, developer? etc'
54
+ option 'greater_than', 'True/False if user has greater than [Permission Name]'
54
55
  end
55
56
  end
56
57
  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 |