diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-01-24 16:48:33 +0300 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2017-01-24 16:48:33 +0300 |
commit | 65bf7e0d92856d90215ca908751e676393c10618 (patch) | |
tree | febf109d5461c13b856d7a8e3c51cdd2fa1beb18 /lib | |
parent | a89aab9c630593524b8a210746d2eb680ac5d102 (diff) | |
parent | 99404a5851a4b8bbba8a5786d7351f2d4b024092 (diff) |
Merge branch '24833-Allow-to-search-by-commit-hash-within-project' into 'master'
Allows to search within project by commit's hash #24833
Closes #24833
See merge request !8028
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/project_search_results.rb | 28 | ||||
-rw-r--r-- | lib/gitlab/search_results.rb | 4 |
2 files changed, 31 insertions, 1 deletions
diff --git a/lib/gitlab/project_search_results.rb b/lib/gitlab/project_search_results.rb index 6bdf3db9cb8..db325c00705 100644 --- a/lib/gitlab/project_search_results.rb +++ b/lib/gitlab/project_search_results.rb @@ -71,6 +71,14 @@ module Gitlab ) 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 def blobs @@ -114,7 +122,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 + 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 diff --git a/lib/gitlab/search_results.rb b/lib/gitlab/search_results.rb index 35212992698..c9c65f76f4b 100644 --- a/lib/gitlab/search_results.rb +++ b/lib/gitlab/search_results.rb @@ -43,6 +43,10 @@ module Gitlab @milestones_count ||= milestones.count end + def single_commit_result? + false + end + private def projects |