fbe 0.23.2 → 0.23.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee5e623e0dd6b64525eb62f7dcad447a595c3c963c747acec37dda308cabcf98
4
- data.tar.gz: c422fd60aba87180dc2ab7265abe5458928b7df765b86e7c3eaea9f8b3884c34
3
+ metadata.gz: 8c12118d96ea30271b8b724c90d498eb3cc34a679bbef6be04153a53eec96e8e
4
+ data.tar.gz: 45363b59481ccff7b37d367acbabba81e7bddf0a649c204ac4e87559d9622729
5
5
  SHA512:
6
- metadata.gz: 0fcd4bf85f7ae73caab3b4b2a834b1978c2fb4aee2c58a83fcb53098d25d6208f25f99ded13ac5efbd441d6f7eeb24f22d5c74249f802353568781d38e9e0d93
7
- data.tar.gz: 3b4aab5363b741fb8f9054a32a84e008a9ad5487d8f668580cbe6d6fdbe0b447511f6c999bcad9b4d906cbd017566e50bfb31ac881c2271c793fe0ce111700b9
6
+ metadata.gz: 04f4c500161bbb87de44b25e1c160c2c03276c4f4737589dea8691c76f0a4a24824b74d4b278db5ac777e306d8c01b7879434ced44ee28b9efcd0cf96c4b0ea9
7
+ data.tar.gz: 1f75a0011d1be3518a72b99d8ffd5e6e4746b4a0a130d3e6507c145b389197419e788a2b0eb7e09fce0ba913ef0621be2754fcfa2000babb03bf58d0250b9748
data/Gemfile.lock CHANGED
@@ -13,6 +13,7 @@ PATH
13
13
  faraday-retry (~> 2.3)
14
14
  filesize (~> 0.2)
15
15
  graphql-client (~> 0.26)
16
+ intercepted (~> 0.2)
16
17
  judges (~> 0.46)
17
18
  liquid (~> 5.5)
18
19
  loog (~> 0.6)
@@ -115,6 +116,7 @@ GEM
115
116
  hashdiff (1.2.0)
116
117
  i18n (1.14.7)
117
118
  concurrent-ruby (~> 1.0)
119
+ intercepted (0.2.0)
118
120
  iri (0.11.2)
119
121
  json (2.12.2)
120
122
  judges (0.50.5)
data/fbe.gemspec CHANGED
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
33
33
  s.add_dependency 'faraday-retry', '~>2.3'
34
34
  s.add_dependency 'filesize', '~>0.2'
35
35
  s.add_dependency 'graphql-client', '~>0.26'
36
+ s.add_dependency 'intercepted', '~>0.2'
36
37
  s.add_dependency 'judges', '~>0.46'
37
38
  s.add_dependency 'liquid', '~>5.5'
38
39
  s.add_dependency 'loog', '~>0.6'
@@ -31,11 +31,9 @@ class Fbe::Middleware::Trace < Faraday::Middleware
31
31
  #
32
32
  # @param [Object] app The next middleware in the stack
33
33
  # @param [Array] trace The array to store trace entries
34
- # @param [Boolean] all Print ALL requests, even very fast?
35
- def initialize(app, trace, all: true)
34
+ def initialize(app, trace)
36
35
  super(app)
37
36
  @trace = trace
38
- @all = all
39
37
  end
40
38
 
41
39
  # Processes the HTTP request and records trace information.
@@ -51,12 +49,10 @@ class Fbe::Middleware::Trace < Faraday::Middleware
51
49
  @app.call(env).on_complete do |response_env|
52
50
  finished = Time.now
53
51
  duration = finished - entry[:started_at]
54
- if duration > 0.01 || @all
55
- entry[:status] = response_env.status
56
- entry[:finished_at] = finished
57
- entry[:duration] = duration
58
- @trace << entry
59
- end
52
+ entry[:status] = response_env.status
53
+ entry[:finished_at] = finished
54
+ entry[:duration] = duration
55
+ @trace << entry
60
56
  end
61
57
  end
62
58
  end
data/lib/fbe/octo.rb CHANGED
@@ -8,11 +8,13 @@ require 'ellipsized'
8
8
  require 'faraday/http_cache'
9
9
  require 'faraday/retry'
10
10
  require 'filesize'
11
+ require 'intercepted'
11
12
  require 'json'
12
13
  require 'loog'
13
14
  require 'obk'
14
15
  require 'octokit'
15
16
  require 'others'
17
+ require 'tago'
16
18
  require 'uri'
17
19
  require 'verbose'
18
20
  require_relative '../fbe'
@@ -105,7 +107,7 @@ def Fbe.octo(options: $options, global: $global, loog: $loog)
105
107
  end
106
108
  builder.use(Octokit::Response::RaiseError)
107
109
  builder.use(Faraday::Response::Logger, loog, formatter: Fbe::Middleware::Formatter)
