labclient 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/labclient.rb +23 -4
- data/lib/labclient/access_levels.rb +24 -30
- data/lib/labclient/branches/branch.rb +25 -0
- data/lib/labclient/branches/create.rb +33 -0
- data/lib/labclient/client.rb +48 -7
- data/lib/labclient/docs.rb +9 -5
- data/lib/labclient/epics/epic.rb +13 -0
- data/lib/labclient/error.rb +1 -0
- data/lib/labclient/files/create.rb +14 -8
- data/lib/labclient/generator/generator.rb +70 -0
- data/lib/labclient/generator/names.rb +68 -0
- data/lib/labclient/generator/template_helper.rb +81 -0
- data/lib/labclient/generator/templates/environments.rb +98 -0
- data/lib/labclient/generator/templates/pages.rb +67 -0
- data/lib/labclient/generator/templates/pipeline_trigger.rb +82 -0
- data/lib/labclient/generator/wizard.rb +142 -0
- data/lib/labclient/groups/group.rb +9 -1
- data/lib/labclient/http.rb +3 -2
- data/lib/labclient/issues/create.rb +2 -0
- data/lib/labclient/issues/issue.rb +31 -1
- data/lib/labclient/issues/update.rb +20 -2
- data/lib/labclient/jobs/delete.rb +1 -1
- data/lib/labclient/jobs/keep.rb +1 -1
- data/lib/labclient/jobs/play.rb +1 -1
- data/lib/labclient/jobs/trace.rb +2 -2
- data/lib/labclient/klass.rb +34 -4
- data/lib/labclient/lab_struct.rb +17 -0
- data/lib/labclient/license/list.rb +2 -2
- data/lib/labclient/members/member.rb +1 -0
- data/lib/labclient/merge_requests/accept.rb +15 -6
- data/lib/labclient/merge_requests/create.rb +12 -0
- data/lib/labclient/merge_requests/merge_request.rb +49 -4
- data/lib/labclient/notes/epics/create.rb +12 -4
- data/lib/labclient/notes/epics/delete.rb +3 -3
- data/lib/labclient/notes/epics/list.rb +21 -4
- data/lib/labclient/notes/epics/show.rb +4 -4
- data/lib/labclient/notes/epics/update.rb +4 -4
- data/lib/labclient/notes/issues/create.rb +11 -1
- data/lib/labclient/notes/issues/list.rb +18 -3
- data/lib/labclient/notes/issues/show.rb +1 -1
- data/lib/labclient/notes/merge_requests/create.rb +8 -0
- data/lib/labclient/notes/merge_requests/list.rb +20 -2
- data/lib/labclient/notes/snippets/create.rb +1 -1
- data/lib/labclient/notes/snippets/list.rb +20 -3
- data/lib/labclient/notes/snippets/show.rb +1 -1
- data/lib/labclient/notifications/update.rb +1 -1
- data/lib/labclient/overview.rb +110 -11
- data/lib/labclient/paginated_response.rb +8 -1
- data/lib/labclient/pipelines/pipeline.rb +41 -0
- data/lib/labclient/projects/methods.rb +71 -2
- data/lib/labclient/projects/reference.rb +14 -0
- data/lib/labclient/projects/snippets/project_snippet.rb +12 -0
- data/lib/labclient/protected_branches/protect.rb +6 -5
- data/lib/labclient/protected_environments/list.rb +29 -0
- data/lib/labclient/protected_environments/protect.rb +53 -0
- data/lib/labclient/protected_environments/protected_environment.rb +22 -0
- data/lib/labclient/protected_environments/show.rb +24 -0
- data/lib/labclient/protected_environments/unprotect.rb +31 -0
- data/lib/labclient/snippets/snippet.rb +2 -2
- data/lib/labclient/users/membership.rb +62 -0
- data/lib/labclient/users/memberships.rb +8 -3
- data/lib/labclient/users/user.rb +13 -1
- data/lib/labclient/version.rb +1 -1
- metadata +37 -9
- data/lib/labclient/open_struct.rb +0 -14
@@ -4,7 +4,7 @@ module LabClient
|
|
4
4
|
class SnippetNotes < Common
|
5
5
|
doc 'Snippets' do
|
6
6
|
title 'Create'
|
7
|
-
desc 'Creates a new note for a single
|
7
|
+
desc 'Creates a new note for a single snippet [Project, Snippet ID]'
|
8
8
|
example 'client.notes.snippets.create(16, 2, body: "Hello!")'
|
9
9
|
result <<~DOC
|
10
10
|
=> #<Note id: 44, type: Snippet>
|
@@ -5,18 +5,35 @@ module LabClient
|
|
5
5
|
@group_name = 'Notes'
|
6
6
|
doc 'Snippets' do
|
7
7
|
title 'List'
|
8
|
-
desc 'Gets a list of all notes for a single
|
8
|
+
desc 'Gets a list of all notes for a single snippet. [Project ID, Snippet ID]'
|
9
|
+
markdown <<~DOC
|
10
|
+
| Attribute | Type | Required | Description |
|
11
|
+
| --------- | ------ | -------- | ------------------------------------------------------------------------------------ |
|
12
|
+
| sort | string | no | Return snippet notes sorted in asc or desc order. Default is desc |
|
13
|
+
| order_by | string | no | Return snippet notes ordered by created_at or updated_at fields. Default is created_at |
|
14
|
+
DOC
|
15
|
+
end
|
16
|
+
|
17
|
+
doc 'Snippets' do
|
9
18
|
example 'client.notes.snippets.list(16, 1)'
|
10
19
|
result <<~DOC
|
11
20
|
=> [#<Note id: 21, type: Snippet>, #<Note id: 20, type: Snippet> .. ]
|
12
21
|
DOC
|
13
22
|
end
|
14
23
|
|
15
|
-
|
24
|
+
doc 'Snippets' do
|
25
|
+
desc 'Filter or Sort'
|
26
|
+
example 'client.notes.snippets.list(16, 1, order_by: :created_at, sort: :asc)'
|
27
|
+
result <<~DOC
|
28
|
+
=> [#<Note id: 21, type: Snippet>, #<Note id: 20, type: Snippet> .. ]
|
29
|
+
DOC
|
30
|
+
end
|
31
|
+
|
32
|
+
def list(project_id, snippet_id, query = {})
|
16
33
|
project_id = format_id(project_id)
|
17
34
|
snippet_id = format_id(snippet_id)
|
18
35
|
|
19
|
-
client.request(:get, "projects/#{project_id}/snippets/#{snippet_id}/notes", Note)
|
36
|
+
client.request(:get, "projects/#{project_id}/snippets/#{snippet_id}/notes", Note, query)
|
20
37
|
end
|
21
38
|
end
|
22
39
|
end
|
@@ -4,7 +4,7 @@ module LabClient
|
|
4
4
|
class SnippetNotes < Common
|
5
5
|
doc 'Snippets' do
|
6
6
|
title 'Show'
|
7
|
-
desc 'Returns a single note for a given
|
7
|
+
desc 'Returns a single note for a given snippet. [Project ID, Snippet ID, Note ID]'
|
8
8
|
example 'client.notes.snippets.show(16, 1, 43)'
|
9
9
|
result <<~DOC
|
10
10
|
=> #<Note id: 21, type: Snippet>
|
data/lib/labclient/overview.rb
CHANGED
@@ -7,11 +7,15 @@ module LabClient
|
|
7
7
|
|
8
8
|
doc 'Overview' do
|
9
9
|
title 'About'
|
10
|
-
|
10
|
+
markdown <<~DOC
|
11
11
|
Labclient is another Gitlab API Gem. A focus on ease of use and helpers and snippets.
|
12
12
|
|
13
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.
|
14
|
+
|
15
|
+
Here's a quick whirlwind example of some of the features:
|
14
16
|
DOC
|
17
|
+
|
18
|
+
demo '350689'
|
15
19
|
end
|
16
20
|
|
17
21
|
doc 'Overview' do
|
@@ -44,6 +48,41 @@ module LabClient
|
|
44
48
|
DOC
|
45
49
|
end
|
46
50
|
|
51
|
+
doc 'Authentication' do
|
52
|
+
title 'Named Profiles'
|
53
|
+
markdown 'Within the `~/.gitlab-labclient` you can also specify profile names'
|
54
|
+
example <<~DOC
|
55
|
+
{
|
56
|
+
"prod": {
|
57
|
+
"url": "https://labclient-prod",
|
58
|
+
"token": "super_secure",
|
59
|
+
"paginate": false
|
60
|
+
},
|
61
|
+
"dev": {
|
62
|
+
"url": "https://labclient-dev",
|
63
|
+
"token": "super_secure",
|
64
|
+
"ssl_verify": false,
|
65
|
+
"paginate": true
|
66
|
+
}
|
67
|
+
}
|
68
|
+
DOC
|
69
|
+
end
|
70
|
+
|
71
|
+
doc 'Authentication' do
|
72
|
+
desc 'Manually select a named profile'
|
73
|
+
example <<~DOC
|
74
|
+
client = LabClient::Client.new(profile: 'prod')
|
75
|
+
DOC
|
76
|
+
end
|
77
|
+
|
78
|
+
doc 'Authentication' do
|
79
|
+
desc 'Automatically select via ENV Variables'
|
80
|
+
example <<~DOC
|
81
|
+
ENV['LABCLIENT_PROFILE'] = 'dev'
|
82
|
+
client = LabClient::Client.new
|
83
|
+
DOC
|
84
|
+
end
|
85
|
+
|
47
86
|
doc 'Authentication' do
|
48
87
|
title 'Environment Variables'
|
49
88
|
desc 'If not provided, and credentials file does not exist will attempt to use ENV variables'
|
@@ -143,6 +182,27 @@ module LabClient
|
|
143
182
|
DOC
|
144
183
|
end
|
145
184
|
|
185
|
+
doc 'Response' do
|
186
|
+
title 'Status'
|
187
|
+
desc 'Each object/call will return a "response" object or the instantiated class object. On each of these you can use "success?" to verify the response of a call.'
|
188
|
+
|
189
|
+
result <<~DOC
|
190
|
+
project = client.projects.show 123123
|
191
|
+
# => #<TyphoeusResponse code: 404>
|
192
|
+
project.success?
|
193
|
+
# => false
|
194
|
+
|
195
|
+
user = client.users.show 1
|
196
|
+
=> #<User id: 1, username: root>
|
197
|
+
user.success?
|
198
|
+
=> true
|
199
|
+
DOC
|
200
|
+
|
201
|
+
result <<~DOC
|
202
|
+
curl -k -H "Private-Token: super_secret_token" -H "Accept: application/json" "https://labclient/api/v4/users?"
|
203
|
+
DOC
|
204
|
+
end
|
205
|
+
|
146
206
|
doc 'Other' do
|
147
207
|
title 'Common Helpers'
|
148
208
|
markdown <<~DOC
|
@@ -191,6 +251,20 @@ module LabClient
|
|
191
251
|
DOC
|
192
252
|
end
|
193
253
|
|
254
|
+
doc 'Other' do
|
255
|
+
desc 'Object Help'
|
256
|
+
|
257
|
+
result <<~DOC
|
258
|
+
project = client.projects.show(5)
|
259
|
+
|
260
|
+
# List Possible Methods
|
261
|
+
project.help
|
262
|
+
|
263
|
+
# Array result of methods
|
264
|
+
project.api_methods
|
265
|
+
DOC
|
266
|
+
end
|
267
|
+
|
194
268
|
doc 'Other' do
|
195
269
|
title 'Object IDs'
|
196
270
|
|
@@ -218,17 +292,18 @@ module LabClient
|
|
218
292
|
end
|
219
293
|
|
220
294
|
doc 'Other' do
|
221
|
-
title '
|
222
|
-
desc '
|
223
|
-
|
224
|
-
example 'docker run -it registry.gitlab.com/labclient/labclient'
|
225
|
-
|
226
|
-
result <<~DOC
|
227
|
-
# Run Container
|
228
|
-
docker run -it -e LABCLIENT_URL="https://labclient" -e LABCLIENT_TOKEN="token" registry.gitlab.com/labclient/labclient
|
295
|
+
title 'Quiet'
|
296
|
+
desc 'Error messages by default are printed to STDOUT. This can be supressed via the :quiet setting'
|
229
297
|
|
230
|
-
|
231
|
-
client.
|
298
|
+
example <<~DOC
|
299
|
+
client = LabClient::Client.new(
|
300
|
+
url: 'https://gitlab.labclient',
|
301
|
+
token: 'gitlab api token',
|
302
|
+
quiet: true
|
303
|
+
)
|
304
|
+
|
305
|
+
# Or after the init
|
306
|
+
client.settings[:quiet] = true
|
232
307
|
DOC
|
233
308
|
end
|
234
309
|
|
@@ -256,6 +331,30 @@ module LabClient
|
|
256
331
|
- [API Authentication](https://docs.gitlab.com/ee/api/README.html#authentication)
|
257
332
|
DOC
|
258
333
|
end
|
334
|
+
|
335
|
+
doc 'Docker' do
|
336
|
+
desc 'A docker image is created from master and can be used to execute snippets or load a quick pry session'
|
337
|
+
|
338
|
+
example 'docker run -it registry.gitlab.com/labclient/labclient'
|
339
|
+
|
340
|
+
result <<~DOC
|
341
|
+
# Run Container
|
342
|
+
docker run -it registry.gitlab.com/labclient/labclient
|
343
|
+
# Without settings configured, initial will prompt for credentials
|
344
|
+
|
345
|
+
client.users.list
|
346
|
+
DOC
|
347
|
+
end
|
348
|
+
|
349
|
+
doc 'Docker' do
|
350
|
+
desc 'The docker container configured and execute code snippets'
|
351
|
+
|
352
|
+
example 'docker run -it registry.gitlab.com/labclient/labclient'
|
353
|
+
|
354
|
+
result <<~DOC
|
355
|
+
docker run -it -e LABCLIENT_URL="https://labclient" -e LABCLIENT_TOKEN="secure_token" labclient 'puts client.users.list.count'
|
356
|
+
DOC
|
357
|
+
end
|
259
358
|
end
|
260
359
|
end
|
261
360
|
# rubocop:enable Metrics/ClassLength
|
@@ -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
|
@@ -111,5 +113,10 @@ module LabClient
|
|
111
113
|
process_entry(entry, @response)
|
112
114
|
end
|
113
115
|
end
|
116
|
+
|
117
|
+
# Forward response success
|
118
|
+
def success?
|
119
|
+
@response.success?
|
120
|
+
end
|
114
121
|
end
|
115
122
|
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
|
@@ -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
|
@@ -488,6 +492,23 @@ module LabClient
|
|
488
492
|
client.projects.environments.stop(id, environment_id)
|
489
493
|
end
|
490
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
|
+
|
491
512
|
# Project Triggers
|
492
513
|
def triggers
|
493
514
|
client.projects.triggers.list(id)
|
@@ -620,6 +641,10 @@ module LabClient
|
|
620
641
|
client.merge_requests.list_project(id, query)
|
621
642
|
end
|
622
643
|
|
644
|
+
def merge_request_create(query)
|
645
|
+
client.merge_requests.create(id, query)
|
646
|
+
end
|
647
|
+
|
623
648
|
# Access Requests
|
624
649
|
def request_access
|
625
650
|
client.projects.access_requests.create(id)
|
@@ -681,6 +706,50 @@ module LabClient
|
|
681
706
|
def clusters
|
682
707
|
client.projects.clusters.list(id)
|
683
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
|
684
753
|
end
|
685
754
|
# rubocop:enable Metrics/ModuleLength
|
686
755
|
end
|
@@ -8,6 +8,9 @@ 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]'
|
@@ -68,6 +71,12 @@ module LabClient
|
|
68
71
|
option 'environment_update', 'Update project environment [Environment ID, Hash]'
|
69
72
|
option 'environment_stop', 'Stop project environment [Environment ID]'
|
70
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
|
+
|
71
80
|
# Deployments
|
72
81
|
option 'deployments', "List this project's deployments"
|
73
82
|
option 'deployment_create', 'Create project deployment [Hash]'
|
@@ -201,6 +210,7 @@ module LabClient
|
|
201
210
|
# Branches
|
202
211
|
option 'branches', 'List repository branches [String]'
|
203
212
|
option 'branch', 'Get a single repository branches [Branch Name]'
|
213
|
+
option 'branch_create', 'Create a repository branches [Hash]'
|
204
214
|
option 'branch_delete', 'Delete a single repository branches [Branch Name]'
|
205
215
|
option 'branch_delete_merged', 'Will delete all branches that are merged into the project’s default branch'
|
206
216
|
|
@@ -238,6 +248,7 @@ module LabClient
|
|
238
248
|
|
239
249
|
# Merge Requests
|
240
250
|
option 'merge_requests', 'List project merge requests, [Hash]'
|
251
|
+
option 'merge_request_create', 'Create new merge request [Hash]'
|
241
252
|
|
242
253
|
# Access Requests
|
243
254
|
option 'access_requests', 'List access requests for project'
|
@@ -251,6 +262,9 @@ module LabClient
|
|
251
262
|
|
252
263
|
# Clusters
|
253
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'
|
254
268
|
end
|
255
269
|
end
|
256
270
|
# rubocop:enable Metrics/BlockLength, Metrics/ClassLength
|