fbe 0.0.48 → 0.0.50
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -1
- data/Gemfile.lock +13 -4
- data/fbe.gemspec +1 -0
- data/lib/fbe/github_graph.rb +127 -0
- data/lib/fbe.rb +1 -1
- data/test/fbe/test_github_graph.rb +94 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc0c3d0b5163d98b8bf564c30c2727c1e5df24b050ed4e9dbec2a1c25723fd22
|
4
|
+
data.tar.gz: 5b0cf7b19dca874f9781416b9c037643669840d127839413b67975813284fcfe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2cf37cbb7d33126faabb2c9ad164842c8b5fa8a860654caa00acf0e28392d0509240434675978c83562e7a65e65e90098c03f959d8c8826821fbcd33b2cb9fd
|
7
|
+
data.tar.gz: 1465c3da23d7f32bec33ca8f41a15a1987da15f4ab7edb66de1b0c606540e2bbe696b79b0bbaff7c8871bac5f19fd503c6eedfcc288cf0e386896ad552007f05
|
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
@@ -9,6 +9,7 @@ PATH
|
|
9
9
|
faraday-http-cache (> 0)
|
10
10
|
faraday-multipart (> 0)
|
11
11
|
faraday-retry (> 0)
|
12
|
+
graphql-client (> 0)
|
12
13
|
judges (> 0)
|
13
14
|
loog (> 0)
|
14
15
|
obk (> 0)
|
@@ -53,7 +54,7 @@ GEM
|
|
53
54
|
ast (2.4.2)
|
54
55
|
backtrace (0.4.0)
|
55
56
|
base64 (0.2.0)
|
56
|
-
baza.rb (0.0.
|
57
|
+
baza.rb (0.0.6)
|
57
58
|
backtrace (> 0)
|
58
59
|
faraday (> 0)
|
59
60
|
faraday-http-cache (> 0)
|
@@ -103,7 +104,14 @@ GEM
|
|
103
104
|
ffi (1.17.0-x64-mingw-ucrt)
|
104
105
|
ffi (1.17.0-x86_64-darwin)
|
105
106
|
ffi (1.17.0-x86_64-linux-gnu)
|
107
|
+
fiber-storage (1.0.0)
|
106
108
|
gli (2.21.5)
|
109
|
+
graphql (2.3.14)
|
110
|
+
base64
|
111
|
+
fiber-storage
|
112
|
+
graphql-client (0.23.0)
|
113
|
+
activesupport (>= 3.0)
|
114
|
+
graphql (>= 1.13.0)
|
107
115
|
hashdiff (1.1.1)
|
108
116
|
i18n (1.14.5)
|
109
117
|
concurrent-ruby (~> 1.0)
|
@@ -113,7 +121,7 @@ GEM
|
|
113
121
|
reline (>= 0.4.2)
|
114
122
|
iri (0.8.0)
|
115
123
|
json (2.7.2)
|
116
|
-
judges (0.25.
|
124
|
+
judges (0.25.2)
|
117
125
|
backtrace (~> 0)
|
118
126
|
baza.rb (~> 0)
|
119
127
|
concurrent-ruby (~> 1.2)
|
@@ -133,7 +141,7 @@ GEM
|
|
133
141
|
crass (~> 1.0.2)
|
134
142
|
nokogiri (>= 1.12.0)
|
135
143
|
loog (0.6.0)
|
136
|
-
minitest (5.
|
144
|
+
minitest (5.25.0)
|
137
145
|
minitest-reporters (1.7.1)
|
138
146
|
ansi
|
139
147
|
builder
|
@@ -278,7 +286,8 @@ PLATFORMS
|
|
278
286
|
|
279
287
|
DEPENDENCIES
|
280
288
|
fbe!
|
281
|
-
|
289
|
+
graphql-client
|
290
|
+
minitest (= 5.25.0)
|
282
291
|
minitest-reporters (= 1.7.1)
|
283
292
|
rake (= 13.2.1)
|
284
293
|
rspec-rails (= 6.1.3)
|
data/fbe.gemspec
CHANGED
@@ -46,6 +46,7 @@ Gem::Specification.new do |s|
|
|
46
46
|
s.add_dependency 'faraday-http-cache', '>0'
|
47
47
|
s.add_dependency 'faraday-multipart', '>0'
|
48
48
|
s.add_dependency 'faraday-retry', '>0'
|
49
|
+
s.add_dependency 'graphql-client', '>0'
|
49
50
|
s.add_dependency 'judges', '>0'
|
50
51
|
s.add_dependency 'loog', '>0'
|
51
52
|
s.add_dependency 'obk', '>0'
|
@@ -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.50
|
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
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - ">"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: graphql-client
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: judges
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -227,6 +241,7 @@ files:
|
|
227
241
|
- lib/fbe/award.rb
|
228
242
|
- lib/fbe/conclude.rb
|
229
243
|
- lib/fbe/fb.rb
|
244
|
+
- lib/fbe/github_graph.rb
|
230
245
|
- lib/fbe/if_absent.rb
|
231
246
|
- lib/fbe/issue.rb
|
232
247
|
- lib/fbe/iterate.rb
|
@@ -247,6 +262,7 @@ files:
|
|
247
262
|
- test/fbe/test_award.rb
|
248
263
|
- test/fbe/test_conclude.rb
|
249
264
|
- test/fbe/test_fb.rb
|
265
|
+
- test/fbe/test_github_graph.rb
|
250
266
|
- test/fbe/test_if_absent.rb
|
251
267
|
- test/fbe/test_issue.rb
|
252
268
|
- test/fbe/test_iterate.rb
|