labclient 0.1.0 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/lib/labclient.rb +65 -42
  3. data/lib/labclient/branches/branch.rb +25 -0
  4. data/lib/labclient/branches/create.rb +33 -0
  5. data/lib/labclient/client.rb +45 -5
  6. data/lib/labclient/common.rb +5 -0
  7. data/lib/labclient/docs.rb +5 -1
  8. data/lib/labclient/epics/epic.rb +13 -0
  9. data/lib/labclient/error.rb +1 -0
  10. data/lib/labclient/files/create.rb +14 -8
  11. data/lib/labclient/generator/generator.rb +70 -0
  12. data/lib/labclient/generator/names.rb +68 -0
  13. data/lib/labclient/generator/template_helper.rb +82 -0
  14. data/lib/labclient/generator/templates/environments.rb +98 -0
  15. data/lib/labclient/generator/templates/pages.rb +67 -0
  16. data/lib/labclient/generator/templates/pipeline_trigger.rb +82 -0
  17. data/lib/labclient/generator/wizard.rb +142 -0
  18. data/lib/labclient/groups/group.rb +17 -0
  19. data/lib/labclient/groups/stub.rb +8 -0
  20. data/lib/labclient/http.rb +8 -3
  21. data/lib/labclient/issues/agent_detail.rb +1 -1
  22. data/lib/labclient/issues/closed_by.rb +1 -1
  23. data/lib/labclient/issues/create.rb +17 -5
  24. data/lib/labclient/issues/delete.rb +1 -1
  25. data/lib/labclient/issues/issue.rb +21 -1
  26. data/lib/labclient/issues/move.rb +1 -1
  27. data/lib/labclient/issues/participants.rb +1 -1
  28. data/lib/labclient/issues/related_merge_requests.rb +1 -1
  29. data/lib/labclient/issues/show.rb +1 -1
  30. data/lib/labclient/issues/subscribe.rb +1 -1
  31. data/lib/labclient/issues/time_stats.rb +5 -5
  32. data/lib/labclient/issues/todo.rb +1 -1
  33. data/lib/labclient/issues/unsubscribe.rb +1 -1
  34. data/lib/labclient/issues/update.rb +1 -1
  35. data/lib/labclient/klass.rb +35 -3
  36. data/lib/labclient/lab_struct.rb +17 -0
  37. data/lib/labclient/license/list.rb +2 -2
  38. data/lib/labclient/members/member.rb +1 -0
  39. data/lib/labclient/merge_requests/accept.rb +16 -7
  40. data/lib/labclient/merge_requests/cancel_auto_merge.rb +1 -1
  41. data/lib/labclient/merge_requests/changes.rb +1 -1
  42. data/lib/labclient/merge_requests/closes_issues.rb +1 -1
  43. data/lib/labclient/merge_requests/commits.rb +1 -1
  44. data/lib/labclient/merge_requests/create.rb +12 -0
  45. data/lib/labclient/merge_requests/delete.rb +1 -1
  46. data/lib/labclient/merge_requests/diff_versions.rb +1 -1
  47. data/lib/labclient/merge_requests/merge_request.rb +49 -4
  48. data/lib/labclient/merge_requests/participants.rb +1 -1
  49. data/lib/labclient/merge_requests/pipelines.rb +2 -2
  50. data/lib/labclient/merge_requests/rebase.rb +1 -1
  51. data/lib/labclient/merge_requests/show.rb +1 -1
  52. data/lib/labclient/merge_requests/subscribe.rb +1 -1
  53. data/lib/labclient/merge_requests/time_stats.rb +5 -5
  54. data/lib/labclient/merge_requests/todo.rb +1 -1
  55. data/lib/labclient/merge_requests/unsubscribe.rb +1 -1
  56. data/lib/labclient/merge_requests/update.rb +1 -1
  57. data/lib/labclient/notes/epics/create.rb +12 -4
  58. data/lib/labclient/notes/epics/delete.rb +3 -3
  59. data/lib/labclient/notes/epics/list.rb +21 -4
  60. data/lib/labclient/notes/epics/show.rb +4 -4
  61. data/lib/labclient/notes/epics/update.rb +4 -4
  62. data/lib/labclient/notes/issues/create.rb +11 -1
  63. data/lib/labclient/notes/issues/list.rb +18 -3
  64. data/lib/labclient/notes/issues/show.rb +1 -1
  65. data/lib/labclient/notes/merge_requests/create.rb +8 -0
  66. data/lib/labclient/notes/merge_requests/list.rb +20 -2
  67. data/lib/labclient/notes/snippets/create.rb +1 -1
  68. data/lib/labclient/notes/snippets/list.rb +20 -3
  69. data/lib/labclient/notes/snippets/show.rb +1 -1
  70. data/lib/labclient/notifications/update.rb +1 -1
  71. data/lib/labclient/overview.rb +117 -16
  72. data/lib/labclient/paginated_response.rb +6 -1
  73. data/lib/labclient/pipelines/pipeline.rb +41 -0
  74. data/lib/labclient/projects/access_requests/access_request.rb +0 -1
  75. data/lib/labclient/projects/badges/project_badge.rb +0 -1
  76. data/lib/labclient/projects/clusters/project_cluster.rb +0 -1
  77. data/lib/labclient/projects/create.rb +13 -0
  78. data/lib/labclient/projects/deployments/project_deployment.rb +1 -3
  79. data/lib/labclient/projects/environments/project_environment.rb +0 -1
  80. data/lib/labclient/projects/forks/existing.rb +0 -2
  81. data/lib/labclient/projects/forks/fork.rb +1 -1
  82. data/lib/labclient/projects/forks/list.rb +0 -1
  83. data/lib/labclient/projects/forks/remove.rb +0 -1
  84. data/lib/labclient/projects/hooks/project_hook.rb +0 -1
  85. data/lib/labclient/projects/labels/project_label.rb +0 -1
  86. data/lib/labclient/projects/methods.rb +76 -2
  87. data/lib/labclient/projects/mirrors/project_mirror.rb +0 -1
  88. data/lib/labclient/projects/reference.rb +17 -0
  89. data/lib/labclient/projects/release_links/project_release_link.rb +0 -1
  90. data/lib/labclient/projects/releases/project_release.rb +0 -1
  91. data/lib/labclient/projects/services/project_service.rb +0 -1
  92. data/lib/labclient/projects/snippets/project_snippet.rb +12 -0
  93. data/lib/labclient/projects/stars/star.rb +0 -2
  94. data/lib/labclient/projects/stars/starred_projects.rb +0 -2
  95. data/lib/labclient/projects/stars/starrers.rb +1 -1
  96. data/lib/labclient/projects/triggers/project_trigger.rb +0 -1
  97. data/lib/labclient/projects/variables/project_variable.rb +0 -1
  98. data/lib/labclient/protected_branches/protect.rb +6 -5
  99. data/lib/labclient/protected_environments/list.rb +29 -0
  100. data/lib/labclient/protected_environments/protect.rb +53 -0
  101. data/lib/labclient/protected_environments/protected_environment.rb +22 -0
  102. data/lib/labclient/protected_environments/show.rb +24 -0
  103. data/lib/labclient/protected_environments/unprotect.rb +31 -0
  104. data/lib/labclient/snippets/snippet.rb +2 -2
  105. data/lib/labclient/users/membership.rb +62 -0
  106. data/lib/labclient/users/memberships.rb +8 -3
  107. data/lib/labclient/users/user.rb +13 -1
  108. data/lib/labclient/version.rb +1 -1
  109. metadata +38 -9
  110. data/lib/labclient/open_struct.rb +0 -14
