labclient 0.1.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/lib/labclient.rb +16 -6
  3. data/lib/labclient/access_levels.rb +24 -30
  4. data/lib/labclient/branches/branch.rb +25 -0
  5. data/lib/labclient/branches/create.rb +33 -0
  6. data/lib/labclient/client.rb +47 -7
  7. data/lib/labclient/commits/project_helpers.rb +4 -0
  8. data/lib/labclient/commits/show.rb +11 -2
  9. data/lib/labclient/docs.rb +9 -5
  10. data/lib/labclient/epics/epic.rb +13 -0
  11. data/lib/labclient/error.rb +1 -0
  12. data/lib/labclient/files/create.rb +14 -8
  13. data/lib/labclient/files/update.rb +1 -1
  14. data/lib/labclient/generator/generator.rb +9 -21
  15. data/lib/labclient/generator/names.rb +17 -3
  16. data/lib/labclient/generator/template_helper.rb +81 -0
  17. data/lib/labclient/generator/templates/environments.rb +98 -0
  18. data/lib/labclient/generator/templates/pages.rb +24 -30
  19. data/lib/labclient/generator/templates/pipeline_trigger.rb +82 -0
  20. data/lib/labclient/generator/wizard.rb +29 -9
  21. data/lib/labclient/groups/group.rb +1 -1
  22. data/lib/labclient/http.rb +3 -2
  23. data/lib/labclient/issues/issue.rb +23 -1
  24. data/lib/labclient/issues/update.rb +20 -2
  25. data/lib/labclient/jobs/delete.rb +1 -1
  26. data/lib/labclient/jobs/keep.rb +1 -1
  27. data/lib/labclient/jobs/play.rb +1 -1
  28. data/lib/labclient/jobs/trace.rb +2 -2
  29. data/lib/labclient/klass.rb +6 -3
  30. data/lib/labclient/lab_struct.rb +21 -0
  31. data/lib/labclient/license/list.rb +2 -2
  32. data/lib/labclient/members/member.rb +1 -0
  33. data/lib/labclient/merge_requests/accept.rb +15 -6
  34. data/lib/labclient/merge_requests/create.rb +12 -0
  35. data/lib/labclient/merge_requests/merge_request.rb +49 -4
  36. data/lib/labclient/notes/epics/create.rb +12 -4
  37. data/lib/labclient/notes/epics/delete.rb +3 -3
  38. data/lib/labclient/notes/epics/list.rb +21 -4
  39. data/lib/labclient/notes/epics/show.rb +4 -4
  40. data/lib/labclient/notes/epics/update.rb +4 -4
  41. data/lib/labclient/notes/issues/create.rb +11 -1
  42. data/lib/labclient/notes/issues/list.rb +18 -3
  43. data/lib/labclient/notes/issues/show.rb +1 -1
  44. data/lib/labclient/notes/merge_requests/create.rb +8 -0
  45. data/lib/labclient/notes/merge_requests/list.rb +20 -2
  46. data/lib/labclient/notes/snippets/create.rb +1 -1
  47. data/lib/labclient/notes/snippets/list.rb +20 -3
  48. data/lib/labclient/notes/snippets/show.rb +1 -1
  49. data/lib/labclient/notifications/update.rb +1 -1
  50. data/lib/labclient/overview.rb +79 -11
  51. data/lib/labclient/paginated_response.rb +3 -1
  52. data/lib/labclient/pipelines/pipeline.rb +41 -0
  53. data/lib/labclient/projects/environments/project_environment.rb +10 -0
  54. data/lib/labclient/projects/methods.rb +49 -2
  55. data/lib/labclient/projects/reference.rb +12 -0
  56. data/lib/labclient/projects/snippets/project_snippet.rb +12 -0
  57. data/lib/labclient/protected_branches/protect.rb +6 -5
  58. data/lib/labclient/protected_environments/list.rb +29 -0
  59. data/lib/labclient/protected_environments/protect.rb +53 -0
  60. data/lib/labclient/protected_environments/protected_environment.rb +22 -0
  61. data/lib/labclient/protected_environments/show.rb +24 -0
  62. data/lib/labclient/protected_environments/unprotect.rb +31 -0
  63. data/lib/labclient/snippets/snippet.rb +2 -2
  64. data/lib/labclient/users/membership.rb +62 -0
  65. data/lib/labclient/users/memberships.rb +8 -3
  66. data/lib/labclient/users/user.rb +7 -1
  67. data/lib/labclient/version.rb +1 -1
  68. metadata +16 -7
  69. data/lib/labclient/generator/templates/template.rb +0 -23
  70. data/lib/labclient/open_struct.rb +0 -14
