Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYarNayar <YarTheGreat@gmail.com>2017-01-11 07:20:32 +0300
committerYarNayar <YarTheGreat@gmail.com>2017-01-24 14:58:00 +0300
commit99404a5851a4b8bbba8a5786d7351f2d4b024092 (patch)
treeb79389d46bd60d1ba9c7ca0c87fa76e0061700c2 /app/controllers/search_controller.rb
parentdd3ddcd72bbfec3ba5bbcd871a9ac68064be7501 (diff)
Search feature: redirects to commit page if query is commit sha and only commit found
See !8028 and #24833
Diffstat (limited to 'app/controllers/search_controller.rb')
-rw-r--r--app/controllers/search_controller.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb
index b666aa01d6b..6576ebd5235 100644
--- a/app/controllers/search_controller.rb
+++ b/app/controllers/search_controller.rb
@@ -45,6 +45,8 @@ class SearchController < ApplicationController
end
@search_objects = @search_results.objects(@scope, params[:page])
+
+ check_single_commit_result
end
def autocomplete
@@ -59,4 +61,16 @@ class SearchController < ApplicationController
render json: search_autocomplete_opts(term).to_json
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