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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
6355041a
Commit
6355041a
authored
Sep 14, 2016
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backport search_helper changes from EE
parent
eab72755
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
66 additions
and
60 deletions
+66
-60
app/helpers/search_helper.rb
app/helpers/search_helper.rb
+31
-0
app/models/repository.rb
app/models/repository.rb
+1
-32
app/views/search/results/_blob.html.haml
app/views/search/results/_blob.html.haml
+1
-1
app/views/search/results/_wiki_blob.html.haml
app/views/search/results/_wiki_blob.html.haml
+1
-1
spec/helpers/search_helper_spec.rb
spec/helpers/search_helper_spec.rb
+32
-0
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+0
-26
No files found.
app/helpers/search_helper.rb
View file @
6355041a
...
@@ -30,6 +30,37 @@ module SearchHelper
...
@@ -30,6 +30,37 @@ module SearchHelper
"Showing
#{
from
}
-
#{
to
}
of
#{
count
}
#{
scope
.
humanize
(
capitalize:
false
)
}
for
\"
#{
term
}
\"
"
"Showing
#{
from
}
-
#{
to
}
of
#{
count
}
#{
scope
.
humanize
(
capitalize:
false
)
}
for
\"
#{
term
}
\"
"
end
end
def
parse_search_result
(
result
)
ref
=
nil
filename
=
nil
basename
=
nil
startline
=
0
result
.
each_line
.
each_with_index
do
|
line
,
index
|
if
line
=~
/^.*:.*:\d+:/
ref
,
filename
,
startline
=
line
.
split
(
':'
)
startline
=
startline
.
to_i
-
index
extname
=
Regexp
.
escape
(
File
.
extname
(
filename
))
basename
=
filename
.
sub
(
/
#{
extname
}
$/
,
''
)
break
end
end
data
=
""
result
.
each_line
do
|
line
|
data
<<
line
.
sub
(
ref
,
''
).
sub
(
filename
,
''
).
sub
(
/^:-\d+-/
,
''
).
sub
(
/^::\d+:/
,
''
)
end
OpenStruct
.
new
(
filename:
filename
,
basename:
basename
,
ref:
ref
,
startline:
startline
,
data:
data
)
end
private
private
# Autocomplete results for various settings pages
# Autocomplete results for various settings pages
...
...
app/models/repository.rb
View file @
6355041a
...
@@ -990,37 +990,6 @@ class Repository
...
@@ -990,37 +990,6 @@ class Repository
Gitlab
::
Popen
.
popen
(
args
,
path_to_repo
).
first
.
scrub
.
split
(
/^--$/
)
Gitlab
::
Popen
.
popen
(
args
,
path_to_repo
).
first
.
scrub
.
split
(
/^--$/
)
end
end
def
parse_search_result
(
result
)
ref
=
nil
filename
=
nil
basename
=
nil
startline
=
0
result
.
each_line
.
each_with_index
do
|
line
,
index
|
if
line
=~
/^.*:.*:\d+:/
ref
,
filename
,
startline
=
line
.
split
(
':'
)
startline
=
startline
.
to_i
-
index
extname
=
Regexp
.
escape
(
File
.
extname
(
filename
))
basename
=
filename
.
sub
(
/
#{
extname
}
$/
,
''
)
break
end
end
data
=
""
result
.
each_line
do
|
line
|
data
<<
line
.
sub
(
ref
,
''
).
sub
(
filename
,
''
).
sub
(
/^:-\d+-/
,
''
).
sub
(
/^::\d+:/
,
''
)
end
OpenStruct
.
new
(
filename:
filename
,
basename:
basename
,
ref:
ref
,
startline:
startline
,
data:
data
)
end
def
fetch_ref
(
source_path
,
source_ref
,
target_ref
)
def
fetch_ref
(
source_path
,
source_ref
,
target_ref
)
args
=
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
fetch --no-tags -f
#{
source_path
}
#{
source_ref
}
:
#{
target_ref
}
)
args
=
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
fetch --no-tags -f
#{
source_path
}
#{
source_ref
}
:
#{
target_ref
}
)
Gitlab
::
Popen
.
popen
(
args
,
path_to_repo
)
Gitlab
::
Popen
.
popen
(
args
,
path_to_repo
)
...
@@ -1048,7 +1017,7 @@ class Repository
...
@@ -1048,7 +1017,7 @@ class Repository
GitHooksService
.
new
.
execute
(
current_user
,
path_to_repo
,
oldrev
,
newrev
,
ref
)
do
GitHooksService
.
new
.
execute
(
current_user
,
path_to_repo
,
oldrev
,
newrev
,
ref
)
do
update_ref!
(
ref
,
newrev
,
oldrev
)
update_ref!
(
ref
,
newrev
,
oldrev
)
if
was_empty
||
!
target_branch
if
was_empty
||
!
target_branch
# If repo was empty expire cache
# If repo was empty expire cache
after_create
if
was_empty
after_create
if
was_empty
...
...
app/views/search/results/_blob.html.haml
View file @
6355041a
-
blob
=
@project
.
repository
.
parse_search_result
(
blob
)
-
blob
=
parse_search_result
(
blob
)
.blob-result
.blob-result
.file-holder
.file-holder
.file-title
.file-title
...
...
app/views/search/results/_wiki_blob.html.haml
View file @
6355041a
-
wiki_blob
=
@project
.
repository
.
parse_search_result
(
wiki_blob
)
-
wiki_blob
=
parse_search_result
(
wiki_blob
)
.blob-result
.blob-result
.file-holder
.file-holder
.file-title
.file-title
...
...
spec/helpers/search_helper_spec.rb
View file @
6355041a
...
@@ -6,6 +6,38 @@ describe SearchHelper do
...
@@ -6,6 +6,38 @@ describe SearchHelper do
str
str
end
end
describe
'parsing result'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:repository
)
{
project
.
repository
}
let
(
:results
)
{
repository
.
search_files
(
'feature'
,
'master'
)
}
let
(
:search_result
)
{
results
.
first
}
subject
{
helper
.
parse_search_result
(
search_result
)
}
it
"returns a valid OpenStruct object"
do
is_expected
.
to
be_an
OpenStruct
expect
(
subject
.
filename
).
to
eq
(
'CHANGELOG'
)
expect
(
subject
.
basename
).
to
eq
(
'CHANGELOG'
)
expect
(
subject
.
ref
).
to
eq
(
'master'
)
expect
(
subject
.
startline
).
to
eq
(
186
)
expect
(
subject
.
data
.
lines
[
2
]).
to
eq
(
" - Feature: Replace teams with group membership
\n
"
)
end
context
"when filename has extension"
do
let
(
:search_result
)
{
"master:CONTRIBUTE.md:5:- [Contribute to GitLab](#contribute-to-gitlab)
\n
"
}
it
{
expect
(
subject
.
filename
).
to
eq
(
'CONTRIBUTE.md'
)
}
it
{
expect
(
subject
.
basename
).
to
eq
(
'CONTRIBUTE'
)
}
end
context
"when file under directory"
do
let
(
:search_result
)
{
"master:a/b/c.md:5:a b c
\n
"
}
it
{
expect
(
subject
.
filename
).
to
eq
(
'a/b/c.md'
)
}
it
{
expect
(
subject
.
basename
).
to
eq
(
'a/b/c'
)
}
end
end
describe
'search_autocomplete_source'
do
describe
'search_autocomplete_source'
do
context
"with no current user"
do
context
"with no current user"
do
before
do
before
do
...
...
spec/models/repository_spec.rb
View file @
6355041a
...
@@ -186,32 +186,6 @@ describe Repository, models: true do
...
@@ -186,32 +186,6 @@ describe Repository, models: true do
it
{
is_expected
.
to
be_an
String
}
it
{
is_expected
.
to
be_an
String
}
it
{
expect
(
subject
.
lines
[
2
]).
to
eq
(
"master:CHANGELOG:188: - Feature: Replace teams with group membership
\n
"
)
}
it
{
expect
(
subject
.
lines
[
2
]).
to
eq
(
"master:CHANGELOG:188: - Feature: Replace teams with group membership
\n
"
)
}
end
end
describe
'parsing result'
do
subject
{
repository
.
parse_search_result
(
search_result
)
}
let
(
:search_result
)
{
results
.
first
}
it
{
is_expected
.
to
be_an
OpenStruct
}
it
{
expect
(
subject
.
filename
).
to
eq
(
'CHANGELOG'
)
}
it
{
expect
(
subject
.
basename
).
to
eq
(
'CHANGELOG'
)
}
it
{
expect
(
subject
.
ref
).
to
eq
(
'master'
)
}
it
{
expect
(
subject
.
startline
).
to
eq
(
186
)
}
it
{
expect
(
subject
.
data
.
lines
[
2
]).
to
eq
(
" - Feature: Replace teams with group membership
\n
"
)
}
context
"when filename has extension"
do
let
(
:search_result
)
{
"master:CONTRIBUTE.md:5:- [Contribute to GitLab](#contribute-to-gitlab)
\n
"
}
it
{
expect
(
subject
.
filename
).
to
eq
(
'CONTRIBUTE.md'
)
}
it
{
expect
(
subject
.
basename
).
to
eq
(
'CONTRIBUTE'
)
}
end
context
"when file under directory"
do
let
(
:search_result
)
{
"master:a/b/c.md:5:a b c
\n
"
}
it
{
expect
(
subject
.
filename
).
to
eq
(
'a/b/c.md'
)
}
it
{
expect
(
subject
.
basename
).
to
eq
(
'a/b/c'
)
}
end
end
end
end
describe
"#changelog"
do
describe
"#changelog"
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