Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#78 fix undefined method `pull_request' for nil #79

Merged
merged 6 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 32 additions & 23 deletions lib/fbe/github_graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
5 changes: 4 additions & 1 deletion lib/fbe/octo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
23 changes: 23 additions & 0 deletions test/fbe/test_github_graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Suban05 marked this conversation as resolved.
Show resolved Hide resolved
end
end