@@ -86,7 +86,7 @@ module LabClient
86
86
  end
87
87
 
88
88
  def link_regex
89
- /<([^>]+)>; rel=\"([^\"]+)\"/
89
+ /<([^>]+)>; rel="([^"]+)"/
90
90
  end
91
91
 
92
92
  def next_page
@@ -111,5 +111,10 @@ module LabClient
111
111
  process_entry(entry, @response)
112
112
  end
113
113
  end
114
+
115
+ # Forward response success
116
+ def success?
117
+ @response.success?
118
+ end
114
119
  end
115
120
  end
@@ -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,7 +24,6 @@ module LabClient
24
24
  date_time_attrs %i[created_at]
25
25
 
26
26
  help do
27
- @group_name = 'Projects'
28
27
  subtitle 'ProjectAccessRequest'
29
28
  option 'user', 'Show user for access request'
30
29
  option 'approve', 'Accept access request [Access Level]'
@@ -36,7 +36,6 @@ module LabClient
36
36
  date_time_attrs %i[created_at]
37
37
 
38
38
  help do
39
- @group_name = 'Projects'
40
39
  subtitle 'ProjectBadge'
41
40
  option 'project', 'Show Project'
42
41
  option 'update', 'Update this badge [Hash]'
@@ -28,7 +28,6 @@ module LabClient
28
28
  user_attrs %i[uster]
