Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
6354d554
Commit
6354d554
authored
Jul 20, 2018
by
Francisco Javier López
Committed by
Sean McGivern
Jul 20, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing bug with wiki ref in ProjectSearchResults
parent
1484ed41
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
7 deletions
+70
-7
changelogs/unreleased/fj-49014-wiki-search-error.yml
changelogs/unreleased/fj-49014-wiki-search-error.yml
+5
-0
lib/gitlab/project_search_results.rb
lib/gitlab/project_search_results.rb
+12
-7
spec/lib/gitlab/project_search_results_spec.rb
spec/lib/gitlab/project_search_results_spec.rb
+53
-0
No files found.
changelogs/unreleased/fj-49014-wiki-search-error.yml
0 → 100644
View file @
6354d554
---
title
:
Fixed bug with invalid repository reference using the wiki search
merge_request
:
20722
author
:
type
:
fixed
lib/gitlab/project_search_results.rb
View file @
6354d554
...
@@ -5,7 +5,7 @@ module Gitlab
...
@@ -5,7 +5,7 @@ module Gitlab
def
initialize
(
current_user
,
project
,
query
,
repository_ref
=
nil
,
per_page:
20
)
def
initialize
(
current_user
,
project
,
query
,
repository_ref
=
nil
,
per_page:
20
)
@current_user
=
current_user
@current_user
=
current_user
@project
=
project
@project
=
project
@repository_ref
=
repository_ref
.
presence
||
project
.
default_branch
@repository_ref
=
repository_ref
.
presence
@query
=
query
@query
=
query
@per_page
=
per_page
@per_page
=
per_page
end
end
...
@@ -95,7 +95,7 @@ module Gitlab
...
@@ -95,7 +95,7 @@ module Gitlab
def
blobs
def
blobs
return
[]
unless
Ability
.
allowed?
(
@current_user
,
:download_code
,
@project
)
return
[]
unless
Ability
.
allowed?
(
@current_user
,
:download_code
,
@project
)
@blobs
||=
Gitlab
::
FileFinder
.
new
(
project
,
repository_ref
).
find
(
query
)
@blobs
||=
Gitlab
::
FileFinder
.
new
(
project
,
repository_
project_
ref
).
find
(
query
)
end
end
def
wiki_blobs
def
wiki_blobs
...
@@ -103,11 +103,8 @@ module Gitlab
...
@@ -103,11 +103,8 @@ module Gitlab
@wiki_blobs
||=
begin
@wiki_blobs
||=
begin
if
project
.
wiki_enabled?
&&
query
.
present?
if
project
.
wiki_enabled?
&&
query
.
present?
project_wiki
=
ProjectWiki
.
new
(
project
)
unless
project
.
wiki
.
empty?
Gitlab
::
WikiFileFinder
.
new
(
project
,
repository_wiki_ref
).
find
(
query
)
unless
project_wiki
.
empty?
ref
=
repository_ref
||
project
.
wiki
.
default_branch
Gitlab
::
WikiFileFinder
.
new
(
project
,
ref
).
find
(
query
)
else
else
[]
[]
end
end
...
@@ -150,5 +147,13 @@ module Gitlab
...
@@ -150,5 +147,13 @@ module Gitlab
def
project_ids_relation
def
project_ids_relation
project
project
end
end
def
repository_project_ref
@repository_project_ref
||=
repository_ref
||
project
.
default_branch
end
def
repository_wiki_ref
@repository_wiki_ref
||=
repository_ref
||
project
.
wiki
.
default_branch
end
end
end
end
end
spec/lib/gitlab/project_search_results_spec.rb
View file @
6354d554
...
@@ -64,6 +64,49 @@ describe Gitlab::ProjectSearchResults do
...
@@ -64,6 +64,49 @@ describe Gitlab::ProjectSearchResults do
end
end
end
end
shared_examples
'blob search repository ref'
do
|
entity_type
|
let
(
:query
)
{
'files'
}
let
(
:file_finder
)
{
double
}
let
(
:project_branch
)
{
'project_branch'
}
subject
(
:results
)
{
described_class
.
new
(
user
,
project
,
query
,
repository_ref
).
objects
(
blob_type
)
}
before
do
allow
(
entity
).
to
receive
(
:default_branch
).
and_return
(
project_branch
)
allow
(
file_finder
).
to
receive
(
:find
).
and_return
([])
end
context
'when repository_ref exists'
do
let
(
:repository_ref
)
{
'ref_branch'
}
it
'uses it'
do
expect
(
Gitlab
::
FileFinder
).
to
receive
(
:new
).
with
(
project
,
repository_ref
).
and_return
(
file_finder
)
results
end
end
context
'when repository_ref is not present'
do
let
(
:repository_ref
)
{
nil
}
it
"uses
#{
entity_type
}
repository default reference"
do
expect
(
Gitlab
::
FileFinder
).
to
receive
(
:new
).
with
(
project
,
project_branch
).
and_return
(
file_finder
)
results
end
end
context
'when repository_ref is blank'
do
let
(
:repository_ref
)
{
''
}
it
"uses
#{
entity_type
}
repository default reference"
do
expect
(
Gitlab
::
FileFinder
).
to
receive
(
:new
).
with
(
project
,
project_branch
).
and_return
(
file_finder
)
results
end
end
end
describe
'blob search'
do
describe
'blob search'
do
let
(
:project
)
{
create
(
:project
,
:public
,
:repository
)
}
let
(
:project
)
{
create
(
:project
,
:public
,
:repository
)
}
...
@@ -75,6 +118,11 @@ describe Gitlab::ProjectSearchResults do
...
@@ -75,6 +118,11 @@ describe Gitlab::ProjectSearchResults do
let
(
:expected_file_by_content
)
{
'CHANGELOG'
}
let
(
:expected_file_by_content
)
{
'CHANGELOG'
}
end
end
it_behaves_like
'blob search repository ref'
,
'project'
do
let
(
:blob_type
)
{
'blobs'
}
let
(
:entity
)
{
project
}
end
describe
'parsing results'
do
describe
'parsing results'
do
let
(
:results
)
{
project
.
repository
.
search_files_by_content
(
'feature'
,
'master'
)
}
let
(
:results
)
{
project
.
repository
.
search_files_by_content
(
'feature'
,
'master'
)
}
let
(
:search_result
)
{
results
.
first
}
let
(
:search_result
)
{
results
.
first
}
...
@@ -212,6 +260,11 @@ describe Gitlab::ProjectSearchResults do
...
@@ -212,6 +260,11 @@ describe Gitlab::ProjectSearchResults do
let
(
:expected_file_by_name
)
{
'Files/Title.md'
}
let
(
:expected_file_by_name
)
{
'Files/Title.md'
}
let
(
:expected_file_by_content
)
{
'CHANGELOG.md'
}
let
(
:expected_file_by_content
)
{
'CHANGELOG.md'
}
end
end
it_behaves_like
'blob search repository ref'
,
'wiki'
do
let
(
:blob_type
)
{
'wiki_blobs'
}
let
(
:entity
)
{
project
.
wiki
}
end
end
end
it
'does not list issues on private projects'
do
it
'does not list issues on private projects'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment