labclient 0.1.4 → 0.3.1

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 (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
@@ -33,7 +33,7 @@ module LabClient
33
33
  desc 'via Project'
34
34
  example <<~DOC
35
35
  project = client.projects.show(264)
36
- project.file_create('other.md',
36
+ project.file_update('other.md',
37
37
  branch: :master,
38
38
  commit_message: "New File!",
39
39
  content: "Content!")
@@ -26,6 +26,16 @@ module LabClient
26
26
  example 'gem install faker'
27
27
  end
28
28
 
29
+ doc 'Wizard' do
30
+ title 'Quickstart'
31
+ desc 'To run, create the client/wizard and run!'
32
+ example <<~DOC
33
+ require 'labclient'
34
+ client = LabClient::Client.new(url: 'https://labclient', token: 'super_secret')
35
+ client.wizard.run!
36
+ DOC
37
+ end
38
+
29
39
  doc 'Wizard' do
30
40
  title 'Client'
31
41
  desc <<-DOC
@@ -74,7 +74,6 @@ module LabClient
74
74
 
75
75
  def generate_group
76
76
  @group = client.groups.create(name: group_name, path: group_path)
77
- # puts "#{@group.name} - #{@group.web_url}"
78
77
  raise 'Unable to Create Group' unless @group.success?
79
78
  end
80
79
  end
@@ -0,0 +1,46 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Specifics
4
+ class GroupClusters < Common
5
+ doc 'Add' do
6
+ desc 'Adds an existing Kubernetes cluster to the group. [Group ID, Hash]'
7
+ example <<~DOC
8
+ params = {
9
+ name: 'cluster-5',
10
+ platform_kubernetes_attributes: {
11
+ api_url: 'https://35.111.51.20',
12
+ token: '12345',
13
+ ca_cert: "-----BEGIN .....-----END CERTIFICATE-----"
14
+ }
15
+ }
16
+
17
+ client.groups.clusters.add(310, params)
18
+ DOC
19
+
20
+ result '=> #<GroupCluster id: 2, name: cluster-5>'
21
+ end
22
+
23
+ doc 'Add' do
24
+ markdown <<~DOC
25
+ | Attribute | Type | Required | Description |
26
+ | --------- | ---- | -------- | ----------- |
27
+ | name | string | yes | The name of the cluster |
28
+ | domain | string | no | The base domain of the cluster |
29
+ | management_project_id | integer | no | The ID of the management project for the cluster |
30
+ | enabled | boolean | no | Determines if cluster is active or not, defaults to true |
31
+ | managed | boolean | no | Determines if GitLab will manage namespaces and service accounts for this cluster, defaults to true |
32
+ | platform_kubernetes_attributes[api_url] | string | yes | The URL to access the Kubernetes API |
33
+ | platform_kubernetes_attributes[token] | string | yes | The token to authenticate against Kubernetes |
34
+ | platform_kubernetes_attributes[ca_cert] | string | no | TLS certificate. Required if API is using a self-signed TLS certificate. |
35
+ | platform_kubernetes_attributes[authorization_type] | string | no | The cluster authorization type: rbac, abac or unknown_authorization. Defaults to rbac. |
36
+ | environment_scope | string | no | The associated environment to the cluster. Defaults to * **(PREMIUM)** |
37
+ DOC
38
+ end
39
+
40
+ def add(group_id, query)
41
+ group_id = format_id(group_id)
42
+
43
+ client.request(:post, "groups/#{group_id}/clusters/user", GroupCluster, query)
44
+ end
45
+ end
46
+ end
@@ -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