29
29
 
30
30
  help do
31
- @group_name = 'Projects'
32
31
  subtitle 'ProjectCluster'
33
32
  option 'project', 'Show Project'
34
33
  option 'update', 'Update this Cluster [Hash]'
@@ -32,6 +32,16 @@ module LabClient
32
32
  example 'client.projects.create(name: "Verbal", description: "hes gone", visibility: :private)'
33
33
  end
34
34
 
35
+ doc 'Create' do
36
+ desc 'Via Group'
37
+ example <<~DOC
38
+ group = client.groups.show(51)
39
+ group.project_create(name: "Hobby", description: "We do have time for your darned hobbies!")
40
+ DOC
41
+
42
+ example 'client.projects.create(name: "Verbal", description: "hes gone", visibility: :private)'
43
+ end
44
+
35
45
  doc 'Create' do
36
46
  title 'For User'
37
47
  desc 'Creates a new project owned by the specified user [user id, params]'
@@ -42,7 +52,10 @@ module LabClient
42
52
  client.request(:post, "projects/user/#{user_id}", Project, query)
43
53
  end
44
54
 
55
+ # TODO: Test Project/Group Creation
56
+ # TODO: Create helper for group
45
57
  def create(query = {})
58
+ format_query_id(:namespace_id, query)
46
59
  client.request(:post, 'projects', Project, query)
47
60
  end
48
61
  end
@@ -28,11 +28,9 @@ module LabClient
28
28
  user_attrs %i[user]
29
29
 
30
30
  help do
31
- @group_name = 'Projects'
32
- subtitle 'ProjectDeployment'
31
+ subtitle 'Project Deployment'
33
32
  option 'project', 'Show Project'
34
33
  option 'update', 'Update this deployment [Hash]'
35
- option 'delete', 'Delete this deployment'
36
34
  option 'stop', 'Stop this deployment'
37
35
  end
38
36
  end
@@ -33,7 +33,6 @@ module LabClient
33
33
  date_time_attrs %i[created_at]
34
34
 
35
35
  help do
36
- @group_name = 'Projects'
37
36
  subtitle 'ProjectEnvironment'
38
37
  option 'project', 'Show Project'
39
38
  option 'update', 'Update this environment [Hash]'
@@ -2,8 +2,6 @@
2
2
  module LabClient
3
3
  # Specifics
4
4
  class Projects < Common
5
- @group_name = 'Forks'
6
-
7
5
  doc 'Associate' do
8
6
  desc 'Create a forked from/to relation between existing projects [Target ID, Source ID]'
9
7
  example 'client.projects.fork_existing(309, 10)'
@@ -2,7 +2,7 @@
2
2
  module LabClient
3
3
  # Specifics
4
4
  class Projects < Common
5
- @group_name = 'Forks'
5
+ @group_name = 'Project Forks'
6
6
 
7
7
  doc 'Create' do
8
8
  desc 'Forks a project into the user namespace of the authenticated user or the one provided.'
@@ -2,7 +2,6 @@
2
2
  module LabClient
3
3
  # Specifics
4
4
  class Projects < Common
5
- @group_name = 'Forks'
6
5
  doc 'List' do
7
6
  desc 'List the projects accessible to the calling user that have an established, forked relationship with the specified project'
8
7
  example 'client.projects.forks(299)'
@@ -2,7 +2,6 @@
2
2
  module LabClient
3
3
  # Specifics
4
4
  class Projects < Common
5
- @group_name = 'Forks'
6
5
  doc 'Remove' do
7
6
  desc 'Delete an existing forked from relationship [Project ID]'
8
7
  example 'client.projects.fork_remove(309)'
