-
Notifications
You must be signed in to change notification settings - Fork 3
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
326 provide basic search functionality #459
base: master
Are you sure you want to change the base?
Conversation
|
||
# Returns a search result to the GraphQL API | ||
class SearchResolver | ||
def call(root, arguments, _context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C: Assignment Branch Condition size for call is too high. [17.26/15]
C: Method has too many lines. [38/10]
lib/search_resolver.rb
Outdated
end | ||
result = result.flatten | ||
graphQLResult = OpenStruct.new( | ||
entries: createEntries(result), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W: Useless assignment to variable - graphQLResult
.
C: Use snake_case for variable names.
lib/search_resolver.rb
Outdated
private | ||
def allOrganizationalUnits(result) | ||
search_result = 0 | ||
result.each do |element| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C: Use snake_case for method names.
lib/search_resolver.rb
Outdated
elem = element._data["_index"] | ||
if elem == 'user' || elem == 'organization' | ||
search_result+=1 | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C: Avoid comparing a variable with multiple items in a conditional, use Array#include?
instead.
lib/search_resolver.rb
Outdated
search_result | ||
end | ||
|
||
private |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W: Useless private
access modifier.
|
||
::Index::RepositoryIndex.import(create :repository, name: 'Ada/repository', owner: ada) | ||
::Index::RepositoryIndex.import(create :repository, name: 'Bob/repository', owner: bob) | ||
::Index::RepositoryIndex.import(create :repository, name: 'Adc/repository', owner: adc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C: Line is too long. [92/80]
::Index::RepositoryIndex.import(create :repository, name: 'Ada/repository', owner: ada) | ||
::Index::RepositoryIndex.import(create :repository, name: 'Bob/repository', owner: bob) | ||
::Index::RepositoryIndex.import(create :repository, name: 'Adc/repository', owner: adc) | ||
::Index::RepositoryIndex.import(create :repository, name: 'Bob/AdaRepository', owner: bob) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C: Line is too long. [95/80]
end | ||
|
||
it 'returns the organizational units' do | ||
organizational_units = search_result['entries'].select do |e| | ||
%w(User Organization).include?(e['entry']['__typename']) | ||
end | ||
expect(organizational_units.length).to eq(5) | ||
expect(organizational_units.length).to eq(expected_count_organizational_units) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C: Line is too long. [86/80]
end | ||
|
||
it 'returns the organizational units' do | ||
organizational_units = search_result['entries'].select do |e| | ||
%w(User Organization).include?(e['entry']['__typename']) | ||
end | ||
expect(organizational_units.length).to eq(5) | ||
expect(organizational_units.length).to eq(expected_count_organizational_units) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C: Line is too long. [86/80]
it 'returns the organizational units' do | ||
organizational_units = search_result['entries'].select do |e| | ||
%w(User Organization).include?(e['entry']['__typename']) | ||
end | ||
expect(organizational_units.length).to eq(5) | ||
expect(organizational_units.length).to eq(expected_count_organizational_units) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C: Line is too long. [86/80]
lib/search_resolver.rb
Outdated
)}).entries | ||
end | ||
result = result.flatten | ||
graphQLResult = OpenStruct.new( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W: Useless assignment to variable - graphQLResult
.
C: Use snake_case for variable names.
lib/search_resolver.rb
Outdated
|
||
private | ||
|
||
def allOrganizationalUnits(result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C: Use snake_case for method names.
lib/search_resolver.rb
Outdated
search_result = 0 | ||
result.each do |element| | ||
elem = element._data['_index'] | ||
search_result += 1 if elem == 'user' || elem == 'organization' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C: Avoid comparing a variable with multiple items in a conditional, use Array#include?
instead.
lib/search_resolver.rb
Outdated
|
||
private | ||
|
||
def allRepositories(result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C: Use snake_case for method names.
lib/search_resolver.rb
Outdated
search_result | ||
end | ||
|
||
private |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W: Useless private
access modifier.
::Index::OrganizationIndex.import(create(:organization, display_name: 'Abc_Organization')) | ||
|
||
::Index::RepositoryIndex.import(create(:repository, name: 'Ada/repository', owner: ada)) | ||
::Index::RepositoryIndex.import(create(:repository, name: 'Bob/repository', owner: bob)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C: Line is too long. [92/80]
|
||
::Index::RepositoryIndex.import(create(:repository, name: 'Ada/repository', owner: ada)) | ||
::Index::RepositoryIndex.import(create(:repository, name: 'Bob/repository', owner: bob)) | ||
::Index::RepositoryIndex.import(create(:repository, name: 'Adc/repository', owner: adc)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C: Line is too long. [92/80]
::Index::RepositoryIndex.import(create(:repository, name: 'Ada/repository', owner: ada)) | ||
::Index::RepositoryIndex.import(create(:repository, name: 'Bob/repository', owner: bob)) | ||
::Index::RepositoryIndex.import(create(:repository, name: 'Adc/repository', owner: adc)) | ||
::Index::RepositoryIndex.import(create(:repository, name: 'Bob/AdaRepository', owner: bob)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C: Line is too long. [95/80]
end | ||
|
||
it 'returns the organizational units' do | ||
organizational_units = search_result['entries'].select do |e| | ||
%w(User Organization).include?(e['entry']['__typename']) | ||
end | ||
expect(organizational_units.length).to eq(5) | ||
expect(organizational_units.length).to eq(expected_count_organizational_units) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C: Line is too long. [86/80]
it 'returns the organizational units' do | ||
organizational_units = search_result['entries'].select do |e| | ||
%w(User Organization).include?(e['entry']['__typename']) | ||
end | ||
expect(organizational_units.length).to eq(5) | ||
expect(organizational_units.length).to eq(expected_count_organizational_units) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C: Line is too long. [86/80]
Codecov Report
@@ Coverage Diff @@
## master #459 +/- ##
==========================================
- Coverage 100% 99.99% -0.01%
==========================================
Files 399 399
Lines 10675 10696 +21
==========================================
+ Hits 10675 10695 +20
- Misses 0 1 +1
Continue to review full report at Codecov.
|
lib/search_resolver.rb
Outdated
private | ||
def allOrganizationalUnits(result) | ||
search_result = 0 | ||
result.each do |element| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check out Enumerable#count
lib/search_resolver.rb
Outdated
private | ||
def allRepositories(result) | ||
search_result = 0 | ||
result.each do |element| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check out Enumerable#count
lib/search_resolver.rb
Outdated
::Index::OrganizationIndex::Organization, | ||
::Index::UserIndex::User] | ||
else | ||
indices = categories.map do |category| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check out Enumerable#reduce
:
indices = categories.reduce([]) do |indices, category|
...
when 'repositories'
indices + [::Index::RepositoryIndex::Repository]
...
end
that way you don't need to flatten the array at the end, which might make it faster.
lib/search_resolver.rb
Outdated
end | ||
indices = indices.flatten | ||
end | ||
result = indices.map do |index| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be done using reduce as well, but I think here flatten is fine.
) | ||
end | ||
|
||
def search_index(query, indices) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C: Method has too many lines. [11/10]
lib/search_resolver.rb
Outdated
end | ||
|
||
def create_indices(categories) | ||
if categories.blank? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C: Method has too many lines. [17/10]
lib/search_resolver.rb
Outdated
result.each do |element| | ||
elem = element._data['_index'] | ||
if elem == 'user' || elem == 'organization' | ||
search_result += 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C: Avoid comparing a variable with multiple items in a conditional, use Array#include?
instead.
lib/search_resolver.rb
Outdated
search_result += 1 | ||
end | ||
end | ||
search_result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C: Assignment Branch Condition size for create_entries is too high. [19.1/15]
C: Method has too many lines. [13/10]
lib/search_resolver.rb
Outdated
result.flatten | ||
end | ||
|
||
def create_indices(categories) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C: Method has too many lines. [17/10]
lib/search_resolver.rb
Outdated
search_result = 0 | ||
result.each do |element| | ||
elem = element._data['_index'] | ||
search_result += 1 if elem == 'user' || elem == 'organization' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C: Avoid comparing a variable with multiple items in a conditional, use Array#include?
instead.
lib/search_resolver.rb
Outdated
search_result | ||
end | ||
|
||
def create_entries(result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C: Assignment Branch Condition size for create_entries is too high. [19.1/15]
C: Method has too many lines. [13/10]
require 'ostruct' | ||
|
||
# Returns a search result to the GraphQL API | ||
class SearchResolver |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E: class definition in method body (Using Ruby 2.5 parser; configure using TargetRubyVersion
parameter, under AllCops
)
lib/search_resolver.rb
Outdated
def all_organizational_units(result) | ||
result.count do |element| | ||
elem = element._data['_index'] | ||
<<<<<<< HEAD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E: unexpected token tLSHFT (Using Ruby 2.5 parser; configure using TargetRubyVersion
parameter, under AllCops
)
lib/search_resolver.rb
Outdated
elem = element._data['_index'] | ||
<<<<<<< HEAD | ||
search_result += 1 if elem == 'user' || elem == 'organization' | ||
======= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E: unexpected token tEQQ (Using Ruby 2.5 parser; configure using TargetRubyVersion
parameter, under AllCops
)
lib/search_resolver.rb
Outdated
search_result += 1 if elem == 'user' || elem == 'organization' | ||
======= | ||
elem == 'organization' || elem == 'user' | ||
>>>>>>> Obey review comments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E: unexpected token tRSHFT (Using Ruby 2.5 parser; configure using TargetRubyVersion
parameter, under AllCops
)
lib/search_resolver.rb
Outdated
end | ||
|
||
def all_repositories(result) | ||
<<<<<<< HEAD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E: unexpected token tLSHFT (Using Ruby 2.5 parser; configure using TargetRubyVersion
parameter, under AllCops
)
lib/search_resolver.rb
Outdated
result.each do |element| | ||
elem = element._data['_index'] | ||
search_result += 1 if elem == 'repository' | ||
======= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E: unexpected token tEQQ (Using Ruby 2.5 parser; configure using TargetRubyVersion
parameter, under AllCops
)
lib/search_resolver.rb
Outdated
======= | ||
result.count do |element| | ||
element._data['_index'] == 'repository' | ||
>>>>>>> Obey review comments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E: unexpected token tRSHFT (Using Ruby 2.5 parser; configure using TargetRubyVersion
parameter, under AllCops
)
lib/search_resolver.rb
Outdated
element._data['_index'] == 'repository' | ||
>>>>>>> Obey review comments | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E: unexpected token kEND (Using Ruby 2.5 parser; configure using TargetRubyVersion
parameter, under AllCops
)
) | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E: unexpected token kEND (Using Ruby 2.5 parser; configure using TargetRubyVersion
parameter, under AllCops
)
lib/search_resolver.rb
Outdated
::Index::OrganizationIndex::Organization, | ||
::Index::UserIndex::User] | ||
else | ||
indices = categories.reduce([]) do |indices, category| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
W: Useless assignment to variable - indices
.
W: Shadowing outer local variable - indices
.
lib/search_resolver.rb
Outdated
end | ||
end | ||
|
||
def create_entries(result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C: Assignment Branch Condition size for create_entries is too high. [19.1/15]
C: Method has too many lines. [13/10]
lib/search_resolver.rb
Outdated
end | ||
end | ||
|
||
def reduce_categories(categories) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C: Method has too many lines. [11/10]
lib/search_resolver.rb
Outdated
end.flatten | ||
end | ||
|
||
def create_indices(categories) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
map_categories_to_indices
might be a better name
lib/search_resolver.rb
Outdated
end | ||
end | ||
|
||
def all_organizational_units(result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
organizational_units_count
might be a better name
lib/search_resolver.rb
Outdated
end | ||
end | ||
|
||
def all_repositories(result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
repositories_count
might be a better name
lib/search_resolver.rb
Outdated
end | ||
end | ||
|
||
def create_entries(result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
map_entries_to_models
might be a better name
lib/search_resolver.rb
Outdated
when 'repositories' | ||
indices + [::Index::RepositoryIndex::Repository] | ||
else | ||
indices + [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be replaced by just indices
as concatenating an empty list is a no-op.
lib/search_resolver.rb
Outdated
end | ||
end | ||
|
||
def map_entries_to_models(result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C: Assignment Branch Condition size for map_entries_to_models is too high. [19.1/15]
C: Method has too many lines. [13/10]
Provides a basic search functionality described in #326