fbe 0.19.0 → 0.19.2
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 +4 -4
- data/lib/fbe/middleware/sqlite_store.rb +3 -1
- data/lib/fbe/octo.rb +8 -5
- data/lib/fbe.rb +1 -1
- data/test/fbe/test_octo.rb +15 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2d7532cc824357975d405225601f1f0873721e96b5328a9cd4e1d57191008a9
|
4
|
+
data.tar.gz: 1c64cade131c3f2751c0dffaaa9bd157cdc4ff41a70b0acf5efe8a8f2788e08b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 742ec0b8b9970a86549a8292ad5390cb5dcdb4addbc4c45590f3ff10526a67d4038c65cc9534d818859558a0915efeeef30d165816cd24a9a12cda2ec83cc87e
|
7
|
+
data.tar.gz: 70eb53d6eb30817c735ef3ab2ea62e050106b616a8384a647106c0ef4b40e861deb62d6a3dfc43a32471157144c9225425e092e4a4df614e91679444c5219f64
|
@@ -14,11 +14,13 @@ require_relative '../../fbe/middleware'
|
|
14
14
|
# Copyright:: Copyright (c) 2024-2025 Zerocracy
|
15
15
|
# License:: MIT
|
16
16
|
class Fbe::Middleware::SqliteStore
|
17
|
+
attr_reader :path
|
18
|
+
|
17
19
|
def initialize(path)
|
18
20
|
raise ArgumentError, 'Database path cannot be nil or empty' if path.nil? || path.empty?
|
19
21
|
dir = File.dirname(path)
|
20
22
|
raise ArgumentError, "Directory #{dir} does not exist" unless File.directory?(dir)
|
21
|
-
@path = path
|
23
|
+
@path = File.absolute_path(path)
|
22
24
|
open
|
23
25
|
prepare
|
24
26
|
at_exit { close }
|
data/lib/fbe/octo.rb
CHANGED
@@ -47,7 +47,7 @@ def Fbe.octo(options: $options, global: $global, loog: $loog)
|
|
47
47
|
loog.debug("The 'GITHUB_TOKEN' environment was provided")
|
48
48
|
end
|
49
49
|
else
|
50
|
-
loog.debug("The 'github_token' option was provided")
|
50
|
+
loog.debug("The 'github_token' option was provided (#{token.length} chars)")
|
51
51
|
end
|
52
52
|
if token.nil?
|
53
53
|
loog.warn('Accessing GitHub API without a token!')
|
@@ -55,10 +55,6 @@ def Fbe.octo(options: $options, global: $global, loog: $loog)
|
|
55
55
|
loog.warn('The GitHub API token is an empty string, won\'t use it')
|
56
56
|
else
|
57
57
|
o = Octokit::Client.new(access_token: token)
|
58
|
-
loog.info(
|
59
|
-
"Accessing GitHub API with a token (#{token.length} chars, ending by #{token[-4..].inspect}, " \
|
60
|
-
"#{Octokit::Client.new(access_token: token).rate_limit.remaining} quota remaining)"
|
61
|
-
)
|
62
58
|
end
|
63
59
|
o.auto_paginate = true
|
64
60
|
o.per_page = 100
|
@@ -84,6 +80,7 @@ def Fbe.octo(options: $options, global: $global, loog: $loog)
|
|
84
80
|
if options.sqlite_cache
|
85
81
|
store = Fbe::Middleware::SqliteStore.new(options.sqlite_cache)
|
86
82
|
serializer = JSON
|
83
|
+
loog.info("Using HTTP cache in SQLite file: #{store.path}")
|
87
84
|
end
|
88
85
|
builder.use(
|
89
86
|
Faraday::HttpCache,
|
@@ -96,6 +93,12 @@ def Fbe.octo(options: $options, global: $global, loog: $loog)
|
|
96
93
|
end
|
97
94
|
o.middleware = stack
|
98
95
|
o = Verbose.new(o, log: loog)
|
96
|
+
unless token.nil? || token.empty?
|
97
|
+
loog.info(
|
98
|
+
"Accessing GitHub API with a token (#{token.length} chars, ending by #{token[-4..].inspect}, " \
|
99
|
+
"#{o.rate_limit.remaining} quota remaining)"
|
100
|
+
)
|
101
|
+
end
|
99
102
|
else
|
100
103
|
loog.debug('The connection to GitHub API is mocked')
|
101
104
|
o = Fbe::FakeOctokit.new
|
data/lib/fbe.rb
CHANGED
data/test/fbe/test_octo.rb
CHANGED
@@ -138,10 +138,8 @@ class TestOcto < Fbe::Test
|
|
138
138
|
body: '{}', headers: { 'X-RateLimit-Remaining' => '1234' }
|
139
139
|
)
|
140
140
|
buf = Loog::Buffer.new
|
141
|
-
|
141
|
+
Fbe.octo(loog: buf, global: {}, options: Judges::Options.new({ 'github_token' => 'secret_github_token' }))
|
142
142
|
assert_match(/Accessing GitHub API with a token \(19 chars, ending by "oken", 1234 quota remaining\)/, buf.to_s)
|
143
|
-
assert_nil(o.last_response, 'Not to be requests until initialize main Octokit client, ' \
|
144
|
-
'because middleware cached after first request and not apply after')
|
145
143
|
end
|
146
144
|
|
147
145
|
def test_retrying
|
@@ -390,4 +388,18 @@ class TestOcto < Fbe::Test
|
|
390
388
|
assert_equal('user1', o.user_name_by_id(42))
|
391
389
|
end
|
392
390
|
end
|
391
|
+
|
392
|
+
def test_through_sqlite_store_when_broken_token
|
393
|
+
WebMock.disable_net_connect!
|
394
|
+
Dir.mktmpdir do |dir|
|
395
|
+
global = {}
|
396
|
+
file = File.expand_path('test.db', dir)
|
397
|
+
stub_request(:get, 'https://api.github.com/user/4242').to_return(status: 401)
|
398
|
+
o = Fbe.octo(loog: Loog::NULL, global:, options: Judges::Options.new({ 'sqlite_cache' => file }))
|
399
|
+
assert_raises(StandardError) do
|
400
|
+
assert_equal('user1', o.user_name_by_id(4242))
|
401
|
+
end
|
402
|
+
assert_path_exists(file)
|
403
|
+
end
|
404
|
+
end
|
393
405
|
end
|