labclient 0.1.1 → 0.2.0

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 (66) hide show
  1. checksums.yaml +4 -4
  2. data/lib/labclient.rb +23 -4
  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 +48 -7
  7. data/lib/labclient/docs.rb +9 -5
  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 +81 -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 +9 -1
  19. data/lib/labclient/http.rb +3 -2
  20. data/lib/labclient/issues/create.rb +2 -0
  21. data/lib/labclient/issues/issue.rb +31 -1
  22. data/lib/labclient/issues/update.rb +20 -2
  23. data/lib/labclient/jobs/delete.rb +1 -1
  24. data/lib/labclient/jobs/keep.rb +1 -1
  25. data/lib/labclient/jobs/play.rb +1 -1
  26. data/lib/labclient/jobs/trace.rb +2 -2
  27. data/lib/labclient/klass.rb +34 -4
  28. data/lib/labclient/lab_struct.rb +17 -0
  29. data/lib/labclient/license/list.rb +2 -2
  30. data/lib/labclient/members/member.rb +1 -0
  31. data/lib/labclient/merge_requests/accept.rb +15 -6
  32. data/lib/labclient/merge_requests/create.rb +12 -0
  33. data/lib/labclient/merge_requests/merge_request.rb +49 -4
  34. data/lib/labclient/notes/epics/create.rb +12 -4
  35. data/lib/labclient/notes/epics/delete.rb +3 -3
  36. data/lib/labclient/notes/epics/list.rb +21 -4
  37. data/lib/labclient/notes/epics/show.rb +4 -4
  38. data/lib/labclient/notes/epics/update.rb +4 -4
  39. data/lib/labclient/notes/issues/create.rb +11 -1
  40. data/lib/labclient/notes/issues/list.rb +18 -3
  41. data/lib/labclient/notes/issues/show.rb +1 -1
  42. data/lib/labclient/notes/merge_requests/create.rb +8 -0
  43. data/lib/labclient/notes/merge_requests/list.rb +20 -2
  44. data/lib/labclient/notes/snippets/create.rb +1 -1
  45. data/lib/labclient/notes/snippets/list.rb +20 -3
  46. data/lib/labclient/notes/snippets/show.rb +1 -1
  47. data/lib/labclient/notifications/update.rb +1 -1
  48. data/lib/labclient/overview.rb +110 -11
  49. data/lib/labclient/paginated_response.rb +8 -1
  50. data/lib/labclient/pipelines/pipeline.rb +41 -0
  51. data/lib/labclient/projects/methods.rb +71 -2
  52. data/lib/labclient/projects/reference.rb +14 -0
  53. data/lib/labclient/projects/snippets/project_snippet.rb +12 -0
  54. data/lib/labclient/protected_branches/protect.rb +6 -5
  55. data/lib/labclient/protected_environments/list.rb +29 -0
  56. data/lib/labclient/protected_environments/protect.rb +53 -0
  57. data/lib/labclient/protected_environments/protected_environment.rb +22 -0
  58. data/lib/labclient/protected_environments/show.rb +24 -0
  59. data/lib/labclient/protected_environments/unprotect.rb +31 -0
  60. data/lib/labclient/snippets/snippet.rb +2 -2
  61. data/lib/labclient/users/membership.rb +62 -0
  62. data/lib/labclient/users/memberships.rb +8 -3
  63. data/lib/labclient/users/user.rb +13 -1
  64. data/lib/labclient/version.rb +1 -1
  65. metadata +37 -9
  66. data/lib/labclient/open_struct.rb +0 -14
@@ -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
@@ -32,8 +32,8 @@ module LabClient
32
32
  subtitle 'Snippet'
33
33
  option 'raw', 'Retrieves the raw snippet content.'
34
34
  option 'agent_detail', 'Hash of user agent details.'
35
- option 'delete', 'Delete this deploy key.'
36
- option 'update', 'Update this this deploy key.'
35
+ option 'delete', 'Delete this snippet.'
36
+ option 'update', 'Update this this snippet.'
37
37
  end
38
38
  end
39
39
  end
@@ -0,0 +1,62 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Inspect Helper
4
+ class Membership < Klass
5
+ include ClassHelpers
6
+ include AccessLevel
7
+
8
+ def inspect
9
+ "#<Membership name: #{source_name}, access: #{level}>"
10
+ end
11
+
12
+ def parent
13
+ case source_type
14
+ when 'Project'
15
+ client.projects.show(source_id)
16
+ when 'Namespace'
17
+ client.groups.show(source_id)
18
+ end
19
+ end
20
+
21
+ def level
22
+ human_access_level(access_level)
23
+ end
24
+
25
+ def guest?
26
+ level == :guest
27
+ end
28
+
29
+ def reporter?
30
+ level == :reporter
31
+ end
32
+
33
+ def developer?
34
+ level == :developer
35
+ end
36
+
37
+ def maintainer?
38
+ level == :maintainer
39
+ end
40
+
41
+ def owner?
42
+ level == :owner
43
+ end
44
+
45
+ def greater_than(leveler)
46
+ case leveler
47
+ when Symbol
48
+ access_level > machine_access_level(leveler)
49
+ when Integer
50
+ access_level > leveler
51
+ end
52
+ end
53
+
54
+ help do
55
+ subtitle 'Membership'
56
+ option 'level', 'Humanized symbol of access level. e.g. :developer'
57
+ option 'parent', 'Collect project/namespace for this membership'
58
+ option '<permission>?', 'True/False evaluation each guest?, developer? etc'
59
+ option 'greater_than', 'True/False if user has greater than [Permission Name]'
60
+ end
61
+ end
62
+ end
@@ -7,7 +7,9 @@ module LabClient
7
7
  desc 'Lists all projects and groups a user is a member of. [User ID, Type]'
8
8
 
9
9
  markdown <<~DOC
10
- Filter memberships by type. Can be either Project or Namespace
10
+ | Attribute | Type | Required | Description |
11
+ | --------- | ------ | -------- | -------------------------------------------------------------- |
12
+ | type | string | no | Filter memberships by type. Can be either Project or Namespace |
11
13
  DOC
12
14
 
13
15
  example 'client.users.memberships(1)'
@@ -26,9 +28,12 @@ module LabClient
26
28
  DOC
27
29
  end
28
30
 
29
- def memberships(user_id, type = 'Project')
31
+ def memberships(user_id, type = nil)
30
32
  user_id = format_id(user_id)
31
- client.request(:get, "users/#{user_id}/memberships", nil, { from: type })
33
+
34
+ query = nil
35
+ query = { type: type } if type
36
+ client.request(:get, "users/#{user_id}/memberships", Membership, query)
32
37
  end
33
38
  end
34
39
  end
@@ -101,10 +101,20 @@ module LabClient
101
101
  client.impersonation_tokens.show(id, token_id)
102
102
  end
103
103
 
104
- def memberships(type = 'Project')
104
+ def memberships(type = nil)
105
105
  client.users.memberships(id, type)
106
106
  end
107
107
 
108
+ # Events
109
+ def events(query = {})
110
+ client.events.user(id, query)
111
+ end
112
+
113
+ # Reload Helper
114
+ def reload
115
+ update_self client.users.show(id)
116
+ end
117
+
108
118
  help do
109
119
  # @group_name = 'Users'
110
120
  subtitle 'User'
@@ -128,11 +138,13 @@ module LabClient
128
138
  option 'emails', 'List user emails'
129
139
  option 'email_create', 'Create email for user [Email Address]'
130
140
  option 'email_delete', 'Delete email for user [Email ID]'
141
+ option 'events', 'List user events [Hash]'
131
142
  option 'impersonation_tokens', 'List impersonation tokesn for user [Filter(Optional)]'
132
143
  option 'impersonation_token_create', 'Create impersonation tokesn [Hash]'
133
144
  option 'impersonation_token_revoke', 'Revoke impersonation tokesn [Token ID]'
134
145
  option 'impersonation_token', 'Show impersonation tokesn [Token ID]'
135
146
  option 'memberships', 'Lists all projects and groups a user is a member of [String/Type]'
147
+ option 'reload', 'Reload this object (New API Call)'
136
148
  end
137
149
  end
138
150
  end