@@ -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
@@ -86,7 +88,7 @@ module LabClient
86
88
  end
87
89
 
88
90
  def link_regex
89
- /<([^>]+)>; rel=\"([^\"]+)\"/
91
+ /<([^>]+)>; rel="([^"]+)"/
90
92
  end
91
93
 
92
94
  def next_page
@@ -33,6 +33,45 @@ module LabClient
33
33
  client.jobs.pipeline(project_id, id, scope)
34
34
  end
35
35
 
36
+ def reload
37
+ project_id = collect_project_id
38
+ update_self client.pipelines.show(project_id, id)
39
+ end
40
+
41
+ # The status of pipelines, one of: running, pending, success, failed, canceled, skipped, created, manual
42
+
43
+ # Wait for Import / Set a Hard Limit
44
+ def wait_for_status(total_time = 300, sleep_time = 15)
45
+ # running
46
+ # pending
47
+ # success
48
+ # failed
49
+ # canceled
50
+ # skipped
51
+ # manual
52
+ # created
53
+
54
+ # Wait
55
+ # [running created pending]
56
+
57
+ # Success
58
+ # [skipped manual canceled success]
59
+
60
+ # Fail
61
+ # [failed]
62
+
63
+ Timeout.timeout(total_time) do
64
+ loop do
65
+ reload
66
+ puts "Waiting for Pipeline: #{status}"
67
+ break if %w[skipped manual canceled success].include? status
68
+ raise 'Pipeline failed' if status == 'failed'
69
+
70
+ sleep sleep_time
71
+ end
72
+ end
73
+ end
74
+
36
75
  # DateTime Fields
37
76
  date_time_attrs %i[created_at updated_at finished_at started_at]
38
77
  user_attrs %i[user]
@@ -43,6 +82,8 @@ module LabClient
43
82
  option 'retry', 'Retry jobs in this pipeline'
44
83
  option 'cancel', 'Cancel jobs in this pipeline'
45
84
  option 'delete', 'Delete this pipeline'
85
+ option 'reload', 'Reload this pipeline object (New API Call)'
86
+ option 'wait_for_status', 'Looping, wait for merge request status [Timeout, Interval]'
46
87
  end
47
88
  end
48
89
  end
@@ -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'
@@ -7,8 +7,8 @@ module LabClient
7
7
  client.projects.users(id)
8
8
  end
9
9
 
10
- def events
11
- client.events.project(id)
10
+ def events(query = {})
11
+ client.events.project(id, query)
12
12
  end
13
13
 
14
14
  def delete
@@ -346,6 +346,10 @@ module LabClient
346
346
  client.branches.show(id, branch_id)
347
347
  end
348
348
 
349
+ def branch_create(query)
350
+ client.branches.create(id, query)
351
+ end
352
+
349
353
  def branch_delete(branch_id)
350
354
  client.branches.delete(id, branch_id)
351
355
  end
@@ -472,6 +476,8 @@ module LabClient
472
476
  client.projects.environments.show(id, environment_id)
473
477
  end
474
478
 
479
+ alias environment environment_show
480
+
475
481
  def environment_create(query)
476
482
  client.projects.environments.create(id, query)
477
483
  end
