diff --git a/GITLAB_ELASTICSEARCH_INDEXER_VERSION b/GITLAB_ELASTICSEARCH_INDEXER_VERSION index 88c5fb891dcf1d1647d2b84bac0630cf9570d213..bc80560fad66ca670bdfbd1e5c973a024d4d0325 100644 --- a/GITLAB_ELASTICSEARCH_INDEXER_VERSION +++ b/GITLAB_ELASTICSEARCH_INDEXER_VERSION @@ -1 +1 @@ -1.4.0 +1.5.0 diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 9a19758b4e8bdce124d4373a891f79bf26db7283..978d0a8c8fbc08de62ba42483b295a03ab5eb1c0 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -96,8 +96,9 @@ def parse_search_result(result) result end - def search_blob_title(project, filename) - filename + # Overriden in EE + def search_blob_title(project, path) + path end def search_service diff --git a/app/views/search/results/_blob.html.haml b/app/views/search/results/_blob.html.haml index bdad07f36d1208a726ee2ff8ed51f92a565441ff..4fb72b26955508d08ce59fe3be623c6480ca757e 100644 --- a/app/views/search/results/_blob.html.haml +++ b/app/views/search/results/_blob.html.haml @@ -2,6 +2,6 @@ - return unless project - blob = parse_search_result(blob) -- blob_link = project_blob_path(project, tree_join(blob.ref, blob.filename)) +- blob_link = project_blob_path(project, tree_join(blob.ref, blob.path)) -= render partial: 'search/results/blob_data', locals: { blob: blob, project: project, file_name: blob.filename, blob_link: blob_link } += render partial: 'search/results/blob_data', locals: { blob: blob, project: project, path: blob.path, blob_link: blob_link } diff --git a/app/views/search/results/_blob_data.html.haml b/app/views/search/results/_blob_data.html.haml index 36b6ea7bd37c103087b8b4e42bbb10db779b7dc8..01e42224428f32284de9084af57db805be2cc7fd 100644 --- a/app/views/search/results/_blob_data.html.haml +++ b/app/views/search/results/_blob_data.html.haml @@ -4,7 +4,7 @@ = link_to blob_link do %i.fa.fa-file %strong - = search_blob_title(project, file_name) + = search_blob_title(project, path) - if blob.data .file-content.code.term{ data: { qa_selector: 'file_text_content' } } = render 'shared/file_highlight', blob: blob, first_line_number: blob.startline diff --git a/app/views/search/results/_wiki_blob.html.haml b/app/views/search/results/_wiki_blob.html.haml index b351ecd4edf3fbc868159f0f960b34131491dd81..9afed2bbecc2dd86493032c060d1617c56447020 100644 --- a/app/views/search/results/_wiki_blob.html.haml +++ b/app/views/search/results/_wiki_blob.html.haml @@ -2,4 +2,4 @@ - wiki_blob = parse_search_result(wiki_blob) - wiki_blob_link = project_wiki_path(project, wiki_blob.basename) -= render partial: 'search/results/blob_data', locals: { blob: wiki_blob, project: project, file_name: wiki_blob.filename, blob_link: wiki_blob_link } += render partial: 'search/results/blob_data', locals: { blob: wiki_blob, project: project, path: wiki_blob.path, blob_link: wiki_blob_link } diff --git a/doc/api/search.md b/doc/api/search.md index ca08f5ca0d755f517c2407f335c217db099a5d24..f9bd514301828e83c7e0e335be53d938bbd0dabf 100644 --- a/doc/api/search.md +++ b/doc/api/search.md @@ -299,6 +299,7 @@ Example response: { "basename": "home", "data": "hello\n\nand bye\n\nend", + "path": "home.md", "filename": "home.md", "id": null, "ref": "master", @@ -308,6 +309,8 @@ Example response: ] ``` +**Note:** `filename` is deprecated in favor of `path`. Both return the full path of the file inside the repository, but in the future `filename` will be only the file name and not the full path (see [this issue][gitlab-34521]). + ### Scope: commits **(STARTER)** This scope is available only if [Elasticsearch](../integration/elasticsearch.md) is enabled. @@ -367,6 +370,7 @@ Example response: { "basename": "README", "data": "```\n\n## Installation\n\nQuick start using the [pre-built", + "path": "README.md", "filename": "README.md", "id": null, "ref": "master", @@ -376,6 +380,8 @@ Example response: ] ``` +**Note:** `filename` is deprecated in favor of `path`. Both return the full path of the file inside the repository, but in the future `filename` will be only the file name and not the full path (see [this issue][gitlab-34521]). + ### Scope: users ```bash @@ -633,6 +639,7 @@ Example response: { "basename": "home", "data": "hello\n\nand bye\n\nend", + "path": "home.md", "filename": "home.md", "id": null, "ref": "master", @@ -642,6 +649,8 @@ Example response: ] ``` +**Note:** `filename` is deprecated in favor of `path`. Both return the full path of the file inside the repository, but in the future `filename` will be only the file name and not the full path (see [this issue][gitlab-34521]). + ### Scope: commits **(STARTER)** This scope is available only if [Elasticsearch](../integration/elasticsearch.md) is enabled. @@ -701,6 +710,7 @@ Example response: { "basename": "README", "data": "```\n\n## Installation\n\nQuick start using the [pre-built", + "path": "README.md", "filename": "README.md", "id": null, "ref": "master", @@ -710,6 +720,8 @@ Example response: ] ``` +**Note:** `filename` is deprecated in favor of `path`. Both return the full path of the file inside the repository, but in the future `filename` will be only the file name and not the full path (see [this issue][gitlab-34521]). + ### Scope: users ```bash @@ -981,6 +993,7 @@ Example response: { "basename": "home", "data": "hello\n\nand bye\n\nend", + "path": "home.md", "filename": "home.md", "id": null, "ref": "master", @@ -990,6 +1003,8 @@ Example response: ] ``` +**Note:** `filename` is deprecated in favor of `path`. Both return the full path of the file inside the repository, but in the future `filename` will be only the file name and not the full path (see [this issue][gitlab-34521]). + ### Scope: commits ```bash @@ -1051,6 +1066,7 @@ Example response: { "basename": "README", "data": "```\n\n## Installation\n\nQuick start using the [pre-built", + "path": "README.md", "filename": "README.md", "id": null, "ref": "master", @@ -1060,6 +1076,8 @@ Example response: ] ``` +**Note:** `filename` is deprecated in favor of `path`. Both return the full path of the file inside the repository, but in the future `filename` will be only the file name and not the full path (see [this issue][gitlab-34521]). + ### Scope: users ```bash @@ -1082,3 +1100,4 @@ Example response: ``` [ce-41763]: https://gitlab.com/gitlab-org/gitlab-foss/issues/41763 +[gitlab-34521]: https://gitlab.com/gitlab-org/gitlab/issues/34521 diff --git a/ee/app/helpers/ee/search_helper.rb b/ee/app/helpers/ee/search_helper.rb index e21b872aa9af17abf12ec44019891a8d16d0af43..115fa9e19e81554b9e698edaead7e6dd56473439 100644 --- a/ee/app/helpers/ee/search_helper.rb +++ b/ee/app/helpers/ee/search_helper.rb @@ -35,11 +35,11 @@ def parse_search_result(result) end override :search_blob_title - def search_blob_title(project, file_name) + def search_blob_title(project, path) if @project - file_name + path else - (project.full_name + ': ' + content_tag(:i, file_name)).html_safe + (project.full_name + ': ' + content_tag(:i, path)).html_safe end end diff --git a/ee/changelogs/unreleased/7832-only-store-basename-in-filename.yml b/ee/changelogs/unreleased/7832-only-store-basename-in-filename.yml new file mode 100644 index 0000000000000000000000000000000000000000..1544f08ecbdf34be2ee7c3d2a0c398ed1caff413 --- /dev/null +++ b/ee/changelogs/unreleased/7832-only-store-basename-in-filename.yml @@ -0,0 +1,5 @@ +--- +title: Don't store full blob path in ES filename field +merge_request: 18470 +author: +type: fixed diff --git a/ee/lib/elasticsearch/git/lite_blob.rb b/ee/lib/elasticsearch/git/lite_blob.rb deleted file mode 100644 index 543455d65d8231d108e79bd20d5f4da196f12165..0000000000000000000000000000000000000000 --- a/ee/lib/elasticsearch/git/lite_blob.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -module Elasticsearch - module Git - class LiteBlob - include ::Gitlab::BlobHelper - include Elasticsearch::Git::EncoderHelper - - attr_accessor :id, :name, :path, :size, :mode, :commit_id - attr_writer :data - - def initialize(repo, raw_blob_hash) - @id = raw_blob_hash[:oid] - @blob = repo.lookup(@id) - - @mode = (raw_blob_hash[:mode] || raw_blob_hash[:filemode]).to_s(8) - @size = @blob.size - @path = encode!(raw_blob_hash[:path]) - @name = @path.split('/').last - end - - def data - @data ||= encode!(@blob.content) - end - end - end -end diff --git a/ee/lib/gitlab/elastic/search_results.rb b/ee/lib/gitlab/elastic/search_results.rb index fe3ba2b8d6f3b9b41b704021b39f2089d6c0192f..e69693a5d8174193b7a0b3005fd574c64a92da3c 100644 --- a/ee/lib/gitlab/elastic/search_results.rb +++ b/ee/lib/gitlab/elastic/search_results.rb @@ -114,9 +114,9 @@ def single_commit_result? def self.parse_search_result(result) ref = result["_source"]["blob"]["commit_sha"] - filename = result["_source"]["blob"]["path"] - extname = File.extname(filename) - basename = filename.sub(/#{extname}$/, '') + path = result["_source"]["blob"]["path"] + extname = File.extname(path) + basename = path.sub(/#{extname}$/, '') content = result["_source"]["blob"]["content"] project_id = result['_source']['project_id'].to_i total_lines = content.lines.size @@ -151,7 +151,7 @@ def self.parse_search_result(result) data = content.lines[from..to] ::Gitlab::Search::FoundBlob.new( - filename: filename, + path: path, basename: basename, ref: ref, startline: from + 1, diff --git a/ee/spec/helpers/search_helper_spec.rb b/ee/spec/helpers/search_helper_spec.rb index ee6126dc74b9c7aab5add98d1e972aa26fac1899..a401438ce0f23c3d6c929cec0b67b6b3109f995c 100644 --- a/ee/spec/helpers/search_helper_spec.rb +++ b/ee/spec/helpers/search_helper_spec.rb @@ -74,7 +74,7 @@ parsed_result = helper.parse_search_result(result) expect(parsed_result.ref). to eq('b83d6e391c22777fca1ed3012fce84f633d7fed0') - expect(parsed_result.filename).to eq('files/ruby/popen.rb') + expect(parsed_result.path).to eq('files/ruby/popen.rb') expect(parsed_result.startline).to eq(2) expect(parsed_result.data).to include("Popen") end diff --git a/ee/spec/lib/gitlab/elastic/search_results_spec.rb b/ee/spec/lib/gitlab/elastic/search_results_spec.rb index 3428b7bc2ec6260fbd0b014c823b4c93d227143d..8973938e0d96407c056295494efb9c8ca1fb4f7c 100644 --- a/ee/spec/lib/gitlab/elastic/search_results_spec.rb +++ b/ee/spec/lib/gitlab/elastic/search_results_spec.rb @@ -100,7 +100,7 @@ expect(parsed).to be_kind_of(::Gitlab::Search::FoundBlob) expect(parsed).to have_attributes( id: nil, - filename: 'path/file.ext', + path: 'path/file.ext', basename: 'path/file', ref: 'sha', startline: 2, diff --git a/ee/spec/models/concerns/elastic/repository_spec.rb b/ee/spec/models/concerns/elastic/repository_spec.rb index b98dd386ba5df433025e645f0cc43785a34dbc2c..fd6d83d07bf1ad1844fe88ce06c53082721161d7 100644 --- a/ee/spec/models/concerns/elastic/repository_spec.rb +++ b/ee/spec/models/concerns/elastic/repository_spec.rb @@ -28,8 +28,16 @@ def index!(project) project = create :project, :repository index!(project) + # Finds custom-highlighting/test.gitlab-custom expect(project.repository.search('def | popen filename:test')[:blobs][:total_count]).to eq(1) + + # Should not find anything, since filename doesn't match on path + expect(project.repository.search('def | popen filename:files')[:blobs][:total_count]).to eq(0) + + # Finds files/ruby/popen.rb, files/markdown/ruby-style-guide.md, files/ruby/regex.rb, files/ruby/version_info.rb expect(project.repository.search('def | popen path:ruby')[:blobs][:total_count]).to eq(4) + + # Finds files/markdown/ruby-style-guide.md expect(project.repository.search('def | popen extension:md')[:blobs][:total_count]).to eq(1) end diff --git a/ee/spec/requests/api/search_spec.rb b/ee/spec/requests/api/search_spec.rb index cfee4bda1ee06bafd3731e80e42666069f4982d3..b9ba27a0e15b7d5c22d0cc10c2c47a0f14dd0f94 100644 --- a/ee/spec/requests/api/search_spec.rb +++ b/ee/spec/requests/api/search_spec.rb @@ -81,7 +81,7 @@ expect(response).to have_gitlab_http_status(200) expect(json_response.size).to eq(1) - expect(json_response.first['filename']).to eq('PROCESS.md') + expect(json_response.first['path']).to eq('PROCESS.md') end it 'by path' do @@ -90,7 +90,7 @@ expect(response).to have_gitlab_http_status(200) expect(json_response.size).to eq(1) json_response.each do |file| - expect(file['filename']).to match(%r[/markdown/]) + expect(file['path']).to match(%r[/markdown/]) end end @@ -100,7 +100,7 @@ expect(response).to have_gitlab_http_status(200) expect(json_response.size).to eq(3) json_response.each do |file| - expect(file['filename']).to match(/\A.+\.md\z/) + expect(file['path']).to match(/\A.+\.md\z/) end end end diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 91811efacd72f79026d6a4c97fc35f4e3713e172..c81cb5bf6643bf0b593b862d5e0bc65639ced0ea 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -1737,7 +1737,12 @@ class ApplicationWithSecret < Application class Blob < Grape::Entity expose :basename expose :data - expose :filename + expose :path + # TODO: :filename was renamed to :path but both still return the full path, + # in the future we can only return the filename here without the leading + # directory path. + # https://gitlab.com/gitlab-org/gitlab/issues/34521 + expose :filename, &:path expose :id expose :ref expose :startline diff --git a/lib/gitlab/file_finder.rb b/lib/gitlab/file_finder.rb index 3958814208c2a7965eb9bff110f44813c247cb15..ec9d2df613bd13270dda2040f2bb815bc6c56c15 100644 --- a/lib/gitlab/file_finder.rb +++ b/lib/gitlab/file_finder.rb @@ -15,12 +15,12 @@ def initialize(project, ref) def find(query) query = Gitlab::Search::Query.new(query, encode_binary: true) do - filter :filename, matcher: ->(filter, blob) { blob.binary_filename =~ /#{filter[:regex_value]}$/i } - filter :path, matcher: ->(filter, blob) { blob.binary_filename =~ /#{filter[:regex_value]}/i } - filter :extension, matcher: ->(filter, blob) { blob.binary_filename =~ /\.#{filter[:regex_value]}$/i } + filter :filename, matcher: ->(filter, blob) { blob.binary_path =~ /#{filter[:regex_value]}$/i } + filter :path, matcher: ->(filter, blob) { blob.binary_path =~ /#{filter[:regex_value]}/i } + filter :extension, matcher: ->(filter, blob) { blob.binary_path =~ /\.#{filter[:regex_value]}$/i } end - files = find_by_filename(query.term) + find_by_content(query.term) + files = find_by_path(query.term) + find_by_content(query.term) files = query.filter_results(files) if query.filters.any? @@ -35,13 +35,14 @@ def find_by_content(query) end end - def find_by_filename(query) - search_filenames(query).map do |filename| - Gitlab::Search::FoundBlob.new(blob_filename: filename, project: project, ref: ref, repository: repository) + def find_by_path(query) + search_paths(query).map do |path| + Gitlab::Search::FoundBlob.new(blob_path: path, project: project, ref: ref, repository: repository) end end - def search_filenames(query) + # Overriden in Gitlab::WikiFileFinder + def search_paths(query) repository.search_files_by_name(query, ref) end end diff --git a/lib/gitlab/search/found_blob.rb b/lib/gitlab/search/found_blob.rb index fa09ecbdf3053266ef87fcfc69b6dd3daae0642f..360239a84e42876dcec39a19ff562be113610636 100644 --- a/lib/gitlab/search/found_blob.rb +++ b/lib/gitlab/search/found_blob.rb @@ -8,20 +8,20 @@ class FoundBlob include BlobLanguageFromGitAttributes include Gitlab::Utils::StrongMemoize - attr_reader :project, :content_match, :blob_filename + attr_reader :project, :content_match, :blob_path - FILENAME_REGEXP = /\A(?[^:]*):(?[^\x00]*)\x00/.freeze - CONTENT_REGEXP = /^(?[^:]*):(?[^\x00]*)\x00(?\d+)\x00/.freeze + PATH_REGEXP = /\A(?[^:]*):(?[^\x00]*)\x00/.freeze + CONTENT_REGEXP = /^(?[^:]*):(?[^\x00]*)\x00(?\d+)\x00/.freeze def self.preload_blobs(blobs) - to_fetch = blobs.select { |blob| blob.is_a?(self) && blob.blob_filename } + to_fetch = blobs.select { |blob| blob.is_a?(self) && blob.blob_path } to_fetch.each { |blob| blob.fetch_blob } end def initialize(opts = {}) @id = opts.fetch(:id, nil) - @binary_filename = opts.fetch(:filename, nil) + @binary_path = opts.fetch(:path, nil) @binary_basename = opts.fetch(:basename, nil) @ref = opts.fetch(:ref, nil) @startline = opts.fetch(:startline, nil) @@ -34,7 +34,7 @@ def initialize(opts = {}) # Allow those to just pass project_id instead. @project_id = opts.fetch(:project_id, nil) @content_match = opts.fetch(:content_match, nil) - @blob_filename = opts.fetch(:blob_filename, nil) + @blob_path = opts.fetch(:blob_path, nil) @repository = opts.fetch(:repository, nil) end @@ -50,16 +50,16 @@ def startline @startline ||= parsed_content[:startline] end - # binary_filename is used for running filters on all matches, - # for grepped results (which use content_match), we get - # filename from the beginning of the grepped result which is faster - # then parsing whole snippet - def binary_filename - @binary_filename ||= content_match ? search_result_filename : parsed_content[:binary_filename] + # binary_path is used for running filters on all matches. + # For grepped results (which use content_match), we get + # the path from the beginning of the grepped result which is faster + # than parsing the whole snippet + def binary_path + @binary_path ||= content_match ? search_result_path : parsed_content[:binary_path] end - def filename - @filename ||= encode_utf8(@binary_filename || parsed_content[:binary_filename]) + def path + @path ||= encode_utf8(@binary_path || parsed_content[:binary_path]) end def basename @@ -70,10 +70,6 @@ def data @data ||= encode_utf8(@binary_data || parsed_content[:binary_data]) end - def path - filename - end - def project_id @project_id || @project&.id end @@ -83,16 +79,16 @@ def present end def fetch_blob - path = [ref, blob_filename] - missing_blob = { binary_filename: blob_filename } + path = [ref, blob_path] + missing_blob = { binary_path: blob_path } BatchLoader.for(path).batch(default_value: missing_blob) do |refs, loader| Gitlab::Git::Blob.batch(repository, refs, blob_size_limit: 1024).each do |blob| # if the blob couldn't be fetched for some reason, - # show at least the blob filename + # show at least the blob path data = { id: blob.id, - binary_filename: blob.path, + binary_path: blob.path, binary_basename: path_without_extension(blob.path), ref: ref, startline: 1, @@ -107,8 +103,8 @@ def fetch_blob private - def search_result_filename - content_match.match(FILENAME_REGEXP) { |matches| matches[:filename] } + def search_result_path + content_match.match(PATH_REGEXP) { |matches| matches[:path] } end def path_without_extension(path) @@ -119,7 +115,7 @@ def parsed_content strong_memoize(:parsed_content) do if content_match parse_search_result - elsif blob_filename + elsif blob_path fetch_blob else {} @@ -129,7 +125,7 @@ def parsed_content def parse_search_result ref = nil - filename = nil + path = nil basename = nil data = [] @@ -138,17 +134,17 @@ def parse_search_result content_match.each_line.each_with_index do |line, index| prefix ||= line.match(CONTENT_REGEXP)&.tap do |matches| ref = matches[:ref] - filename = matches[:filename] + path = matches[:path] startline = matches[:startline] startline = startline.to_i - index - basename = path_without_extension(filename) + basename = path_without_extension(path) end data << line.sub(prefix.to_s, '') end { - binary_filename: filename, + binary_path: path, binary_basename: basename, ref: ref, startline: startline, diff --git a/lib/gitlab/wiki_file_finder.rb b/lib/gitlab/wiki_file_finder.rb index e9be6db50da30fdc07aba83136bf231858096d42..a963cc7954f6a27869ec85b952528462b7f9faae 100644 --- a/lib/gitlab/wiki_file_finder.rb +++ b/lib/gitlab/wiki_file_finder.rb @@ -12,12 +12,12 @@ def initialize(project, ref) private - def search_filenames(query) + def search_paths(query) safe_query = Regexp.escape(query.tr(' ', '-')) safe_query = Regexp.new(safe_query, Regexp::IGNORECASE) - filenames = repository.ls_files(ref) + paths = repository.ls_files(ref) - filenames.grep(safe_query) + paths.grep(safe_query) end end end diff --git a/spec/fixtures/api/schemas/public_api/v4/blobs.json b/spec/fixtures/api/schemas/public_api/v4/blobs.json index a812815838f0ca403c2dfaf5c8ee5742160083b4..5dcefb42367907b51949faebfd1a57724dbd9939 100644 --- a/spec/fixtures/api/schemas/public_api/v4/blobs.json +++ b/spec/fixtures/api/schemas/public_api/v4/blobs.json @@ -5,6 +5,7 @@ "properties" : { "basename": { "type": "string" }, "data": { "type": "string" }, + "path": { "type": ["string"] }, "filename": { "type": ["string"] }, "id": { "type": ["string", "null"] }, "project_id": { "type": "integer" }, @@ -12,7 +13,7 @@ "startline": { "type": "integer" } }, "required": [ - "basename", "data", "filename", "id", "ref", "startline", "project_id" + "basename", "data", "path", "filename", "id", "ref", "startline", "project_id" ], "additionalProperties": false } diff --git a/spec/lib/gitlab/file_finder_spec.rb b/spec/lib/gitlab/file_finder_spec.rb index b49c5817131e623d12e0fbeb70b196f105211eae..a3ba7388f366872057f13a234d3c7525119b0b78 100644 --- a/spec/lib/gitlab/file_finder_spec.rb +++ b/spec/lib/gitlab/file_finder_spec.rb @@ -6,11 +6,11 @@ subject { described_class.new(project, project.default_branch) } it_behaves_like 'file finder' do - let(:expected_file_by_name) { 'files/images/wm.svg' } + let(:expected_file_by_path) { 'files/images/wm.svg' } let(:expected_file_by_content) { 'CHANGELOG' } end - it 'filters by name' do + it 'filters by filename' do results = subject.find('files filename:wm.svg') expect(results.count).to eq(1) diff --git a/spec/lib/gitlab/project_search_results_spec.rb b/spec/lib/gitlab/project_search_results_spec.rb index d6e50c672e6b2d5365912e32c08df5b95c966e2f..99078f19361285e3904123c691b893088cc0297b 100644 --- a/spec/lib/gitlab/project_search_results_spec.rb +++ b/spec/lib/gitlab/project_search_results_spec.rb @@ -79,20 +79,20 @@ end it 'finds by name' do - expect(results.map(&:filename)).to include(expected_file_by_name) + expect(results.map(&:path)).to include(expected_file_by_path) end - it "loads all blobs for filename matches in single batch" do + it "loads all blobs for path matches in single batch" do expect(Gitlab::Git::Blob).to receive(:batch).once.and_call_original expected = project.repository.search_files_by_name(query, 'master') - expect(results.map(&:filename)).to include(*expected) + expect(results.map(&:path)).to include(*expected) end it 'finds by content' do - blob = results.select { |result| result.filename == expected_file_by_content }.flatten.last + blob = results.select { |result| result.path == expected_file_by_content }.flatten.last - expect(blob.filename).to eq(expected_file_by_content) + expect(blob.path).to eq(expected_file_by_content) end end @@ -146,7 +146,7 @@ let(:blob_type) { 'blobs' } let(:disabled_project) { create(:project, :public, :repository, :repository_disabled) } let(:private_project) { create(:project, :public, :repository, :repository_private) } - let(:expected_file_by_name) { 'files/images/wm.svg' } + let(:expected_file_by_path) { 'files/images/wm.svg' } let(:expected_file_by_content) { 'CHANGELOG' } end @@ -169,7 +169,7 @@ let(:blob_type) { 'wiki_blobs' } let(:disabled_project) { create(:project, :public, :wiki_repo, :wiki_disabled) } let(:private_project) { create(:project, :public, :wiki_repo, :wiki_private) } - let(:expected_file_by_name) { 'Files/Title.md' } + let(:expected_file_by_path) { 'Files/Title.md' } let(:expected_file_by_content) { 'CHANGELOG.md' } end diff --git a/spec/lib/gitlab/search/found_blob_spec.rb b/spec/lib/gitlab/search/found_blob_spec.rb index a575f6e2f11a5150b93fe18c492cfb1d2d911d5f..07842faa6389e495878d38d346cc930d95a78a32 100644 --- a/spec/lib/gitlab/search/found_blob_spec.rb +++ b/spec/lib/gitlab/search/found_blob_spec.rb @@ -15,7 +15,6 @@ is_expected.to be_an described_class expect(subject.id).to be_nil expect(subject.path).to eq('CHANGELOG') - expect(subject.filename).to eq('CHANGELOG') expect(subject.basename).to eq('CHANGELOG') expect(subject.ref).to eq('master') expect(subject.startline).to eq(188) @@ -25,12 +24,12 @@ it 'does not parse content if not needed' do expect(subject).not_to receive(:parse_search_result) expect(subject.project_id).to eq(project.id) - expect(subject.binary_filename).to eq('CHANGELOG') + expect(subject.binary_path).to eq('CHANGELOG') end it 'parses content only once when needed' do expect(subject).to receive(:parse_search_result).once.and_call_original - expect(subject.filename).to eq('CHANGELOG') + expect(subject.path).to eq('CHANGELOG') expect(subject.startline).to eq(188) end @@ -38,7 +37,7 @@ let(:search_result) { "master:testdata/project::function1.yaml\x001\x00---\n" } it 'returns a valid FoundBlob' do - expect(subject.filename).to eq('testdata/project::function1.yaml') + expect(subject.path).to eq('testdata/project::function1.yaml') expect(subject.basename).to eq('testdata/project::function1') expect(subject.ref).to eq('master') expect(subject.startline).to eq(1) @@ -50,7 +49,7 @@ let(:search_result) { "master:testdata/foo.txt\x001\x00blah:9:blah" } it 'returns a valid FoundBlob' do - expect(subject.filename).to eq('testdata/foo.txt') + expect(subject.path).to eq('testdata/foo.txt') expect(subject.basename).to eq('testdata/foo') expect(subject.ref).to eq('master') expect(subject.startline).to eq(1) @@ -62,7 +61,7 @@ let(:search_result) { "master:testdata/foo.txt\x001\x00blah\x001\x00foo" } it 'returns a valid FoundBlob' do - expect(subject.filename).to eq('testdata/foo.txt') + expect(subject.path).to eq('testdata/foo.txt') expect(subject.basename).to eq('testdata/foo') expect(subject.ref).to eq('master') expect(subject.startline).to eq(1) @@ -74,7 +73,7 @@ let(:results) { project.repository.search_files_by_content('Role models', 'master') } it 'returns a valid FoundBlob that ends with an empty line' do - expect(subject.filename).to eq('files/markdown/ruby-style-guide.md') + expect(subject.path).to eq('files/markdown/ruby-style-guide.md') expect(subject.basename).to eq('files/markdown/ruby-style-guide') expect(subject.ref).to eq('master') expect(subject.startline).to eq(1) @@ -87,7 +86,7 @@ let(:results) { project.repository.search_files_by_content('файл', 'master') } it 'returns results as UTF-8' do - expect(subject.filename).to eq('encoding/russian.rb') + expect(subject.path).to eq('encoding/russian.rb') expect(subject.basename).to eq('encoding/russian') expect(subject.ref).to eq('master') expect(subject.startline).to eq(1) @@ -99,7 +98,7 @@ let(:results) { project.repository.search_files_by_content('webhook', 'master') } it 'returns results as UTF-8' do - expect(subject.filename).to eq('encoding/テスト.txt') + expect(subject.path).to eq('encoding/テスト.txt') expect(subject.basename).to eq('encoding/テスト') expect(subject.ref).to eq('master') expect(subject.startline).to eq(3) @@ -111,7 +110,7 @@ let(:search_result) { (+"master:encoding/iso8859.txt\x001\x00\xC4\xFC\nmaster:encoding/iso8859.txt\x002\x00\nmaster:encoding/iso8859.txt\x003\x00foo\n").force_encoding(Encoding::ASCII_8BIT) } it 'returns results as UTF-8' do - expect(subject.filename).to eq('encoding/iso8859.txt') + expect(subject.path).to eq('encoding/iso8859.txt') expect(subject.basename).to eq('encoding/iso8859') expect(subject.ref).to eq('master') expect(subject.startline).to eq(1) @@ -124,7 +123,6 @@ let(:search_result) { "master:CONTRIBUTE.md\x005\x00- [Contribute to GitLab](#contribute-to-gitlab)\n" } it { expect(subject.path).to eq('CONTRIBUTE.md') } - it { expect(subject.filename).to eq('CONTRIBUTE.md') } it { expect(subject.basename).to eq('CONTRIBUTE') } end @@ -132,7 +130,6 @@ let(:search_result) { "master:a/b/c.md\x005\x00a b c\n" } it { expect(subject.path).to eq('a/b/c.md') } - it { expect(subject.filename).to eq('a/b/c.md') } it { expect(subject.basename).to eq('a/b/c') } end end @@ -141,7 +138,7 @@ context 'when file is under directory' do let(:path) { 'a/b/c.md' } - subject { described_class.new(blob_filename: path, project: project, ref: 'master') } + subject { described_class.new(blob_path: path, project: project, ref: 'master') } before do allow(Gitlab::Git::Blob).to receive(:batch).and_return([ @@ -150,7 +147,6 @@ end it { expect(subject.path).to eq('a/b/c.md') } - it { expect(subject.filename).to eq('a/b/c.md') } it { expect(subject.basename).to eq('a/b/c') } context 'when filename has multiple extensions' do diff --git a/spec/lib/gitlab/wiki_file_finder_spec.rb b/spec/lib/gitlab/wiki_file_finder_spec.rb index fdd95d5e6e6d62bfee521259824d9b47d5cdfa1a..aeba081f3d373e91801bcf8b1a32f42de54ac923 100644 --- a/spec/lib/gitlab/wiki_file_finder_spec.rb +++ b/spec/lib/gitlab/wiki_file_finder_spec.rb @@ -15,7 +15,7 @@ it_behaves_like 'file finder' do subject { described_class.new(project, project.wiki.default_branch) } - let(:expected_file_by_name) { 'Files/Title.md' } + let(:expected_file_by_path) { 'Files/Title.md' } let(:expected_file_by_content) { 'CHANGELOG.md' } end end diff --git a/spec/requests/api/search_spec.rb b/spec/requests/api/search_spec.rb index 8abdcaa2e0e96adcbc3e940ac02761b5e3e56ea9..0d8130f5e49b9a8395f06e6d1616b4cdb6d1ee52 100644 --- a/spec/requests/api/search_spec.rb +++ b/spec/requests/api/search_spec.rb @@ -436,6 +436,7 @@ expect(response).to have_gitlab_http_status(200) expect(json_response.size).to eq(2) + expect(json_response.first['path']).to eq('PROCESS.md') expect(json_response.first['filename']).to eq('PROCESS.md') end diff --git a/spec/support/shared_examples/file_finder.rb b/spec/support/shared_examples/file_finder.rb index 984a06ccd1aec8ce0bf973f643f80adb5ea6888c..f4b28b94090e5bd98d7bda6d4bbd0fd1fea9ff30 100644 --- a/spec/support/shared_examples/file_finder.rb +++ b/spec/support/shared_examples/file_finder.rb @@ -4,19 +4,19 @@ let(:query) { 'files' } let(:search_results) { subject.find(query) } - it 'finds by name' do - blob = search_results.find { |blob| blob.filename == expected_file_by_name } + it 'finds by path' do + blob = search_results.find { |blob| blob.path == expected_file_by_path } - expect(blob.filename).to eq(expected_file_by_name) + expect(blob.path).to eq(expected_file_by_path) expect(blob).to be_a(Gitlab::Search::FoundBlob) expect(blob.ref).to eq(subject.ref) expect(blob.data).not_to be_empty end it 'finds by content' do - blob = search_results.find { |blob| blob.filename == expected_file_by_content } + blob = search_results.find { |blob| blob.path == expected_file_by_content } - expect(blob.filename).to eq(expected_file_by_content) + expect(blob.path).to eq(expected_file_by_content) expect(blob).to be_a(Gitlab::Search::FoundBlob) expect(blob.ref).to eq(subject.ref) expect(blob.data).not_to be_empty