@@ -1,3 +1,3 @@
1
1
  module LabClient
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: labclient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Davin Walker
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-04 00:00:00.000000000 Z
11
+ date: 2020-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -25,19 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '6.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: awesome_print
28
+ name: amazing_print
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.8'
33
+ version: '1.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1.8'
40
+ version: '1.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: gitlab_chronic_duration
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '1.16'
111
+ - !ruby/object:Gem::Dependency
112
+ name: faker
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.12'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.12'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: minitest
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -295,6 +309,7 @@ files:
295
309
  - lib/labclient/awards/snippets/list.rb
296
310
  - lib/labclient/awards/snippets/show.rb
297
311
  - lib/labclient/branches/branch.rb
312
+ - lib/labclient/branches/create.rb
298
313
  - lib/labclient/branches/delete.rb
299
314
  - lib/labclient/branches/delete_merged.rb
300
315
  - lib/labclient/branches/list.rb
@@ -387,6 +402,13 @@ files:
387
402
  - lib/labclient/files/delete.rb
388
403
  - lib/labclient/files/show.rb
389
404
  - lib/labclient/files/update.rb
405
+ - lib/labclient/generator/generator.rb
406
+ - lib/labclient/generator/names.rb
407
+ - lib/labclient/generator/template_helper.rb
408
+ - lib/labclient/generator/templates/environments.rb
409
+ - lib/labclient/generator/templates/pages.rb
410
+ - lib/labclient/generator/templates/pipeline_trigger.rb
411
+ - lib/labclient/generator/wizard.rb
390
412
  - lib/labclient/groups/access_requests/access_request.rb
391
413
  - lib/labclient/groups/access_requests/approve.rb
392
414
  - lib/labclient/groups/access_requests/client.rb
@@ -490,6 +512,7 @@ files:
490
512
  - lib/labclient/keys/show.rb
491
513
  - lib/labclient/keys/user.rb
492
514
  - lib/labclient/klass.rb
515
+ - lib/labclient/lab_struct.rb
493
516
  - lib/labclient/license/add.rb
494
517
  - lib/labclient/license/delete.rb
495
518
  - lib/labclient/license/license.rb
@@ -560,7 +583,6 @@ files:
560
583
  - lib/labclient/notes/snippets/update.rb
561
584
  - lib/labclient/notifications/list.rb
562
585
  - lib/labclient/notifications/update.rb
563
- - lib/labclient/open_struct.rb
564
586
  - lib/labclient/overview.rb
565
587
  - lib/labclient/paginated_response.rb
566
588
  - lib/labclient/pipelines/cancel.rb
@@ -744,6 +766,11 @@ files:
744
766
  - lib/labclient/protected_branches/protect.rb
745
767
  - lib/labclient/protected_branches/show.rb
746
768
  - lib/labclient/protected_branches/unprotect.rb
769
+ - lib/labclient/protected_environments/list.rb
770
+ - lib/labclient/protected_environments/protect.rb
771
+ - lib/labclient/protected_environments/protected_environment.rb
772
+ - lib/labclient/protected_environments/show.rb
773
+ - lib/labclient/protected_environments/unprotect.rb
747
774
  - lib/labclient/protected_tags/list.rb
748
775
  - lib/labclient/protected_tags/protect.rb
749
776
  - lib/labclient/protected_tags/show.rb
@@ -838,6 +865,7 @@ files:
838
865
  - lib/labclient/users/keys/list.rb
839
866
  - lib/labclient/users/keys/show.rb
840
867
  - lib/labclient/users/list.rb
868
+ - lib/labclient/users/membership.rb
841
869
  - lib/labclient/users/memberships.rb
842
870
  - lib/labclient/users/search.rb
843
871
  - lib/labclient/users/show.rb
@@ -859,7 +887,7 @@ homepage: https://gitlab.com/labclient/labclient
859
887
  licenses:
860
888
  - MIT
861
889
  metadata: {}
862
- post_install_message:
890
+ post_install_message:
863
891
  rdoc_options: []
864
892
  require_paths:
865
893
  - lib
@@ -875,7 +903,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
875
903
  version: '0'
876
904
  requirements: []
877
905
  rubygems_version: 3.0.3
878
- signing_key:
906
+ signing_key:
879
907
  specification_version: 4
880
908
  summary: Gitlab API Client
881
909
  test_files: []