@@ -22,7 +22,6 @@ module LabClient
22
22
  date_time_attrs %i[created_at]
23
23
 
24
24
  help do
25
- @group_name = 'Projects'
26
25
  subtitle 'ProjectHook'
27
26
  option 'project', 'Show Project'
28
27
  option 'update', 'Update this hook [Hash]'
@@ -43,7 +43,6 @@ module LabClient
43
43
  end
44
44
 
45
45
  help do
46
- @group_name = 'Projects'
47
46
  subtitle 'ProjectLabel'
48
47
  option 'project', 'Show Project'
49
48
  option 'update', 'Update this label [Hash]'
@@ -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
@@ -75,10 +75,15 @@ module LabClient
75
75
  update_self(client.projects.fork_existing(id, target_id))
76
76
  end
77
77
 
78
+ # Issues
78
79
  def issues(query = {})
79
80
  client.issues.project_issues(id, query)
80
81
  end
81
82
 
83
+ def issue_create(query)
84
+ client.issues.create(id, query)
85
+ end
86
+
82
87
  # Hooks
83
88
  def hooks
84
89
  client.projects.hooks.list(id)
@@ -341,6 +346,10 @@ module LabClient
341
346
  client.branches.show(id, branch_id)
342
347
  end
343
348
 
349
+ def branch_create(query)
350
+ client.branches.create(id, query)
351
+ end
352
+
344
353
  def branch_delete(branch_id)
345
354
  client.branches.delete(id, branch_id)
346
355
  end
@@ -483,6 +492,23 @@ module LabClient
483
492
  client.projects.environments.stop(id, environment_id)
484
493
  end
485
494
 
495
+ # Protected Environments
496
+ def protected_environments
497
+ client.protected_environments.list(id)
498
+ end
499
+
500
+ def protected_environment(environment_id)
501
+ client.protected_environments.show(id, environment_id)
502
+ end
503
+
504
+ def protect_environment(query)
505
+ client.protected_environments.protect(id, query)
506
+ end
507
+
508
+ def unprotect_environment(environment_id)
509
+ client.protected_environments.unprotect(id, environment_id)
510
+ end
511
+
486
512
  # Project Triggers
487
513
  def triggers
488
514
  client.projects.triggers.list(id)
@@ -615,6 +641,10 @@ module LabClient
615
641
  client.merge_requests.list_project(id, query)
616
642
  end
617
643
 
644
+ def merge_request_create(query)
645
+ client.merge_requests.create(id, query)
646
+ end
647
+
618
648
  # Access Requests
619
649
  def request_access
620
650
  client.projects.access_requests.create(id)
@@ -676,6 +706,50 @@ module LabClient
676
706
  def clusters
677
707
  client.projects.clusters.list(id)
678
708
  end
709
+
710
+ # Reload
711
+ def reload
712
+ update_self client.projects.show(id)
713
+ end
714
+
715
+ # Parent Helper
716
+ def parent
717
+ case namespace.kind
718
+ when 'user'
719
+ client.users.show(namespace.id)
720
+ when 'group'
721
+ client.groups.show(namespace.id)
722
+ end
723
+ end
724
+
725
+ # Snippets
726
+ def snippets
727
+ client.projects.snippets.list(id)
728
+ end
729
+
730
+ def snippet_create(query)
731
+ client.projects.snippets.create(id, query)
732
+ end
733
+
734
+ # Wait for Import / Set a Hard Limit
735
+ def wait_for_import(total_time = 300, sleep_time = 15)
736
+ # none
737
+ # scheduled
738
+ # failed
739
+ # started
740
+ # finished
741
+
742
+ Timeout.timeout(total_time) do
743
+ loop do
744
+ reload
745
+ puts "Waiting for Import Status: #{import_status}"
746
+ break if %w[none finished].include? import_status
747
+ raise "Import Failed: #{import_error}" if import_status == 'failed'
748
+
749
+ sleep sleep_time
750
+ end
751
+ end
752
+ end
679
753
  end
680
754
  # rubocop:enable Metrics/ModuleLength
681
755
  end
@@ -21,7 +21,6 @@ module LabClient
21
21
  date_time_attrs %i[last_update_started_at last_successful_update_at]
22
22
 
23
23
  help do
