diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-24 03:07:18 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-24 03:07:18 +0300 |
commit | c77dd0995c19bd0d3a4203192f0710623e8f93be (patch) | |
tree | 90a7c773450f10031e2d53a8a126e84913224e6c | |
parent | 11faf8ae72dcdbaff31f97410a3a9319324438fd (diff) |
Add latest changes from gitlab-org/gitlab@master
-rw-r--r-- | GITLAB_ELASTICSEARCH_INDEXER_VERSION | 2 | ||||
-rw-r--r-- | app/helpers/search_helper.rb | 5 | ||||
-rw-r--r-- | app/views/search/results/_blob.html.haml | 4 | ||||
-rw-r--r-- | app/views/search/results/_blob_data.html.haml | 2 | ||||
-rw-r--r-- | app/views/search/results/_wiki_blob.html.haml | 2 | ||||
-rw-r--r-- | changelogs/unreleased/ak-add-elastic-cluster-app.yml | 4 | ||||
-rw-r--r-- | doc/api/search.md | 19 | ||||
-rw-r--r-- | doc/user/clusters/applications.md | 28 | ||||
-rw-r--r-- | lib/api/entities.rb | 7 | ||||
-rw-r--r-- | lib/gitlab/file_finder.rb | 17 | ||||
-rw-r--r-- | lib/gitlab/search/found_blob.rb | 54 | ||||
-rw-r--r-- | lib/gitlab/wiki_file_finder.rb | 6 | ||||
-rw-r--r-- | spec/fixtures/api/schemas/public_api/v4/blobs.json | 3 | ||||
-rw-r--r-- | spec/lib/gitlab/file_finder_spec.rb | 4 | ||||
-rw-r--r-- | spec/lib/gitlab/project_search_results_spec.rb | 14 | ||||
-rw-r--r-- | spec/lib/gitlab/search/found_blob_spec.rb | 24 | ||||
-rw-r--r-- | spec/lib/gitlab/wiki_file_finder_spec.rb | 2 | ||||
-rw-r--r-- | spec/requests/api/search_spec.rb | 1 | ||||
-rw-r--r-- | spec/support/shared_examples/file_finder.rb | 10 |
19 files changed, 117 insertions, 91 deletions
diff --git a/GITLAB_ELASTICSEARCH_INDEXER_VERSION b/GITLAB_ELASTICSEARCH_INDEXER_VERSION index 88c5fb891dc..bc80560fad6 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 9a19758b4e8..978d0a8c8fb 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -96,8 +96,9 @@ module SearchHelper 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 bdad07f36d1..4fb72b26955 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 36b6ea7bd37..01e42224428 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 b351ecd4edf..9afed2bbecc 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/changelogs/unreleased/ak-add-elastic-cluster-app.yml b/changelogs/unreleased/ak-add-elastic-cluster-app.yml new file mode 100644 index 00000000000..b8fd0880553 --- /dev/null +++ b/changelogs/unreleased/ak-add-elastic-cluster-app.yml @@ -0,0 +1,4 @@ +title: Create table for elastic stack. +merge_request: 18015 +author: +type: added diff --git a/doc/api/search.md b/doc/api/search.md index ca08f5ca0d7..f9bd5143018 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/doc/user/clusters/applications.md b/doc/user/clusters/applications.md index dc6f859e881..d8d249a327e 100644 --- a/doc/user/clusters/applications.md +++ b/doc/user/clusters/applications.md @@ -82,19 +82,21 @@ certificates. Installing Cert-Manager on your cluster will issue a certificate by [Let's Encrypt](https://letsencrypt.org/) and ensure that certificates are valid and up-to-date. -NOTE: **Note:** -The -[jetstack/cert-manager](https://github.com/jetstack/cert-manager) -chart is used to install this application with a -[`values.yaml`](https://gitlab.com/gitlab-org/gitlab/blob/master/vendor/cert_manager/values.yaml) -file. Prior to GitLab 12.3, -the [stable/cert-manager](https://github.com/helm/charts/tree/master/stable/cert-manager) -chart was used. +The chart used to install this application depends on the version of GitLab used. In: -NOTE: **Note:** -If you have installed cert-manager prior to GitLab 12.3, Let's Encrypt will -[block requests from older versions of cert-manager](https://community.letsencrypt.org/t/blocking-old-cert-manager-versions/98753). -To resolve this, uninstall cert-manager (consider [backing up any additional configuration](https://docs.cert-manager.io/en/latest/tasks/backup-restore-crds.html)), then install cert-manager again. +- GitLab 12.3 and newer, the [jetstack/cert-manager](https://github.com/jetstack/cert-manager) + chart is used with a [`values.yaml`](https://gitlab.com/gitlab-org/gitlab/blob/master/vendor/cert_manager/values.yaml) + file. +- GitLab 12.2 and older, the [stable/cert-manager](https://github.com/helm/charts/tree/master/stable/cert-manager) + chart was used. + +If you have installed Cert-Manager prior to GitLab 12.3, Let's Encrypt will +[block requests from older versions of Cert-Manager](https://community.letsencrypt.org/t/blocking-old-cert-manager-versions/98753). + +To resolve this: + +1. Uninstall Cert-Manager (consider [backing up any additional configuration](https://docs.cert-manager.io/en/latest/tasks/backup-restore-crds.html)). +1. Install Cert-Manager again. ### GitLab Runner @@ -296,7 +298,7 @@ The applications below can be uninstalled. | Application | GitLab version | Notes | | ----------- | -------------- | ----- | -| Cert-Manager | 12.2+ | The associated private key will be deleted and cannot be restored. Deployed applications will continue to use HTTPS, but certificates will not be renewed. Before uninstalling, you may wish to [back up your configuration](https://docs.cert-manager.io/en/latest/tasks/backup-restore-crds.html) or [revoke your certificates](https://letsencrypt.org/docs/revoking/) | +| Cert-Manager | 12.2+ | The associated private key will be deleted and cannot be restored. Deployed applications will continue to use HTTPS, but certificates will not be renewed. Before uninstalling, you may wish to [back up your configuration](https://docs.cert-manager.io/en/latest/tasks/backup-restore-crds.html) or [revoke your certificates](https://letsencrypt.org/docs/revoking/). | | GitLab Runner | 12.2+ | Any running pipelines will be canceled. | | Helm | 12.2+ | The associated Tiller pod, the `gitlab-managed-apps` namespace, and all of its resources will be deleted and cannot be restored. | | Ingress | 12.1+ | The associated load balancer and IP will be deleted and cannot be restored. Furthermore, it can only be uninstalled if JupyterHub is not installed. | diff --git a/lib/api/entities.rb b/lib/api/entities.rb index d3a29c6386d..933a571c17d 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -1710,7 +1710,12 @@ module API 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 3958814208c..ec9d2df613b 100644 --- a/lib/gitlab/file_finder.rb +++ b/lib/gitlab/file_finder.rb @@ -15,12 +15,12 @@ module Gitlab 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 @@ module Gitlab 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 fa09ecbdf30..360239a84e4 100644 --- a/lib/gitlab/search/found_blob.rb +++ b/lib/gitlab/search/found_blob.rb @@ -8,20 +8,20 @@ module Gitlab include BlobLanguageFromGitAttributes include Gitlab::Utils::StrongMemoize - attr_reader :project, :content_match, :blob_filename + attr_reader :project, :content_match, :blob_path - FILENAME_REGEXP = /\A(?<ref>[^:]*):(?<filename>[^\x00]*)\x00/.freeze - CONTENT_REGEXP = /^(?<ref>[^:]*):(?<filename>[^\x00]*)\x00(?<startline>\d+)\x00/.freeze + PATH_REGEXP = /\A(?<ref>[^:]*):(?<path>[^\x00]*)\x00/.freeze + CONTENT_REGEXP = /^(?<ref>[^:]*):(?<path>[^\x00]*)\x00(?<startline>\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 @@ module Gitlab # 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 @@ module Gitlab @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 @@ module Gitlab @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 @@ module Gitlab 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 @@ module Gitlab 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 @@ module Gitlab strong_memoize(:parsed_content) do if content_match parse_search_result - elsif blob_filename + elsif blob_path fetch_blob else {} @@ -129,7 +125,7 @@ module Gitlab def parse_search_result ref = nil - filename = nil + path = nil basename = nil data = [] @@ -138,17 +134,17 @@ module Gitlab 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 e9be6db50da..a963cc7954f 100644 --- a/lib/gitlab/wiki_file_finder.rb +++ b/lib/gitlab/wiki_file_finder.rb @@ -12,12 +12,12 @@ module Gitlab 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 a812815838f..5dcefb42367 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 b49c5817131..a3ba7388f36 100644 --- a/spec/lib/gitlab/file_finder_spec.rb +++ b/spec/lib/gitlab/file_finder_spec.rb @@ -6,11 +6,11 @@ describe Gitlab::FileFinder do 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 d6e50c672e6..99078f19361 100644 --- a/spec/lib/gitlab/project_search_results_spec.rb +++ b/spec/lib/gitlab/project_search_results_spec.rb @@ -79,20 +79,20 @@ describe Gitlab::ProjectSearchResults do 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 @@ describe Gitlab::ProjectSearchResults do 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 @@ describe Gitlab::ProjectSearchResults do 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 a575f6e2f11..07842faa638 100644 --- a/spec/lib/gitlab/search/found_blob_spec.rb +++ b/spec/lib/gitlab/search/found_blob_spec.rb @@ -15,7 +15,6 @@ describe Gitlab::Search::FoundBlob do 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 @@ describe Gitlab::Search::FoundBlob do 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 @@ describe Gitlab::Search::FoundBlob do 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 @@ describe Gitlab::Search::FoundBlob do 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 @@ describe Gitlab::Search::FoundBlob do 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 @@ describe Gitlab::Search::FoundBlob do 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 @@ describe Gitlab::Search::FoundBlob do 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 @@ describe Gitlab::Search::FoundBlob do 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 @@ describe Gitlab::Search::FoundBlob do 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 @@ describe Gitlab::Search::FoundBlob do 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 @@ describe Gitlab::Search::FoundBlob do 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 @@ describe Gitlab::Search::FoundBlob do 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 @@ describe Gitlab::Search::FoundBlob do 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 fdd95d5e6e6..aeba081f3d3 100644 --- a/spec/lib/gitlab/wiki_file_finder_spec.rb +++ b/spec/lib/gitlab/wiki_file_finder_spec.rb @@ -15,7 +15,7 @@ describe Gitlab::WikiFileFinder do 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 8abdcaa2e0e..0d8130f5e49 100644 --- a/spec/requests/api/search_spec.rb +++ b/spec/requests/api/search_spec.rb @@ -436,6 +436,7 @@ describe API::Search do 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 984a06ccd1a..f4b28b94090 100644 --- a/spec/support/shared_examples/file_finder.rb +++ b/spec/support/shared_examples/file_finder.rb @@ -4,19 +4,19 @@ shared_examples 'file finder' do 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 |