@@ -488,6 +494,23 @@ module LabClient
488
494
  client.projects.environments.stop(id, environment_id)
489
495
  end
490
496
 
497
+ # Protected Environments
498
+ def protected_environments
499
+ client.protected_environments.list(id)
500
+ end
501
+
502
+ def protected_environment(environment_id)
503
+ client.protected_environments.show(id, environment_id)
504
+ end
505
+
506
+ def protect_environment(query)
507
+ client.protected_environments.protect(id, query)
508
+ end
509
+
510
+ def unprotect_environment(environment_id)
511
+ client.protected_environments.unprotect(id, environment_id)
512
+ end
513
+
491
514
  # Project Triggers
492
515
  def triggers
493
516
  client.projects.triggers.list(id)
@@ -620,6 +643,10 @@ module LabClient
620
643
  client.merge_requests.list_project(id, query)
621
644
  end
622
645
 
646
+ def merge_request_create(query)
647
+ client.merge_requests.create(id, query)
648
+ end
649
+
623
650
  # Access Requests
624
651
  def request_access
625
652
  client.projects.access_requests.create(id)
@@ -687,6 +714,25 @@ module LabClient
687
714
  update_self client.projects.show(id)
688
715
  end
689
716
 
717
+ # Parent Helper
718
+ def parent
719
+ case namespace.kind
720
+ when 'user'
721
+ client.users.show(namespace.id)
722
+ when 'group'
723
+ client.groups.show(namespace.id)
724
+ end
725
+ end
726
+
727
+ # Snippets
728
+ def snippets
729
+ client.projects.snippets.list(id)
730
+ end
731
+
732
+ def snippet_create(query)
733
+ client.projects.snippets.create(id, query)
734
+ end
735
+
690
736
  # Wait for Import / Set a Hard Limit
691
737
  def wait_for_import(total_time = 300, sleep_time = 15)
692
738
  # none
@@ -698,6 +744,7 @@ module LabClient
698
744
  Timeout.timeout(total_time) do
699
745
  loop do
700
746
  reload
747
+ puts "Waiting for Import Status: #{import_status}"
701
748
  break if %w[none finished].include? import_status
702
749
  raise "Import Failed: #{import_error}" if import_status == 'failed'
703
750
 
@@ -71,6 +71,12 @@ module LabClient
71
71
  option 'environment_update', 'Update project environment [Environment ID, Hash]'
72
72
  option 'environment_stop', 'Stop project environment [Environment ID]'
73
73
 
74
+ # Protected Environments
75
+ option 'protected_environments', 'List protected environments [String]'
76
+ option 'protected_environment', 'Show single protected environment [String]'
77
+ option 'protect_environment', 'Protect a single environment [Hash]'
78
+ option 'unprotect_environment', 'Unprotect environment [Environment]'
79
+
74
80
  # Deployments
75
81
  option 'deployments', "List this project's deployments"
76
82
  option 'deployment_create', 'Create project deployment [Hash]'
@@ -133,6 +139,7 @@ module LabClient
133
139
 
134
140
  # Commits
135
141
  option 'commits', 'List Commits [Hash]'
142
+ option 'commit', 'Show Commit [String/Commit Sha]'
136
143
  option 'commit_create', 'Create new commit [Hash]'
137
144
  option 'commit_refs', 'Get all references (from branches or tags) a commit is pushed to. [Commit ID, Scope]'
138
145
  option 'commit_cherry_pick', 'Cherry picks a commit to a target branch. [Commit ID, Branch]'
@@ -204,6 +211,7 @@ module LabClient
204
211
  # Branches
205
212
  option 'branches', 'List repository branches [String]'
206
213
  option 'branch', 'Get a single repository branches [Branch Name]'
214
+ option 'branch_create', 'Create a repository branches [Hash]'
207
215
  option 'branch_delete', 'Delete a single repository branches [Branch Name]'
208
216
  option 'branch_delete_merged', 'Will delete all branches that are merged into the project’s default branch'
