labclient 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2d1d2daf2bc113e0a5e74d3b2888dc20278bb18e5aab063a21919f9ab7ef4ca9
4
- data.tar.gz: 40f0b1e58ba394663e4ab90f1ac9fd6e4734e718d6f1aac9f1394bc7c067afd3
3
+ metadata.gz: 105ec572236cc556ebab18031557136d5bb1e78a33d39ad00ba9032e831627b2
4
+ data.tar.gz: 49b836de0a75f9e1ca38cf1620754d824116047c9b944b3c8f81949d07f60162
5
5
  SHA512:
6
- metadata.gz: 9d6e0a96ecd9eba62f3a38c89b621b6379cb1e63bb67a212acc7333dc0dc3ae6d3b58011bdbbb8b2b13c08959d144540e46698112dd1d91a6c613208abe541f3
7
- data.tar.gz: 317e9e1290ccad1878af5f838842ab893879ed2306fcbcf0509ba9fa4372717a94b98ba37f038db86b01945dc7d2a95b18d8f158b1db64fc6884aa310bd14001
6
+ metadata.gz: 1504185ca949dc3dc77eb8266965e2f70d3023a954dcd01eb8194e47086c26a731438310f902f014fd5e63f982ce2a141fda0e37ab55f3a772e46905fb27d46c
7
+ data.tar.gz: 45c22d9129316bd4dd25558c9184d7a1eb79ed2ddd0dab153f60b39fd7838b4e95388465a617002c787b3f32f4dc62eb9924c3624d4f3ac5e6aab63770012946
@@ -101,6 +101,10 @@ module LabClient
101
101
  resp.headers['retry-after']&.to_i
102
102
  end
103
103
 
104
+ def retry_debug_headers
105
+ resp.headers.select { |k, _v| k.include? 'ratelimit' }
106
+ end
107
+
104
108
  # Handle Retry Logic
105
109
  # 1. If response merits a retry
106
110
  # 2. Retry is enabled
@@ -37,7 +37,6 @@ module LabClient
37
37
  debug_handler if debug?
38
38
 
39
39
  post_request_handlers
40
-
41
40
  process resp
42
41
  rescue LabClient::Error => e
43
42
  logger.fatal('Request Failed', e.error_details) unless quiet?
@@ -46,7 +45,7 @@ module LabClient
46
45
  self.retries += 1
47
46
 
48
47
  # Assume Retry After by Default
49
- logger.debug('Retry After', value: retry_after, retry_header: retry_header) if debug?
48
+ logger.debug('Retry After', value: retry_after, retry_debug_headers: retry_debug_headers) if debug?
50
49
  self.delay = retry_after if resp.headers.key? 'retry-after'
51
50
 
52
51
  self.delay += delay_factor
@@ -20,7 +20,7 @@ module LabClient
20
20
  :name => "create_eks_clusters",
21
21
  :state => "on",
