labclient 0.1.4 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '09bb30f5014cb0b4a37d7f4aa421549337b6177bf132580974cf1a35199c6242'
4
- data.tar.gz: cc354dc398276bba64db00bc9adafd23e9c341eba16c4c2dd315788f3ab72fb1
3
+ metadata.gz: 0c77fa948bc39c9ec7d677340949a7bc52ed03999c4cb5286d125154edb06f9b
4
+ data.tar.gz: fa96ed5df9a9ddf7eea56cd7eb7a34832b4a9509d982159fd8069c5ae49de241
5
5
  SHA512:
6
- metadata.gz: f492cb23a182293f165733d7d54830a2a34b9666c487cf63b5bd2dded2dbd58a7713f513eeba0813e382f1efe0d2c50cb8204f485678448b76f109bf289b8887
7
- data.tar.gz: 0d558d85cea6f58bddf600dd36962b9a3fe1bc0c91e9b398ff6d2c35103fd61d88e4b6d47d24aa06bff15a5c2c195561847f495400ddef1eabaf78cfd7c65498
6
+ metadata.gz: 2148330fb1c533956e2f51085729c7c8e96b8fc27e21b43bbbac2b492906047bc52d964b203fe42ac86fc2f041310ab6c6b4e7f90ae5935efcedaf11674a4363
7
+ data.tar.gz: 004cbd92b60fd45996a4ecd9ae38039b3bae703a22f4d804e34390a56662a0f0859992295a83bf0d53f7e4e6191e2c9f416fcc4b7618e54e1b944c73aa4478fc
@@ -1,6 +1,5 @@
1
1
  # Public Gems
2
2
  require 'oj'
3
- require 'pry'
4
3
  require 'typhoeus'
5
4
  require 'active_support/all'
6
5
  require 'amazing_print'
@@ -360,6 +359,15 @@ require 'labclient/groups/badges/update'
360
359
  require 'labclient/groups/badges/delete'
361
360
  require 'labclient/groups/badges/group_badge'
362
361
 
362
+ # Group Clusters
363
+ require 'labclient/groups/clusters/client'
364
+ require 'labclient/groups/clusters/list'
365
+ require 'labclient/groups/clusters/show'
366
+ require 'labclient/groups/clusters/add'
367
+ require 'labclient/groups/clusters/update'
368
+ require 'labclient/groups/clusters/delete'
369
+ require 'labclient/groups/clusters/group_cluster'
370
+
363
371
  require 'labclient/groups/group'
364
372
 
365
373
  # Issues
@@ -849,6 +857,12 @@ require 'labclient/resource_labels/merge_requests/client'
849
857
  require 'labclient/resource_labels/merge_requests/list'
850
858
  require 'labclient/resource_labels/merge_requests/show'
851
859
 
860
+ # Feature Flags
861
+ require 'labclient/feature_flags/create'
862
+ require 'labclient/feature_flags/delete'
863
+ require 'labclient/feature_flags/list'
864
+ require 'labclient/feature_flags/feature_flag'
865
+
852
866
  require 'labclient/resource_labels/resource_label'
853
867
 
854
868
  # Generators
@@ -860,7 +874,7 @@ require 'labclient/generator/generator'
860
874
  require 'labclient/generator/wizard'
861
875
 
862
876
  # Dynamically Require Templates (Simplify new template creation)
863
- Dir[File.dirname(__FILE__) + '/labclient/generator/templates/*.rb'].sort.each { |file| require file }
877
+ Dir["#{File.dirname(__FILE__)}/labclient/generator/templates/*.rb"].sort.each { |file| require file }
864
878
 
865
879
  # I am Very Last
866
880
  require 'labclient/client'
@@ -2,46 +2,40 @@
2
2
  module LabClient
3
3
  # Shared Methods
4
4
  module AccessLevel
5
+ HUMAN_ACCESS_LEVELS = {
6
+ 0 => :none,
7
+ 10 => :guest,
8
+ 20 => :reporter,
9
+ 30 => :developer,
10
+ 40 => :maintainer,
11
+ 50 => :owner,
12
+ 60 => :admin
13
+ }.freeze
14
+
15
+ MACHINE_ACCESS_LEVELS = {
16
+ none: 0,
17
+ guest: 10,
18
+ reporter: 20,
19
+ developer: 30,
20
+ maintainer: 40,
21
+ owner: 50,
22
+ admin: 60
23
+ }.freeze
24
+
5
25
  def human_access_level(level = 10)