24
- @group_name = 'Projects'
25
24
  subtitle 'ProjectMirror'
26
25
  option 'project', 'Show Project'
27
26
  option 'update', 'Update this Mirror [Hash]'
@@ -8,11 +8,17 @@ module LabClient
8
8
  option 'archive', 'Archive this project'
9
9
  option 'delete', 'Schedule/Delete this project'
10
10
  option 'events', "List this project's events"
11
+ option 'reload', 'Reload this project object (New API Call)'
12
+ option 'wait_for_import', 'Looping, wait for project import [Timeout, Interval]'
13
+
11
14
  option 'fork_existing', 'Create Fork Relationship [Target/Source Project]'
12
15
  option 'fork_remove', 'Remove Fork Relationshgip'
13
16
  option 'fork', 'Fork this project, accepts hash, [namespace, path, name]'
14
17
  option 'forks', 'List forks of this project'
18
+
19
+ # Issues
15
20
  option 'issues', 'List project issues [Hash]'
21
+ option 'issue_create', 'Create a new issue in this project [Hash]'
16
22
 
17
23
  option 'housekeeping', 'Start the Housekeeping'
18
24
  option 'languages', 'Get percentage value of languages used.'
@@ -65,6 +71,12 @@ module LabClient
65
71
  option 'environment_update', 'Update project environment [Environment ID, Hash]'
66
72
  option 'environment_stop', 'Stop project environment [Environment ID]'
67
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
+
68
80
  # Deployments
69
81
  option 'deployments', "List this project's deployments"
70
82
  option 'deployment_create', 'Create project deployment [Hash]'
@@ -198,6 +210,7 @@ module LabClient
198
210
  # Branches
199
211
  option 'branches', 'List repository branches [String]'
200
212
  option 'branch', 'Get a single repository branches [Branch Name]'
213
+ option 'branch_create', 'Create a repository branches [Hash]'
201
214
  option 'branch_delete', 'Delete a single repository branches [Branch Name]'
202
215
  option 'branch_delete_merged', 'Will delete all branches that are merged into the project’s default branch'
203
216
 
@@ -235,6 +248,7 @@ module LabClient
235
248
 
236
249
  # Merge Requests
237
250
  option 'merge_requests', 'List project merge requests, [Hash]'
251
+ option 'merge_request_create', 'Create new merge request [Hash]'
238
252
 
239
253
  # Access Requests
240
254
  option 'access_requests', 'List access requests for project'
@@ -248,6 +262,9 @@ module LabClient
248
262
 
249
263
  # Clusters
250
264
  option 'clusters', 'Returns a list of project clusters.'
265
+
266
+ option 'events', 'List project events [Hash]'
267
+ option 'parent', 'Show (API Call) Project Parent, returns either Group or User'
251
268
  end
252
269
  end
253
270
  # rubocop:enable Metrics/BlockLength, Metrics/ClassLength
@@ -32,7 +32,6 @@ module LabClient
32
32
  date_time_attrs %i[created_at release_linkd_at]
33
33
 
34
34
  help do
35
- @group_name = 'Projects'
36
35
  subtitle 'ProjectRelease'
37
36
  option 'project', 'Show Project'
38
37
  option 'update', 'Update this release link [Hash]'
@@ -46,7 +46,6 @@ module LabClient
46
46
  date_time_attrs %i[created_at released_at]
47
47
 
48
48
  help do
49
- @group_name = 'Projects'
50
49
  subtitle 'ProjectRelease'
51
50
  option 'project', 'Show Project'
52
51
  option 'update', 'Update this release [Hash]'
@@ -27,7 +27,6 @@ module LabClient
27
27
  date_time_attrs %i[created_at updated_at]
28
28
 
29
29
  help do
30
- @group_name = 'Projects'
31
30
  subtitle 'ProjectService'
32
31
  option 'project', 'Show Project'
33
32
  option 'update', 'Update this service [Hash]'
@@ -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
@@ -2,8 +2,6 @@
2
2
  module LabClient
3
3
  # Specifics
4
4
  class Projects < Common
5
- @group_name = 'Stars'
6
-
7
5
  doc 'Star' do
8
6
  desc 'Stars a given project'
9
7
  example 'client.projects.star(10)'