22
22
  :gates => [
23
- [0] OpenStruct {
23
+ [0] LabStruct {
24
24
  :key => "boolean",
25
25
  :value => true
26
26
  }
@@ -3,11 +3,11 @@ module LabClient
3
3
  # Specifics
4
4
  class Files < Common
5
5
  doc 'Show' do
6
- desc 'Allows you to receive information about file in repository like name, size, content [Project ID, File Path, Ref (master default), kind]'
6
+ desc 'Allows you to receive information about file in repository like name, size, content [Project ID, File Path, Ref (main default), kind]'
7
7
  example 'client.files.show(264, "README.md")'
8
8
 
9
9
  markdown <<~DOC
10
- Ref will default to `master`
10
+ Ref will default to `main`
11
11
 
12
12
  Kind can be left empty or set to either :raw or :blame
13
13
  DOC
@@ -15,12 +15,12 @@ module LabClient
15
15
 
16
16
  doc 'Show' do
17
17
  desc 'Raw Content'
18
- example 'client.files.show(264, "README.md", :master, :raw)'
18
+ example 'client.files.show(264, "README.md", :main, :raw)'
19
19
  end
20
20
 
21
21
  doc 'Show' do
22
22
  desc 'Blame'
23
- example 'client.files.show(264, "README.md", :master, :blame)'
23
+ example 'client.files.show(264, "README.md", :main, :blame)'
24
24
  end
25
25
 
26
26
  doc 'Show' do
@@ -31,7 +31,7 @@ module LabClient
31
31
  DOC
32
32
  end
33
33
 
34
- def show(project_id, file_path, ref = :master, kind = nil)
34
+ def show(project_id, file_path, ref = :main, kind = nil)
35
35
  kind = case kind
36
36
  when :raw
37
37
  '/raw'
@@ -88,7 +88,7 @@ module Typhoeus
88
88
  elsif headers['content-type']&.include? 'text/plain'
89
89
  body
90
90
  else
91
- result = Oj.load(body, mode: :compat, object_class: LabClient::LabStruct)
91
+ result = Oj.load(body, mode: :compat, symbol_keys: true, object_class: LabClient::LabStruct)
92
92
  result.instance_variable_set(:@response, self) if result.instance_of?(LabClient::LabStruct)
93
93
  result
94
94
  end
@@ -5,7 +5,7 @@ module LabClient
5
5
  include LabClient::Logger
6
6
  include CurlHelper
7
7
 
8
- attr_reader :client, :response
8
+ attr_reader :client
9
9
 
10
10
  extend Docs
11
11
 
@@ -105,18 +105,13 @@ module LabClient
105
105
  client.quiet?
106
106
  end
107
107
 
108
- # rubocop:disable Lint/MissingSuper
109
- def initialize(hash = nil, response = nil, client = nil)
108
+ def initialize(table = nil, response = nil, client = nil)
109
+ # @table = table unless table.nil?
110
110
  @client = client
111
111
  @response = response
112
112
 
113
- @table = {}
114
- hash&.each_pair do |k, v|
115
- k = k.to_sym
116
- @table[k] = v
117
- end
113
+ super(table)
118
114
  end
119
- # rubocop:enable Lint/MissingSuper
120
115
 
121
116
  # Forward response success
122
117
  def success?
@@ -1,16 +1,28 @@
1
- # Extensions for OpenStruct specific to LabClient
1
+ # Extensions for LabStruct specific to LabClient
2
2
  module LabClient
3
- # Unique inherited class to not override top level openstruct
4
- class LabStruct < OpenStruct
3
+ # Unique inherited class to not override top level LabStruct
4
+ class LabStruct
5
5
  include CurlHelper
6
- attr_reader :response
6
+ attr_reader :response, :table
7
+
8
+ def initialize(hash = {})
9
+ @table = if hash.instance_of?(LabClient::LabStruct)
10
+ hash.to_h
11
+ else
12
+ hash
13
+ end
14
+ end
15
+
16
+ def to_h
17
+ @table
18
+ end
7
19
 
8
20
  def keys
9
- to_h.keys.sort
21
+ @table.keys.sort
10
22
  end
11
23
 
12
24
  def inspect
13
- to_h.inspect
25
+ @table.inspect
14
26
  end
15
27
 
16
28
  def as_json(*args)
@@ -18,7 +30,7 @@ module LabClient
18
30
  end
19
31
 
20
32
  def slice(*opts)
21
- to_h.slice(*opts)
33
+ @table.slice(*opts)
22
34
  end
23
35
 
24
36
  def client
@@ -29,5 +41,25 @@ module LabClient
29
41
  def success?
30
42
  @response.success?
31
43
  end
44
+
45
+ def method_missing(method, *_args)
46
+ @table[method] if @table.keys.include?(method)
47
+ end
48
+
49
+ def respond_to_missing?(method_name, include_private = false)
50
+ @table.keys.include?(method_name) || super
51
+ end
52
+
53
+ def key?(idx)
54
+ @table.key? idx
55
+ end
56
+
57
+ def []=(name, value)
58
+ @table[name] = value
59
+ end
60
+
61
+ def [](name)
62
+ @table[name.to_sym]
63
+ end
32
64
  end
33
65
  end
@@ -13,13 +13,21 @@ module LabClient
13
13
  end
14
14
 
15
15
  doc 'Delete' do
16
- desc 'Delete through MergeRequest'
16
+ desc 'Delete via MergeRequest'
17
17
  example <<~DOC
18
- mr = client.merge_requests.show(343,2)
18
+ mr = client.merge_requests.delete(343,2)
19
19
  mr.delete
20
20
  DOC
21
21
  end
22
22
 
23
+ doc 'Delete' do
24
+ desc 'Via Project'
25
+ example <<~DOC
26
+ project = client.projects.show(1)
27
+ project.merge_requests_delete(12)
28
+ DOC
29
+ end
30
+
23
31
  # Delete
24
32
  def delete(project_id, merge_request_id)
25
33
  project_id = format_id(project_id)
@@ -31,7 +31,7 @@ module LabClient
31
31
  example 'client.notifications.update_project(16, level: :custom)'
32
32
 
33
33
  result <<~DOC
34
- OpenStruct {
34
+ LabStruct {
35
35
  :level => "custom",
36
36
  :events => LabStruct {
37
37
  :new_release => nil,
@@ -321,7 +321,7 @@ module LabClient
321
321
  end
322
322
 
323
323
  # Files
324
- def file(file_path, ref = :master, kind = nil)
324
+ def file(file_path, ref = :main, kind = nil)
325
325
  client.files.show(id, file_path, ref, kind)
326
326
  end
327
327
 
@@ -647,6 +647,10 @@ module LabClient
647
647
  client.merge_requests.create(id, query)
648
648
  end
649
649
 
650
+ def merge_request_delete(merge_request_iid)
651
+ client.merge_requests.delete(id, merge_request_iid)
652
+ end
653
+
650
654
  # Access Requests
651
655
  def request_access
652
656
  client.projects.access_requests.create(id)
@@ -1,6 +1,6 @@
1
1
  # Overall version
2
2
  module LabClient
3
- VERSION = '0.4.2'.freeze
3
+ VERSION = '0.5.0'.freeze
4
4
 
5
5
  # Make it easy to print version
6
6
  def self.version
data/lib/labclient.rb CHANGED
@@ -876,7 +876,7 @@ require 'labclient/generator/generator'
876
876
  require 'labclient/generator/wizard'
877
877
 
878
878
  # Dynamically Require Templates (Simplify new template creation)
879
- Dir["#{File.dirname(__FILE__)}/labclient/generator/templates/*.rb"].sort.each { |file| require file }
879
+ Dir["#{File.dirname(__FILE__)}/labclient/generator/templates/*.rb"].each { |file| require file }
880
880
 
881
881
  # Load Client Files - I am Very Last!
882
882
  require 'labclient/client/setup'
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.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Davin Walker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-11 00:00:00.000000000 Z
11
+ date: 2021-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -224,16 +224,16 @@ dependencies:
224
224
  name: rubocop
225
225
  requirement: !ruby/object:Gem::Requirement
226
226
  requirements:
227
- - - "~>"
227
+ - - ">="
228
228
  - !ruby/object:Gem::Version
229
- version: '1.10'
229
+ version: '0'
230
230
  type: :development
231
231
  prerelease: false
232
232
  version_requirements: !ruby/object:Gem::Requirement
233
233
  requirements:
234
- - - "~>"
234
+ - - ">="
235
235
  - !ruby/object:Gem::Version
236
- version: '1.10'
236
+ version: '0'
237
237
  - !ruby/object:Gem::Dependency
238
238
  name: rubocop-minitest
239
239
  requirement: !ruby/object:Gem::Requirement
@@ -943,7 +943,8 @@ files:
943
943
  homepage: https://gitlab.com/labclient/labclient
944
944
  licenses:
945
945
  - MIT
946
- metadata: {}
946
+ metadata:
947
+ rubygems_mfa_required: 'true'
947
948
  post_install_message:
948
949
  rdoc_options: []
949
950
  require_paths:
@@ -959,7 +960,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
959
960
  - !ruby/object:Gem::Version
960
961
  version: '0'
961
962
  requirements: []
962
- rubygems_version: 3.0.3
963
+ rubygems_version: 3.2.32
963
964
  signing_key:
964
965
  specification_version: 4
965
966
  summary: Gitlab API Client