209
217
 
@@ -241,6 +249,7 @@ module LabClient
241
249
 
242
250
  # Merge Requests
243
251
  option 'merge_requests', 'List project merge requests, [Hash]'
252
+ option 'merge_request_create', 'Create new merge request [Hash]'
244
253
 
245
254
  # Access Requests
246
255
  option 'access_requests', 'List access requests for project'
@@ -254,6 +263,9 @@ module LabClient
254
263
 
255
264
  # Clusters
256
265
  option 'clusters', 'Returns a list of project clusters.'
266
+
267
+ option 'events', 'List project events [Hash]'
268
+ option 'parent', 'Show (API Call) Project Parent, returns either Group or User'
257
269
  end
258
270
  end
259
271
  # rubocop:enable Metrics/BlockLength, Metrics/ClassLength
@@ -35,6 +35,14 @@ module LabClient
35
35
  client.projects.snippets.delete(project_id, id)
36
36
  end
37
37
 
38
+ def notes
39
+ client.notes.snippets.list(project_id, id)
40
+ end
41
+
42
+ def note_create(query)
43
+ client.notes.snippets.create(project_id, id, query)
44
+ end
45
+
38
46
  date_time_attrs %i[updated_at created_at]
39
47
 
40
48
  user_attrs %i[author]
@@ -45,6 +53,10 @@ module LabClient
45
53
  option 'agent_detail', 'Hash of user agent details.'
46
54
  option 'delete', 'Delete this deploy key.'
47
55
  option 'update', 'Update this this deploy key.'
56
+
57
+ # Notes
58
+ option 'notes', 'List notes/comments. [Hash]'
59
+ option 'note_create', 'Creates a new note. [Hash]'
48
60
  end
49
61
  end
50
62
  end
@@ -19,11 +19,12 @@ module LabClient
19
19
  | allowed_to_unprotect | array | no | **(STARTER)** Array of access levels allowed to unprotect, with each described by a hash |
20
20
  | code_owner_approval_required | boolean | no | **(PREMIUM)** Prevent pushes to this branch if it matches an item in the CODEOWNERS file (defaults: false) |
21
21
 
22
- *Valid access levels*
23
- 0 => No access, :none
24
- 30 => Developer access, :developer
25
- 40 => Maintainer access, :maintainer
26
- 60 => Admin access, :admin
22
+ **Valid access levels**
23
+
24
+ - 0, :none => No access
25
+ - 30, :developer => Developer access
26
+ - 40, :maintainer => Maintainer access
27
+ - 60, :admin => Admin access
27
28
 
28
29
  DOC
29
30
  end