108
- builder.use(Fbe::Middleware::Trace, trace, all: false)
110
+ builder.use(Fbe::Middleware::Trace, trace)
109
111
  builder.adapter(Faraday.default_adapter)
110
112
  end
111
113
  o.middleware = stack
@@ -122,12 +124,12 @@ def Fbe.octo(options: $options, global: $global, loog: $loog)
122
124
  end
123
125
  o =
124
126
  decoor(o, loog:, trace:) do
125
- def print_trace!
127
+ def print_trace!(all: false, max: 5)
126
128
  if @trace.empty?
127
129
  @loog.debug('GitHub API trace is empty')
128
130
  else
129
131
  grouped =
130
- @trace.group_by do |entry|
132
+ @trace.select { |e| e[:duration] > 0.05 || all }.group_by do |entry|
131
133
  uri = URI.parse(entry[:url])
132
134
  query = uri.query
133
135
  query = "?#{query.ellipsized(40)}" if query
@@ -135,7 +137,16 @@ def Fbe.octo(options: $options, global: $global, loog: $loog)
135
137
  end
136
138
  message = grouped
137
139
  .sort_by { |_path, entries| -entries.count }
138
- .map { |path, entries| " #{path.gsub(%r{^https://api.github.com/}, '/')}: #{entries.count}" }
140
+ .map do |path, entries|
141
+ [
142
+ ' ',
143
+ path.gsub(%r{^https://api.github.com/}, '/'),
144
+ ': ',
145
+ entries.count,
146
+ " (#{entries.sum { |e| e[:duration] }.seconds})"
147
+ ].join
148
+ end
149
+ .take(max)
139
150
  .join("\n")
140
151
  @loog.info(
141
152
  "GitHub API trace (#{grouped.count} URLs vs #{@trace.count} requests, " \
@@ -183,11 +194,10 @@ def Fbe.octo(options: $options, global: $global, loog: $loog)
183
194
  end
184
195
  end
185
196
  o =
186
- others(o:) do |*args|
187
- if args.first != :off_quota? && args.first != :print_trace! && @o.off_quota?
188
- raise "We are off-quota (remaining: #{@o.rate_limit.remaining})"
197
+ intercepted(o) do |e, m, _args, _r|
198
+ if e == :before && m != :off_quota? && m != :print_trace! && m != :rate_limit && o.off_quota?
199
+ raise "We are off-quota (remaining: #{o.rate_limit.remaining}), can't do #{name}()"
189
200
  end
190
- @o.__send__(*args)
191
201
  end
192
202
  o
193
203
  end
data/lib/fbe.rb CHANGED
@@ -10,5 +10,5 @@
10
10
  # License:: MIT
11
11
  module Fbe
12
12
  # Current version of the gem (changed by +.rultor.yml+ on every release)
13
- VERSION = '0.23.2' unless const_defined?(:VERSION)
13
+ VERSION = '0.23.3' unless const_defined?(:VERSION)
14
14
  end
@@ -367,7 +367,6 @@ class TestOcto < Fbe::Test
367
367
  { body: '{}', headers: { 'X-RateLimit-Remaining' => '222' } }
368
368
  )
369
369
  stub_request(:get, 'https://api.github.com/user/123').to_return do
370
- sleep(0.02)
371
370
  {
372
371
  status: 200,
373
372
  body: '{"id":123,"login":"test"}',
@@ -375,7 +374,6 @@ class TestOcto < Fbe::Test
375
374
  }
376
375
  end
377
376
  stub_request(:get, 'https://api.github.com/repos/foo/bar').to_return do
378
- sleep(0.02)
379
377
  {
380
378
  status: 200,
381
379
  body: '{"id":456,"full_name":"foo/bar"}',
@@ -386,9 +384,9 @@ class TestOcto < Fbe::Test
386
384
  octo.user(123)
387
385
  octo.repository('foo/bar')
388
386
  octo.repository('foo/bar')
389
- octo.print_trace!
387
+ octo.print_trace!(all: true, max: 9_999)
390
388
  output = loog.to_s
391
- assert_includes output, '2 URLs vs 3 requests'
389
+ assert_includes output, '3 URLs vs 4 requests'
392
390
  assert_includes output, '222 quota left'
393
391
  assert_includes output, '/user/123: 1'
394
392
  assert_includes output, '/repos/foo/bar: 2'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fbe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.23.2
4
+ version: 0.23.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -163,6 +163,20 @@ dependencies:
163
163
  - - "~>"
164
164
  - !ruby/object:Gem::Version
165
165
  version: '0.26'
166
+ - !ruby/object:Gem::Dependency
167
+ name: intercepted
168
+ requirement: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - "~>"
171
+ - !ruby/object:Gem::Version
172
+ version: '0.2'
173
+ type: :runtime
174
+ prerelease: false
175
+ version_requirements: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - "~>"
178
+ - !ruby/object:Gem::Version
179
+ version: '0.2'
166
180
  - !ruby/object:Gem::Dependency
167
181
  name: judges
168
182
  requirement: !ruby/object:Gem::Requirement