fbe 0.0.48 → 0.0.49
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/Gemfile +2 -1
- data/Gemfile.lock +12 -4
- data/lib/fbe/github_graph.rb +127 -0
- data/lib/fbe.rb +1 -1
- data/test/fbe/test_github_graph.rb +94 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: de934a3e457616c2fe03c05db185cacf7bde9f433154d5ce27f23eb39c98c582
|
|
4
|
+
data.tar.gz: 2d142124379b8ba0d5235c2ea216d1fc21c2797b1734fbee5bf291d5fb83849b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: be56b1e327441975aec62216e59cec70d34b6bf2adb3a3dc794991bfbfe54bfcbdfc79340d4d06138ac4c249ee71361509a675e2ab6b2bf4d1131d3436010ae3
|
|
7
|
+
data.tar.gz: e76fc18cd19acc4d32263b38f3b94d12c8c926ce0004a904a568a06de0bf2d53dcaf445e6255beff4a84bb8636903524026d1429f0dcd48fd28880046ad5b291
|
data/Gemfile
CHANGED
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
source 'https://rubygems.org'
|
|
24
24
|
gemspec
|
|
25
25
|
|
|
26
|
-
gem '
|
|
26
|
+
gem 'graphql-client'
|
|
27
|
+
gem 'minitest', '5.25.0', require: false
|
|
27
28
|
gem 'minitest-reporters', '1.7.1', require: false
|
|
28
29
|
gem 'rake', '13.2.1', require: false
|
|
29
30
|
gem 'rspec-rails', '6.1.3', require: false
|
data/Gemfile.lock
CHANGED
|
@@ -53,7 +53,7 @@ GEM
|
|
|
53
53
|
ast (2.4.2)
|
|
54
54
|
backtrace (0.4.0)
|
|
55
55
|
base64 (0.2.0)
|
|
56
|
-
baza.rb (0.0.
|
|
56
|
+
baza.rb (0.0.6)
|
|
57
57
|
backtrace (> 0)
|
|
58
58
|
faraday (> 0)
|
|
59
59
|
faraday-http-cache (> 0)
|
|
@@ -103,7 +103,14 @@ GEM
|
|
|
103
103
|
ffi (1.17.0-x64-mingw-ucrt)
|
|
104
104
|
ffi (1.17.0-x86_64-darwin)
|
|
105
105
|
ffi (1.17.0-x86_64-linux-gnu)
|
|
106
|
+
fiber-storage (1.0.0)
|
|
106
107
|
gli (2.21.5)
|
|
108
|
+
graphql (2.3.14)
|
|
109
|
+
base64
|
|
110
|
+
fiber-storage
|
|
111
|
+
graphql-client (0.23.0)
|
|
112
|
+
activesupport (>= 3.0)
|
|
113
|
+
graphql (>= 1.13.0)
|
|
107
114
|
hashdiff (1.1.1)
|
|
108
115
|
i18n (1.14.5)
|
|
109
116
|
concurrent-ruby (~> 1.0)
|
|
@@ -113,7 +120,7 @@ GEM
|
|
|
113
120
|
reline (>= 0.4.2)
|
|
114
121
|
iri (0.8.0)
|
|
115
122
|
json (2.7.2)
|
|
116
|
-
judges (0.25.
|
|
123
|
+
judges (0.25.2)
|
|
117
124
|
backtrace (~> 0)
|
|
118
125
|
baza.rb (~> 0)
|
|
119
126
|
concurrent-ruby (~> 1.2)
|
|
@@ -133,7 +140,7 @@ GEM
|
|
|
133
140
|
crass (~> 1.0.2)
|
|
134
141
|
nokogiri (>= 1.12.0)
|
|
135
142
|
loog (0.6.0)
|
|
136
|
-
minitest (5.
|
|
143
|
+
minitest (5.25.0)
|
|
137
144
|
minitest-reporters (1.7.1)
|
|
138
145
|
ansi
|
|
139
146
|
builder
|
|
@@ -278,7 +285,8 @@ PLATFORMS
|
|
|
278
285
|
|
|
279
286
|
DEPENDENCIES
|
|
280
287
|
fbe!
|
|
281
|
-
|
|
288
|
+
graphql-client
|
|
289
|
+
minitest (= 5.25.0)
|
|
282
290
|
minitest-reporters (= 1.7.1)
|
|
283
291
|
rake (= 13.2.1)
|
|
284
292
|
rspec-rails (= 6.1.3)
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# MIT License
|
|
4
|
+
#
|
|
5
|
+
# Copyright (c) 2024 Zerocracy
|
|
6
|
+
#
|
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
# furnished to do so, subject to the following conditions:
|
|
13
|
+
#
|
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
# copies or substantial portions of the Software.
|
|
16
|
+
#
|
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
# SOFTWARE.
|
|
24
|
+
|
|
25
|
+
require 'loog'
|
|
26
|
+
require 'graphql/client'
|
|
27
|
+
require 'graphql/client/http'
|
|
28
|
+
|
|
29
|
+
# Interface to GitHub GraphQL API.
|
|
30
|
+
#
|
|
31
|
+
# @param [Judges::Options] options The options available globally
|
|
32
|
+
# @param [Hash] global Hash of global options
|
|
33
|
+
# @param [Loog] loog Logging facility
|
|
34
|
+
def Fbe.github_graph(options: $options, global: $global, loog: $loog)
|
|
35
|
+
global[:github_graph] ||=
|
|
36
|
+
if options.testing.nil?
|
|
37
|
+
Fbe::Graph.new(token: options.github_token || ENV.fetch('GITHUB_TOKEN', nil))
|
|
38
|
+
else
|
|
39
|
+
loog.debug('The connection to GitHub GraphQL API is mocked')
|
|
40
|
+
Fbe::Graph::Fake.new
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# The GitHub GraphQL client
|
|
45
|
+
class Fbe::Graph
|
|
46
|
+
def initialize(token:, host: 'api.github.com')
|
|
47
|
+
@token = token
|
|
48
|
+
http = HTTP.new(token, host)
|
|
49
|
+
@client = GraphQL::Client.new(schema: GraphQL::Client.load_schema(http), execute: http)
|
|
50
|
+
@client.allow_dynamic_queries = true
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def query(query_string)
|
|
54
|
+
result = @client.query(@client.parse(query_string))
|
|
55
|
+
result.data
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def resolved_conversations(owner, name, number)
|
|
59
|
+
result = query(
|
|
60
|
+
<<~GRAPHQL
|
|
61
|
+
{
|
|
62
|
+
repository(owner: "#{owner}", name: "#{name}") {
|
|
63
|
+
pullRequest(number: #{number}) {
|
|
64
|
+
reviewThreads(first: 100) {
|
|
65
|
+
nodes {
|
|
66
|
+
id
|
|
67
|
+
isResolved
|
|
68
|
+
comments(first: 100) {
|
|
69
|
+
nodes {
|
|
70
|
+
id
|
|
71
|
+
body
|
|
72
|
+
author {
|
|
73
|
+
login
|
|
74
|
+
}
|
|
75
|
+
createdAt
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
GRAPHQL
|
|
84
|
+
)
|
|
85
|
+
result.repository.pull_request.review_threads.to_h['nodes']
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def total_commits(owner, name, branch)
|
|
89
|
+
result = query(
|
|
90
|
+
<<~GRAPHQL
|
|
91
|
+
{
|
|
92
|
+
repository(owner: "#{owner}", name: "#{name}") {
|
|
93
|
+
ref(qualifiedName: "#{branch}") {
|
|
94
|
+
target {
|
|
95
|
+
... on Commit {
|
|
96
|
+
history {
|
|
97
|
+
totalCount
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
GRAPHQL
|
|
105
|
+
)
|
|
106
|
+
result.repository.ref.target.history.total_count
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# The HTTP class
|
|
110
|
+
class HTTP < GraphQL::Client::HTTP
|
|
111
|
+
def initialize(token, host)
|
|
112
|
+
@token = token
|
|
113
|
+
super("https://#{host}/graphql")
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def headers(_context)
|
|
117
|
+
{ Authorization: "Bearer #{@token}" }
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# Fake GitHub GraphQL client, for tests.
|
|
122
|
+
class Fake
|
|
123
|
+
def query(_query)
|
|
124
|
+
{}
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
data/lib/fbe.rb
CHANGED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# MIT License
|
|
4
|
+
#
|
|
5
|
+
# Copyright (c) 2024 Zerocracy
|
|
6
|
+
#
|
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
# furnished to do so, subject to the following conditions:
|
|
13
|
+
#
|
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
# copies or substantial portions of the Software.
|
|
16
|
+
#
|
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
# SOFTWARE.
|
|
24
|
+
|
|
25
|
+
require 'minitest/autorun'
|
|
26
|
+
require 'judges/options'
|
|
27
|
+
require 'webmock/minitest'
|
|
28
|
+
require 'loog'
|
|
29
|
+
require_relative '../../lib/fbe/github_graph'
|
|
30
|
+
|
|
31
|
+
# Test.
|
|
32
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
33
|
+
# Copyright:: Copyright (c) 2024 Zerocracy
|
|
34
|
+
# License:: MIT
|
|
35
|
+
class TestGitHubGraph < Minitest::Test
|
|
36
|
+
def test_simple_use
|
|
37
|
+
WebMock.disable_net_connect!
|
|
38
|
+
global = {}
|
|
39
|
+
options = Judges::Options.new({ 'testing' => true })
|
|
40
|
+
Fbe.github_graph(options:, loog: Loog::NULL, global:)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_simple_use_graph
|
|
44
|
+
skip # it's a "live" test, run it manually if you need it
|
|
45
|
+
WebMock.allow_net_connect!
|
|
46
|
+
client = Fbe::Graph.new(token: ENV.fetch('GITHUB_TOKEN', nil))
|
|
47
|
+
result = client.query(
|
|
48
|
+
<<~GRAPHQL
|
|
49
|
+
query {
|
|
50
|
+
viewer {
|
|
51
|
+
login
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
GRAPHQL
|
|
55
|
+
)
|
|
56
|
+
refute(result.viewer.login.empty?)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_use_with_global_variables
|
|
60
|
+
WebMock.disable_net_connect!
|
|
61
|
+
$global = {}
|
|
62
|
+
$options = Judges::Options.new({ 'testing' => true })
|
|
63
|
+
$loog = Loog::NULL
|
|
64
|
+
Fbe.github_graph
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def test_with_broken_token
|
|
68
|
+
skip # it's a "live" test, run it manually if you need it
|
|
69
|
+
WebMock.allow_net_connect!
|
|
70
|
+
global = {}
|
|
71
|
+
options = Judges::Options.new({ 'github_token' => 'incorrect-value' })
|
|
72
|
+
assert_raises { Fbe.github_graph(loog: Loog::NULL, global:, options:) }
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def test_gets_resolved_conversations
|
|
76
|
+
skip # it's a "live" test, run it manually if you need it
|
|
77
|
+
WebMock.allow_net_connect!
|
|
78
|
+
global = {}
|
|
79
|
+
options = Judges::Options.new
|
|
80
|
+
g = Fbe.github_graph(options:, loog: Loog::NULL, global:)
|
|
81
|
+
result = g.resolved_conversations('zerocracy', 'baza', 172)
|
|
82
|
+
assert_equal(1, result.count)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def test_gets_total_commits_of_repo
|
|
86
|
+
skip # it's a "live" test, run it manually if you need it
|
|
87
|
+
WebMock.allow_net_connect!
|
|
88
|
+
global = {}
|
|
89
|
+
options = Judges::Options.new
|
|
90
|
+
g = Fbe.github_graph(options:, loog: Loog::NULL, global:)
|
|
91
|
+
result = g.total_commits('zerocracy', 'baza', 'master')
|
|
92
|
+
assert(result.positive?)
|
|
93
|
+
end
|
|
94
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fbe
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.49
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yegor Bugayenko
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2024-08-
|
|
11
|
+
date: 2024-08-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: backtrace
|
|
@@ -227,6 +227,7 @@ files:
|
|
|
227
227
|
- lib/fbe/award.rb
|
|
228
228
|
- lib/fbe/conclude.rb
|
|
229
229
|
- lib/fbe/fb.rb
|
|
230
|
+
- lib/fbe/github_graph.rb
|
|
230
231
|
- lib/fbe/if_absent.rb
|
|
231
232
|
- lib/fbe/issue.rb
|
|
232
233
|
- lib/fbe/iterate.rb
|
|
@@ -247,6 +248,7 @@ files:
|
|
|
247
248
|
- test/fbe/test_award.rb
|
|
248
249
|
- test/fbe/test_conclude.rb
|
|
249
250
|
- test/fbe/test_fb.rb
|
|
251
|
+
- test/fbe/test_github_graph.rb
|
|
250
252
|
- test/fbe/test_if_absent.rb
|
|
251
253
|
- test/fbe/test_issue.rb
|
|
252
254
|
- test/fbe/test_iterate.rb
|