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
Tatuya Kamada
gitlab-ce
Commits
99404a58
Commit
99404a58
authored
Jan 11, 2017
by
YarNayar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Search feature: redirects to commit page if query is commit sha and only commit found
See !8028 and #24833
parent
dd3ddcd7
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
57 additions
and
1 deletion
+57
-1
app/controllers/search_controller.rb
app/controllers/search_controller.rb
+14
-0
changelogs/unreleased/redirect-to-commit-when-only-commit-found.yml
.../unreleased/redirect-to-commit-when-only-commit-found.yml
+5
-0
lib/gitlab/project_search_results.rb
lib/gitlab/project_search_results.rb
+9
-1
lib/gitlab/search_results.rb
lib/gitlab/search_results.rb
+4
-0
spec/features/search_spec.rb
spec/features/search_spec.rb
+25
-0
No files found.
app/controllers/search_controller.rb
View file @
99404a58
...
@@ -45,6 +45,8 @@ class SearchController < ApplicationController
...
@@ -45,6 +45,8 @@ class SearchController < ApplicationController
end
end
@search_objects
=
@search_results
.
objects
(
@scope
,
params
[
:page
])
@search_objects
=
@search_results
.
objects
(
@scope
,
params
[
:page
])
check_single_commit_result
end
end
def
autocomplete
def
autocomplete
...
@@ -59,4 +61,16 @@ class SearchController < ApplicationController
...
@@ -59,4 +61,16 @@ class SearchController < ApplicationController
render
json:
search_autocomplete_opts
(
term
).
to_json
render
json:
search_autocomplete_opts
(
term
).
to_json
end
end
private
def
check_single_commit_result
if
@search_results
.
single_commit_result?
only_commit
=
@search_results
.
objects
(
'commits'
).
first
query
=
params
[
:search
].
strip
.
downcase
found_by_commit_sha
=
Commit
.
valid_hash?
(
query
)
&&
only_commit
.
sha
.
start_with?
(
query
)
redirect_to
namespace_project_commit_path
(
@project
.
namespace
,
@project
,
only_commit
)
if
found_by_commit_sha
end
end
end
end
changelogs/unreleased/redirect-to-commit-when-only-commit-found.yml
0 → 100644
View file @
99404a58
---
title
:
'
Search
feature:
redirects
to
commit
page
if
query
is
commit
sha
and
only
commit
found'
merge_request
:
8028
author
:
YarNayar
lib/gitlab/project_search_results.rb
View file @
99404a58
...
@@ -71,6 +71,14 @@ module Gitlab
...
@@ -71,6 +71,14 @@ module Gitlab
)
)
end
end
def
single_commit_result?
commits_count
==
1
&&
total_result_count
==
1
end
def
total_result_count
issues_count
+
merge_requests_count
+
milestones_count
+
notes_count
+
blobs_count
+
wiki_blobs_count
+
commits_count
end
private
private
def
blobs
def
blobs
...
@@ -122,7 +130,7 @@ module Gitlab
...
@@ -122,7 +130,7 @@ module Gitlab
commits
=
find_commits_by_message
(
query
)
commits
=
find_commits_by_message
(
query
)
commit_by_sha
=
find_commit_by_sha
(
query
)
commit_by_sha
=
find_commit_by_sha
(
query
)
commits
<<
commit_by_sha
if
commit_by_sha
&&
!
commits
.
include?
(
commit_by_sha
)
commits
|=
[
commit_by_sha
]
if
commit_by_sha
commits
commits
end
end
...
...
lib/gitlab/search_results.rb
View file @
99404a58
...
@@ -43,6 +43,10 @@ module Gitlab
...
@@ -43,6 +43,10 @@ module Gitlab
@milestones_count
||=
milestones
.
count
@milestones_count
||=
milestones
.
count
end
end
def
single_commit_result?
false
end
private
private
def
projects
def
projects
...
...
spec/features/search_spec.rb
View file @
99404a58
...
@@ -217,6 +217,31 @@ describe "Search", feature: true do
...
@@ -217,6 +217,31 @@ describe "Search", feature: true do
visit
search_path
(
project_id:
project
.
id
)
visit
search_path
(
project_id:
project
.
id
)
end
end
it
'redirects to commit page when search by sha and only commit found'
do
fill_in
'search'
,
with:
'6d394385cf567f80a8fd85055db1ab4c5295806f'
click_button
'Search'
expect
(
page
).
to
have_current_path
(
namespace_project_commit_path
(
project
.
namespace
,
project
,
'6d394385cf567f80a8fd85055db1ab4c5295806f'
))
end
it
'redirects to single commit regardless of query case'
do
fill_in
'search'
,
with:
'6D394385cf'
click_button
'Search'
expect
(
page
).
to
have_current_path
(
namespace_project_commit_path
(
project
.
namespace
,
project
,
'6d394385cf567f80a8fd85055db1ab4c5295806f'
))
end
it
'holds on /search page when the only commit is found by message'
do
create_commit
(
'Message referencing another sha: "deadbeef" '
,
project
,
user
,
'master'
)
fill_in
'search'
,
with:
'deadbeef'
click_button
'Search'
expect
(
page
).
to
have_current_path
(
'/search'
,
only_path:
true
)
end
it
'shows multiple matching commits'
do
it
'shows multiple matching commits'
do
fill_in
'search'
,
with:
'See merge request'
fill_in
'search'
,
with:
'See merge request'
...
...
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