6
- case level
7
- when 0 then :none
8
- when 10 then :guest
9
- when 20 then :reporter
10
- when 30 then :developer
11
- when 40 then :maintainer
12
- when 50 then :owner
13
- when 60 then :admin
14
- end
26
+ HUMAN_ACCESS_LEVELS[level]
15
27
  end
16
28
 
17
29
  def machine_access_level(level = :developer)
18
- case level
19
- when :none then 0
20
- when :guest then 10
21
- when :reporter then 20
22
- when :developer then 30
23
- when :maintainer then 40
24
- when :owner then 50
25
- when :admin then 60
26
- end
30
+ MACHINE_ACCESS_LEVELS[level]
27
31
  end
28
32
 
29
33
  def machine_protected_access_level(level = :developer)
30
- case level
31
- when :none then 0
32
- when :developer then 30
33
- when :maintainer then 40
34
- when :admin then 60
35
- end
34
+ MACHINE_ACCESS_LEVELS[level]
36
35
  end
37
36
 
38
37
  def human_protected_access_level(level = 10)
39
- case level
40
- when 0 then :none
41
- when 30 then :developer
42
- when 40 then :maintainer
43
- when 60 then :admin
44
- end
38
+ HUMAN_ACCESS_LEVELS[level]
45
39
  end
46
40
  end
47
41
  end
@@ -37,8 +37,8 @@ module LabClient
37
37
  discussions: Discussions,
38
38
  epics: Epics,
39
39
  events: Events,
40
+ feature_flags: FeatureFlags,
40
41
  files: Files,
41
- wizard: Generator::Wizard,
42
42
  groups: Groups,
43
43
  impersonation_tokens: ImpersonationTokens,
44
44
  issues: Issues,
@@ -69,7 +69,8 @@ module LabClient
69
69
  todos: Todos,
70
70
  users: Users,
71
71
  version: Version,
72
- wikis: Wikis
72
+ wikis: Wikis,
73
+ wizard: Generator::Wizard
73
74
  }
74
75
 
75
76
  @subclasses.each do |name, obj|
@@ -82,9 +83,16 @@ module LabClient
82
83
  subclasses.keys.sort
83
84
  end
84
85
 
85
- def help
86
+ def help(help_filter = nil)
86
87
  puts 'Available Methods'