@@ -0,0 +1,29 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Specifics
4
+ class ProtectedEnvironments < Common
5
+ doc 'List' do
6
+ desc 'Gets a list of protected environmentes from a project. [Project ID, String]'
7
+ example 'client.protected_environments.list(36)'
8
+ result '[#<ProtectedEnvironment name: prod>]'
9
+
10
+ markdown <<~DOC
11
+ Search: You can use ^term and term$ to find environmentes that begin and end with term respectively.
12
+ DOC
13
+ end
14
+
15
+ doc 'List' do
16
+ desc 'via Project'
17
+ example <<~DOC
18
+ project = client.projects.show(264)
19
+ project.protected_environments
20
+ DOC
21
+ end
22
+
23
+ def list(project_id)
24
+ project_id = format_id(project_id)
25
+
26
+ client.request(:get, "projects/#{project_id}/protected_environments", ProtectedEnvironment)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,53 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Specifics
4
+ class ProtectedEnvironments < Common
5
+ doc 'Protect' do
6
+ desc 'Protects a single environment [Project ID, Hash]'
7
+ example <<~DOC
8
+ client.protected_environments.protect(36,
9
+ name: :prod,
10
+ deploy_access_levels: [
11
+ { access_level: :developer }
12
+ ]
13
+ )
14
+ DOC
15
+ result '#<ProtectedEnvironment name: prod>'
16
+
17
+ markdown <<~DOC
18
+ | Attribute | Type | Required | Description |
19
+ | -------------------- | -------------- | -------- | ---------------------------------------------------------------------------------------------------------------- |
20
+ | name | string | yes | The name of the environment. |
21
+ | deploy_access_levels | array | yes | Array of access levels allowed to deploy, with each described by a hash. |
22
+
23
+ Elements in the deploy_access_levels array should take the form {user_id: integer}, {group_id: integer} or {access_level: integer}. Each user must have access to the project and each group must have this project shared.
24
+
25
+ **Valid access levels**
26
+
27
+ | Access Level | Values |
28
+ | ------------ | --------------- |
29
+ | Developer | 30, :developer |
30
+ | Maintainer | 40, :maintainer |
31
+ | Admin | 60, :admin |
32
+
33
+ DOC
34
+ end
35
+
36
+ doc 'Protect' do
37
+ desc 'via Project'
38
+ example <<~DOC
39
+ project = client.projects.show(264)
40
+ project.protect_environment(name: :other, push_access_level: :admin)
41
+ DOC
42
+ end
43
+
44
+ def protect(project_id, query)
45
+ query[:deploy_access_levels].each do |access_level|
46
+ protected_query_access_level(access_level, :access_level)
47
+ end
48
+
49
+ project_id = format_id(project_id)
50
+ client.request(:post, "projects/#{project_id}/protected_environments", ProtectedEnvironment, query)
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,22 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Inspect Helper
4
+ class ProtectedEnvironment < Klass
5
+ include ClassHelpers
6
+ def inspect
7
+ "#<ProtectedEnvironment name: #{name}>"
8
+ end
9
+
10
+ def unprotect
11
+ project_id = collect_project_id
12
+
13
+ client.protected_environments.unprotect(project_id, name)
14
+ end
15
+
16
+ help do
17
+ subtitle 'ProjectEnvironment'
18
+ option 'project', 'Show Project'
19
+ option 'unprotect', 'Remove protected environment'
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Specifics
4
+ class ProtectedEnvironments < Common
5
+ doc 'Show' do
6
+ desc 'Gets a single protected environment [Project ID, ProtectedEnvironment]'
7
+ example 'client.protected_environments.show(36, :prod)'
8
+ result '#<ProtectedEnvironment name: prod>'
9
+ end
10
+
11
+ doc 'Show' do
12
+ desc 'via Project'
13
+ example <<~DOC
14
+ project = client.projects.show(264)
15
+ project.protected_environment(:master)
16
+ DOC
17
+ end
18
+
19
+ def show(project_id, environment_id)
20
+ project_id = format_id(project_id)
21
+ client.request(:get, "projects/#{project_id}/protected_environments/#{environment_id}", ProtectedEnvironment)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,31 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Specifics
4
+ class ProtectedEnvironments < Common
5
+ doc 'Unprotect' do
6
+ desc 'Unprotects the given protected environment [Project ID, ProtectedEnvironment]'
7
+ example 'client.protected_environments.unprotect(264, :prod)'
8
+ end
9
+
10
+ doc 'Unprotect' do
11
+ desc 'via Project'
12
+ example <<~DOC
13
+ project = client.projects.show(264)
14
+ project.unprotect_environment(:other)
15
+ DOC
16
+ end
17
+
18
+ doc 'Unprotect' do
19
+ desc 'via ProtectedEnvironment'
20
+ example <<~DOC
21
+ protected_env = client.protected_environments.show(36, :prod)
22
+ protected_env.unprotect
23
+ DOC
24
+ end
25
+
26
+ def unprotect(project_id, environment_id)
27
+ project_id = format_id(project_id)
28
+ client.request(:delete, "projects/#{project_id}/protected_environments/#{environment_id}")
29
+ end
30
+ end
31
+ end