Skip to content
Snippets Groups Projects
Commit 5a506996 authored by Jonathan Schoeffling's avatar Jonathan Schoeffling Committed by Michael Chmielewski
Browse files

Add support for searching commit log messages

Include the log messages of recent commits in project-level search
results, providing functionality similar to 'git log --grep'.

Update repository model rspec tests to validate the output of
Repository#commits_with_log_matching.
parent 8c9e1df9
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -208,6 +208,7 @@ v 8.0.0
- Fix references to target project issues in Merge Requests markdown preview and textareas (Francesco Levorato)
- Redirect from incorrectly cased group or project path to correct one (Francesco Levorato)
- Removed API calls from CE to CI
- Include commit logs in project search
 
v 7.14.3
- No changes
Loading
Loading
Loading
Loading
@@ -23,8 +23,8 @@ class SearchController < ApplicationController
 
@search_results =
if @project
unless %w(blobs notes issues merge_requests milestones wiki_blobs).
include?(@scope)
unless %w(blobs notes issues merge_requests milestones wiki_blobs
commits).include?(@scope)
@scope = 'blobs'
end
 
Loading
Loading
Loading
Loading
@@ -87,6 +87,12 @@ class Repository
commits
end
 
def commits_with_log_matching(query)
list = Gitlab::Git::Commit.where(repo: raw_repository, limit: 1000)
list = Commit.decorate(list, @project) if list.present?
list.select! { |c| c.message.match /#{query}/i }
end
def find_branch(name)
branches.find { |branch| branch.name == name }
end
Loading
Loading
Loading
Loading
@@ -11,6 +11,8 @@
= hidden_field_tag :scope, 'merge_requests'
- elsif current_controller?(:wikis)
= hidden_field_tag :scope, 'wiki_blobs'
- elsif current_controller?(:commits)
= hidden_field_tag :scope, 'commits'
- else
= hidden_field_tag :search_code, true
 
Loading
Loading
Loading
Loading
@@ -42,6 +42,13 @@
Wiki
%span.badge
= @search_results.wiki_blobs_count
%li{class: ("active" if @scope == 'commits')}
= link_to search_filter_path(scope: 'commits') do
= icon('history fw')
%span
Commit Logs
%span.badge
= @search_results.commits_count
 
- elsif @show_snippets
%li{class: ("active" if @scope == 'snippet_blobs')}
Loading
Loading
.search-result-row
.commits-row-title
%strong.str-truncated
= link_to commits.title, namespace_project_commit_path(@project.namespace, @project, commits.id), class: "commit_short_id"
.pull-right
= link_to commits.short_id, namespace_project_commit_path(@project.namespace, @project, commits.id), class: "commit_short_id"
.notes_count
- if @note_counts
- note_count = @note_counts.fetch(commits.id, 0)
- else
- notes = commits.notes
- note_count = notes.user.count
- if note_count > 0
%span.light
%i.fa.fa-comments
= note_count
- if commits.description?
.commits-row-description
%pre
= preserve(gfm(escape_once(commits.description)))
.commits-row-info
= commit_author_link(commits, avatar: true, size: 24)
authored
.committed_ago
#{time_ago_with_tooltip(commits.committed_date)} &nbsp;
= link_to_browse_code(@project, commits)
%br
Loading
Loading
@@ -20,6 +20,8 @@ module Gitlab
Kaminari.paginate_array(blobs).page(page).per(per_page)
when 'wiki_blobs'
Kaminari.paginate_array(wiki_blobs).page(page).per(per_page)
when 'commits'
Kaminari.paginate_array(commits).page(page).per(per_page)
else
super
end
Loading
Loading
@@ -27,7 +29,7 @@ module Gitlab
 
def total_count
@total_count ||= issues_count + merge_requests_count + blobs_count +
notes_count + wiki_blobs_count
notes_count + wiki_blobs_count + commits_count
end
 
def blobs_count
Loading
Loading
@@ -42,6 +44,10 @@ module Gitlab
@wiki_blobs_count ||= wiki_blobs.count
end
 
def commits_count
@commits_count ||= commits.count
end
private
 
def blobs
Loading
Loading
@@ -70,6 +76,10 @@ module Gitlab
Note.where(project_id: limit_project_ids).user.search(query).order('updated_at DESC')
end
 
def commits
project.repository.commits_with_log_matching(query)
end
def limit_project_ids
[project.id]
end
Loading
Loading
Loading
Loading
@@ -26,6 +26,17 @@ describe Repository do
it { is_expected.to eq('c1acaa58bbcbc3eafe538cb8274ba387047b69f8') }
end
 
describe :commits_with_log_matching do
subject { repository.commits_with_log_matching('submodule').
map{|k| k.id}
}
it { is_expected.to include('5937ac0a7beb003549fc5fd26fc247adbce4a52e') }
it { is_expected.to include('6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9') }
it { is_expected.to include('cfe32cf61b73a0d5e9f13e774abde7ff789b1660') }
it { is_expected.not_to include('913c66a37b4a45b9769037c55c2d238bd0942d2e') }
end
describe :blob_at do
context 'blank sha' do
subject { repository.blob_at(Gitlab::Git::BLANK_SHA, '.gitignore') }
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment