diff --git a/lib/fbe/github_graph.rb b/lib/fbe/github_graph.rb index cc43b58..7df2dbb 100644 --- a/lib/fbe/github_graph.rb +++ b/lib/fbe/github_graph.rb @@ -82,7 +82,7 @@ def resolved_conversations(owner, name, number) } GRAPHQL ) - result.repository.pull_request.review_threads.to_h['nodes'] + result&.to_h&.dig('repository', 'pullRequest', 'reviewThreads', 'nodes') || [] end def total_commits(owner, name, branch) @@ -124,29 +124,38 @@ def query(_query) {} end - def resolved_conversations(_owner, _name, _number) - [ - { - 'id' => 'PRRT_kwDOK2_4A85BHZAR', - 'isResolved' => true, - 'comments' => { - 'nodes' => [ - { - 'id' => 'PRRC_kwDOK2_4A85l3obO', - 'body' => 'first message', - 'author' => { '__typename' => 'User', 'login' => 'reviewer' }, - 'createdAt' => '2024-08-08T09:41:46Z' - }, - { - 'id' => 'PRRC_kwDOK2_4A85l3yTp', - 'body' => 'second message', - 'author' => { '__typename' => 'User', 'login' => 'programmer' }, - 'createdAt' => '2024-08-08T10:01:55Z' - } - ] - } + def resolved_conversations(owner, name, _number) + data = { + zerocracy_baza: [ + conversation('PRRT_kwDOK2_4A85BHZAR') + ] + } + data[:"#{owner}_#{name}"] || [] + end + + private + + def conversation(id) + { + 'id' => id, + 'isResolved' => true, + 'comments' => { + 'nodes' => [ + { + 'id' => 'PRRC_kwDOK2_4A85l3obO', + 'body' => 'first message', + 'author' => { '__typename' => 'User', 'login' => 'reviewer' }, + 'createdAt' => '2024-08-08T09:41:46Z' + }, + { + 'id' => 'PRRC_kwDOK2_4A85l3yTp', + 'body' => 'second message', + 'author' => { '__typename' => 'User', 'login' => 'programmer' }, + 'createdAt' => '2024-08-08T10:01:55Z' + } + ] } - ] + } end end end diff --git a/lib/fbe/octo.rb b/lib/fbe/octo.rb index bd22f47..ff1da59 100644 --- a/lib/fbe/octo.rb +++ b/lib/fbe/octo.rb @@ -522,7 +522,10 @@ def repository_events(repo, _options = {}) node_id: 'R_kgDOK2_4Aw', name: 'baza', full_name: 'zerocracy/baza', - private: false + private: false, + owner: { + login: 'zerocracy' + } } }, head: { diff --git a/test/fbe/test_github_graph.rb b/test/fbe/test_github_graph.rb index 98eb53e..5649b51 100644 --- a/test/fbe/test_github_graph.rb +++ b/test/fbe/test_github_graph.rb @@ -80,6 +80,15 @@ def test_gets_resolved_conversations g = Fbe.github_graph(options:, loog: Loog::NULL, global:) result = g.resolved_conversations('zerocracy', 'baza', 172) assert_equal(1, result.count) + result = g.resolved_conversations('zerocracy', 'baza', 0) + assert(Array, result.class) + assert(0, result.count) + result = g.resolved_conversations('zerocracy1', 'baza', 0) + assert(Array, result.class) + assert(0, result.count) + result = g.resolved_conversations('zerocracy', 'baza1', 0) + assert(Array, result.class) + assert(0, result.count) end def test_gets_total_commits_of_repo @@ -91,4 +100,18 @@ def test_gets_total_commits_of_repo result = g.total_commits('zerocracy', 'baza', 'master') assert(result.positive?) end + + def test_get_fake_empty_conversations + WebMock.disable_net_connect! + graph = Fbe.github_graph(options: Judges::Options.new('testing' => true), loog: Loog::NULL, global: {}) + result = graph.resolved_conversations(nil, 'baza', 172) + assert(result.empty?) + end + + def test_get_fake_conversations + WebMock.disable_net_connect! + graph = Fbe.github_graph(options: Judges::Options.new('testing' => true), loog: Loog::NULL, global: {}) + result = graph.resolved_conversations('zerocracy', 'baza', 172) + assert_equal(1, result.count) + end end