87
- puts " - #{subclasses.keys.sort.join(' ')}\n\n"
88
+
89
+ shown_subclasses = if help_filter
90
+ api_methods.grep(/#{help_filter}/)
91
+ else
92
+ api_methods
93
+ end
94
+
95
+ puts " - #{shown_subclasses.join(' ')}\n\n"
88
96
  puts "See help for each specific sub-category\n"
89
97
  puts "- client.users.help\n"
90
98
  puts "- client.users.api_methods\n"
@@ -109,24 +117,29 @@ module LabClient
109
117
  self.http = HTTP.new(@settings)
110
118
  end
111
119
 
120
+ def base_url
121
+ "#{settings[:url]}/api/v4/"
122
+ end
123
+
112
124
  def prompt_for_url
113
125
  print 'Enter GitLab URL (e.g. https://gitlab.com): '
114
- @settings[:url] = STDIN.gets.chomp
126
+ @settings[:url] = $stdin.gets.chomp
115
127
  raise 'LabClient Error - Missing URL!' if @settings[:url].blank?
116
128
  end
117
129
 
118
130
  def prompt_for_token
119
131
  print 'Enter Personal Access Token: '
120
- @settings[:token] = STDIN.gets.chomp
132
+ @settings[:token] = $stdin.gets.chomp
121
133
  end
122
134
 
123
135
  def unspecified_defaults
124
136
  @settings[:paginate] = true if @settings[:paginate].nil?
125
137
  @settings[:ssl_verify] = true if @settings[:ssl_verify].nil?
138
+ @settings[:quiet] = false if @settings[:quiet].nil?
126
139
  end
127
140
 
128
141
  def home_file
129
- ENV['HOME'] + '/.gitlab-labclient'
142
+ "#{ENV['HOME']}/.gitlab-labclient"
130
143
  end
131
144
 
132
145
  # Easier Profile Name Access
@@ -173,7 +186,7 @@ module LabClient
173
186
 
174
187
  process resp
175
188
  rescue LabClient::Error => e
176
- puts e.message
189
+ puts e.message unless settings[:quiet]
177
190
  resp
178
191
  end
179
192
 
@@ -6,6 +6,10 @@ module LabClient
6
6
  client.commits.list(id, query)
7
7
  end
8
8
 
9
+ def commit(commit_id, query = {})
10
+ client.commits.show(id, commit_id, query)
11
+ end
12
+
9
13
  def commit_create(query = {})
10
14
  client.commits.create(id, query)
11
15
  end
@@ -16,10 +16,19 @@ module LabClient
16
16
  DOC
17
17
  end
18
18
 
19
+ doc 'Show' do
20
+ desc 'Via Project'
21
+ example <<~DOC
22
+ project = client.projects.show(16)
23
+ project.commit("b539e5d3")
24
+ DOC
25
+ end
26
+
19
27
  # Show
20
- def show(project_id, commit_id)
28
+ def show(project_id, commit_id, query = {})
21
29
  project_id = format_id(project_id)
22
- client.request(:get, "projects/#{project_id}/repository/commits/#{commit_id}", Commit)
30
+
31
+ client.request(:get, "projects/#{project_id}/repository/commits/#{commit_id}", Commit, query)
23
32
  end
24
33
  end
25
34
  end
@@ -12,13 +12,15 @@ module LabClient
12
12
  end
13
13
 
14
14
  def api_methods
15
- public_methods(false)
15
+ public_methods(false).sort
16
16
  end
17
17
 
18
- def help
19
- api_methods_help
18
+ def help(help_filter = nil)
19
+ api_methods_help(help_filter)
20
+
21
+ LabClient::Docs.docs[group_name]&.each do |key, group|
22
+ next if help_filter && !key.downcase.include?(help_filter.to_s)
20
23
 
21
- LabClient::Docs.docs[group_name].each do |key, group|
22
24
  puts "\n=====[ #{key} ]====="
23
25
  group.select { |x| x[:example] }.each { |x| puts "#{x[:example]}\n" }
24
26
  end
@@ -26,10 +28,17 @@ module LabClient
26
28
  nil
27
29
  end
28
30
 
29
- def api_methods_help
31
+ def api_methods_help(help_filter = nil)
30
32
  puts group_name
31
33
  puts ' Available Methods'
32
- puts " #{api_methods.sort.join(' ')}\n"
34
+
35
+ shown_subclasses = if help_filter
36
+ api_methods.grep(/#{help_filter}/)
37
+ else
38
+ api_methods
39
+ end
40
+
41
+ puts " #{shown_subclasses.join(' ')}\n"
33
42
  end
34
43
 
35
44
  # Helper to get docs
@@ -26,11 +26,11 @@ module LabClient
26
26
  # ---------------------------------
27
27
 
28
28
  # Klass Helper
29
- def help
29
+ def help(&block)
30
30
  # require 'active_support/inflector'
31
31
  @group_name ||= group_name.pluralize
32
32
  doc 'Reference' do
33
- yield
33
+ block.call
34
34
  end
35
35
  end
36
36
 
@@ -50,10 +50,14 @@ module LabClient
50
50
  end
51
51
 
52
52
  def desc(value)
53
- # @result[:desc] = simple_format value
54
53
  @result[:desc] = value
55
54
  end
56
55
 
56
+ def demo(value)
57
+ @result[:demo_url] = "https://asciinema.org/a/#{value}.js"
58
+ @result[:demo] = "<script id='asciicast-#{value}' src='#{@result[:demo_url]}' data-autoplay='true' data-loop='true' async></script>"
59
+ end
60
+
57
61
  def example(value)
58
62
  @result[:example] = value
59
63
  end
@@ -81,10 +85,10 @@ module LabClient
81
85
  subnav = subgroup.gsub(' ', '_')
82
86
 
83
87
  # Title
84
- subnav += '_' + @result[:title].gsub(' ', '_') if @result.key? :title
88
+ subnav += "_#{@result[:title].gsub(' ', '_')}" if @result.key? :title
85
89
 
86
90
  @result[:nav] = nav
87
- @result[:nav] += '-' + subnav if subnav
91
+ @result[:nav] += "-#{subnav}" if subnav
88
92
  end
89
93
 
90
94
  def doc(subgroup)
@@ -0,0 +1,48 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Specifics
4
+ class FeatureFlags < Common
5
+ doc 'Create' do
6
+ title 'Set or create a feature'
7
+ example 'client.feature_flags.create(:create_eks_clusters, value: true)'
8
+ result <<~DOC
9
+ => #<FeatureFlag name: create_eks_clusters, state: on
10
+ DOC
11
+ end
12
+
13
+ doc 'Attributes' do
14
+ desc 'Register a new Application'
15
+ markdown <<~DOC
16
+ | Attribute | Type | Required | Description |
17
+ | --------- | ---- | -------- | ----------- |
18
+ | name | string | yes | Name of the feature to create or update |
19
+ | value | integer/string | yes | `true` or `false` to enable/disable, or an integer for percentage of time |
20
+ | feature_group | string | no | A Feature group name |
21
+ | user | string | no | A GitLab username |
22
+ | group | string | no | A GitLab group's path, for example gitlab-org |
23
+ | project | string | no | A projects path, for example gitlab-org/gitlab-foss |
24
+
25
+ Note that you can enable or disable a feature for a `feature_group`, a `user`,
26
+ a `group`, and a `project` in a single API call.
27
+ DOC
28
+ end
29
+
30
+ doc 'Create' do
31
+ example <<~DOC
32
+ client.applications.create(
33
+ name: "Grafana",
34
+ redirect_uri: "https://gitlab.com/-/grafana/login/gitlab",
35
+ scopes: "email"
36
+ )
37
+ DOC
38
+ result <<~DOC
39
+ #<Application id: 11, Grafana>
40
+ DOC
41
+ end
42
+
43
+ # Create
44
+ def create(name, query = {})
45
+ client.request(:post, "features/#{name}", FeatureFlag, query)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,23 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Specifics
4
+ class FeatureFlags < Common
5
+ doc 'Delete' do
6
+ title 'Delete a feature'
7
+ example 'client.feature_flags.delete(:name)'
8
+ end
9
+
10
+ doc 'Delete' do
11
+ desc 'Delete via FeatureFlag'
12
+ example <<~DOC
13
+ feature = client.feature_flags.list.first
14
+ feature.delete
15
+ DOC
16
+ end
17
+
18
+ # Delete
19
+ def delete(name)
20
+ client.request(:delete, "features/#{name}")
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,35 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Inspect Helper
4
+ class FeatureFlag < Klass
5
+ include ClassHelpers
6
+ def inspect
7
+ "#<FeatureFlag name: #{name}, state: #{state}>"
8
+ end
9
+
10
+ def delete
11
+ client.feature_flags.delete name
12
+ end
13
+
14
+ def update(query)
15
+ update_self client.feature_flags.create(name, query)
16
+ end
17
+
18
+ def toggle
19
+ if state == 'off'
20
+ update(value: true)
21
+ else
22
+ update(value: false)
23
+ end
24
+ end
25
+
26
+ date_time_attrs %i[created_at]
27
+
28
+ help do
29
+ subtitle 'Feature Flag'
30
+ option 'delete', 'Delete this specific feature flag'
31
+ option 'toggle', 'Disable / Turn on feature'
32
+ option 'update', 'Create flag / Update with values [Hash]'
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,49 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Specifics
4
+ class FeatureFlags < Common
5
+ doc 'List' do
6
+ title 'List all features'
7
+ desc 'Get a list of all persisted features, with its gate values.'
8
+ example 'client.feature_flags.list'
9
+ result <<~DOC
10
+ => [#<Feature name: create_eks_clusters, state: on>]
11
+ DOC
12
+ end
13
+
14
+ doc 'List' do
15
+ title 'View detail of features'
16
+ desc 'Retrieve detailed information of feature flags'
17
+ example 'client.feature_flags.list.each(&:verbose)'
18
+ result <<~DOC
19
+ LabClient::Feature {
20
+ :name => "create_eks_clusters",
21
+ :state => "on",
22
+ :gates => [
23
+ [0] OpenStruct {
24
+ :key => "boolean",
25
+ :value => true
26
+ }
27
+ ]
28
+ }
29
+ => [#<Feature name: create_eks_clusters, state: on>]
30
+ DOC
31
+ end
32
+
33
+ doc 'List' do
34
+ title 'Toggle all features on or off'
35
+ example <<~DOC
36
+ client.feature_flags.list.each(&:toggle)
37
+ DOC
38
+ result <<~DOC
39
+ [#<Feature name: create_eks_clusters, state: off>,
40
+ #<Feature name: merge_train1, state: off>,
41
+ #<Feature name: merge_train2, state: off>]
42
+ DOC
43
+ end
44
+
45
+ def list
46
+ client.request(:get, 'features', FeatureFlag)
47
+ end
48
+ end
49
+ end