diff options
author | YarNayar <YarTheGreat@gmail.com> | 2016-12-08 17:54:45 +0300 |
---|---|---|
committer | YarNayar <YarTheGreat@gmail.com> | 2017-01-24 14:56:00 +0300 |
commit | dd3ddcd72bbfec3ba5bbcd871a9ac68064be7501 (patch) | |
tree | c8af4e24a8d87e788e601057c325907b6580ffac /lib | |
parent | f1568d71f073165c86668bd09c1d228cbb6d474b (diff) |
Allows to search within project by commit's hash
Was proposed in #24833
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/project_search_results.rb | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/gitlab/project_search_results.rb b/lib/gitlab/project_search_results.rb index 6bdf3db9cb8..a66719706be 100644 --- a/lib/gitlab/project_search_results.rb +++ b/lib/gitlab/project_search_results.rb @@ -114,7 +114,25 @@ module Gitlab end def commits - @commits ||= project.repository.find_commits_by_message(query) + @commits ||= find_commits(query) + end + + def find_commits(query) + return [] unless Ability.allowed?(@current_user, :download_code, @project) + + commits = find_commits_by_message(query) + commit_by_sha = find_commit_by_sha(query) + commits << commit_by_sha if commit_by_sha && !commits.include?(commit_by_sha) + commits + end + + def find_commits_by_message(query) + project.repository.find_commits_by_message(query) + end + + def find_commit_by_sha(query) + key = query.strip + project.repository.commit(key) if Commit.valid_hash?(key) end def project_ids_relation |