Commit c77dd099 authored by GitLab Bot's avatar GitLab Bot

Add latest changes from gitlab-org/gitlab@master

parent 11faf8ae
...@@ -96,8 +96,9 @@ module SearchHelper ...@@ -96,8 +96,9 @@ module SearchHelper
result result
end end
def search_blob_title(project, filename) # Overriden in EE
filename def search_blob_title(project, path)
path
end end
def search_service def search_service
......
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
- return unless project - return unless project
- blob = parse_search_result(blob) - 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 }
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
= link_to blob_link do = link_to blob_link do
%i.fa.fa-file %i.fa.fa-file
%strong %strong
= search_blob_title(project, file_name) = search_blob_title(project, path)
- if blob.data - if blob.data
.file-content.code.term{ data: { qa_selector: 'file_text_content' } } .file-content.code.term{ data: { qa_selector: 'file_text_content' } }
= render 'shared/file_highlight', blob: blob, first_line_number: blob.startline = render 'shared/file_highlight', blob: blob, first_line_number: blob.startline
...@@ -2,4 +2,4 @@ ...@@ -2,4 +2,4 @@
- wiki_blob = parse_search_result(wiki_blob) - wiki_blob = parse_search_result(wiki_blob)
- wiki_blob_link = project_wiki_path(project, wiki_blob.basename) - 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 }
title: Create table for elastic stack.
merge_request: 18015
author:
type: added
...@@ -299,6 +299,7 @@ Example response: ...@@ -299,6 +299,7 @@ Example response:
{ {
"basename": "home", "basename": "home",
"data": "hello\n\nand bye\n\nend", "data": "hello\n\nand bye\n\nend",
"path": "home.md",
"filename": "home.md", "filename": "home.md",
"id": null, "id": null,
"ref": "master", "ref": "master",
...@@ -308,6 +309,8 @@ Example response: ...@@ -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)** ### Scope: commits **(STARTER)**
This scope is available only if [Elasticsearch](../integration/elasticsearch.md) is enabled. This scope is available only if [Elasticsearch](../integration/elasticsearch.md) is enabled.
...@@ -367,6 +370,7 @@ Example response: ...@@ -367,6 +370,7 @@ Example response:
{ {
"basename": "README", "basename": "README",
"data": "```\n\n## Installation\n\nQuick start using the [pre-built", "data": "```\n\n## Installation\n\nQuick start using the [pre-built",
"path": "README.md",
"filename": "README.md", "filename": "README.md",
"id": null, "id": null,
"ref": "master", "ref": "master",
...@@ -376,6 +380,8 @@ Example response: ...@@ -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 ### Scope: users
```bash ```bash
...@@ -633,6 +639,7 @@ Example response: ...@@ -633,6 +639,7 @@ Example response:
{ {
"basename": "home", "basename": "home",
"data": "hello\n\nand bye\n\nend", "data": "hello\n\nand bye\n\nend",
"path": "home.md",
"filename": "home.md", "filename": "home.md",
"id": null, "id": null,
"ref": "master", "ref": "master",
...@@ -642,6 +649,8 @@ Example response: ...@@ -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)** ### Scope: commits **(STARTER)**
This scope is available only if [Elasticsearch](../integration/elasticsearch.md) is enabled. This scope is available only if [Elasticsearch](../integration/elasticsearch.md) is enabled.
...@@ -701,6 +710,7 @@ Example response: ...@@ -701,6 +710,7 @@ Example response:
{ {
"basename": "README", "basename": "README",
"data": "```\n\n## Installation\n\nQuick start using the [pre-built", "data": "```\n\n## Installation\n\nQuick start using the [pre-built",
"path": "README.md",
"filename": "README.md", "filename": "README.md",
"id": null, "id": null,
"ref": "master", "ref": "master",
...@@ -710,6 +720,8 @@ Example response: ...@@ -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 ### Scope: users
```bash ```bash
...@@ -981,6 +993,7 @@ Example response: ...@@ -981,6 +993,7 @@ Example response:
{ {
"basename": "home", "basename": "home",
"data": "hello\n\nand bye\n\nend", "data": "hello\n\nand bye\n\nend",
"path": "home.md",
"filename": "home.md", "filename": "home.md",
"id": null, "id": null,
"ref": "master", "ref": "master",
...@@ -990,6 +1003,8 @@ Example response: ...@@ -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 ### Scope: commits
```bash ```bash
...@@ -1051,6 +1066,7 @@ Example response: ...@@ -1051,6 +1066,7 @@ Example response:
{ {
"basename": "README", "basename": "README",
"data": "```\n\n## Installation\n\nQuick start using the [pre-built", "data": "```\n\n## Installation\n\nQuick start using the [pre-built",
"path": "README.md",
"filename": "README.md", "filename": "README.md",
"id": null, "id": null,
"ref": "master", "ref": "master",
...@@ -1060,6 +1076,8 @@ Example response: ...@@ -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 ### Scope: users
```bash ```bash
...@@ -1082,3 +1100,4 @@ Example response: ...@@ -1082,3 +1100,4 @@ Example response:
``` ```
[ce-41763]: https://gitlab.com/gitlab-org/gitlab-foss/issues/41763 [ce-41763]: https://gitlab.com/gitlab-org/gitlab-foss/issues/41763
[gitlab-34521]: https://gitlab.com/gitlab-org/gitlab/issues/34521
...@@ -82,19 +82,21 @@ certificates. Installing Cert-Manager on your cluster will issue a ...@@ -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 certificate by [Let's Encrypt](https://letsencrypt.org/) and ensure that
certificates are valid and up-to-date. certificates are valid and up-to-date.
NOTE: **Note:** The chart used to install this application depends on the version of GitLab used. In:
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.
NOTE: **Note:** - GitLab 12.3 and newer, the [jetstack/cert-manager](https://github.com/jetstack/cert-manager)
If you have installed cert-manager prior to GitLab 12.3, Let's Encrypt will chart is used with a [`values.yaml`](https://gitlab.com/gitlab-org/gitlab/blob/master/vendor/cert_manager/values.yaml)
[block requests from older versions of cert-manager](https://community.letsencrypt.org/t/blocking-old-cert-manager-versions/98753). file.
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.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 ### GitLab Runner
...@@ -296,7 +298,7 @@ The applications below can be uninstalled. ...@@ -296,7 +298,7 @@ The applications below can be uninstalled.
| Application | GitLab version | Notes | | 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. | | 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. | | 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. | | 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. |
......
...@@ -1710,7 +1710,12 @@ module API ...@@ -1710,7 +1710,12 @@ module API
class Blob < Grape::Entity class Blob < Grape::Entity
expose :basename expose :basename
expose :data 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 :id
expose :ref expose :ref
expose :startline expose :startline
......
...@@ -15,12 +15,12 @@ module Gitlab ...@@ -15,12 +15,12 @@ module Gitlab
def find(query) def find(query)
query = Gitlab::Search::Query.new(query, encode_binary: true) do query = Gitlab::Search::Query.new(query, encode_binary: true) do
filter :filename, 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_filename =~ /#{filter[:regex_value]}/i } filter :path, matcher: ->(filter, blob) { blob.binary_path =~ /#{filter[:regex_value]}/i }
filter :extension, matcher: ->(filter, blob) { blob.binary_filename =~ /\.#{filter[:regex_value]}$/i } filter :extension, matcher: ->(filter, blob) { blob.binary_path =~ /\.#{filter[:regex_value]}$/i }
end 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? files = query.filter_results(files) if query.filters.any?
...@@ -35,13 +35,14 @@ module Gitlab ...@@ -35,13 +35,14 @@ module Gitlab
end end
end end
def find_by_filename(query) def find_by_path(query)
search_filenames(query).map do |filename| search_paths(query).map do |path|
Gitlab::Search::FoundBlob.new(blob_filename: filename, project: project, ref: ref, repository: repository) Gitlab::Search::FoundBlob.new(blob_path: path, project: project, ref: ref, repository: repository)
end end
end end
def search_filenames(query) # Overriden in Gitlab::WikiFileFinder
def search_paths(query)
repository.search_files_by_name(query, ref) repository.search_files_by_name(query, ref)
end end
end end
......
...@@ -8,20 +8,20 @@ module Gitlab ...@@ -8,20 +8,20 @@ module Gitlab
include BlobLanguageFromGitAttributes include BlobLanguageFromGitAttributes
include Gitlab::Utils::StrongMemoize 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 PATH_REGEXP = /\A(?<ref>[^:]*):(?<path>[^\x00]*)\x00/.freeze
CONTENT_REGEXP = /^(?<ref>[^:]*):(?<filename>[^\x00]*)\x00(?<startline>\d+)\x00/.freeze CONTENT_REGEXP = /^(?<ref>[^:]*):(?<path>[^\x00]*)\x00(?<startline>\d+)\x00/.freeze
def self.preload_blobs(blobs) 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 } to_fetch.each { |blob| blob.fetch_blob }
end end
def initialize(opts = {}) def initialize(opts = {})
@id = opts.fetch(:id, nil) @id = opts.fetch(:id, nil)
@binary_filename = opts.fetch(:filename, nil) @binary_path = opts.fetch(:path, nil)
@binary_basename = opts.fetch(:basename, nil) @binary_basename = opts.fetch(:basename, nil)
@ref = opts.fetch(:ref, nil) @ref = opts.fetch(:ref, nil)
@startline = opts.fetch(:startline, nil) @startline = opts.fetch(:startline, nil)
...@@ -34,7 +34,7 @@ module Gitlab ...@@ -34,7 +34,7 @@ module Gitlab
# Allow those to just pass project_id instead. # Allow those to just pass project_id instead.
@project_id = opts.fetch(:project_id, nil) @project_id = opts.fetch(:project_id, nil)
@content_match = opts.fetch(:content_match, 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) @repository = opts.fetch(:repository, nil)
end end
...@@ -50,16 +50,16 @@ module Gitlab ...@@ -50,16 +50,16 @@ module Gitlab
@startline ||= parsed_content[:startline] @startline ||= parsed_content[:startline]
end end
# binary_filename is used for running filters on all matches, # binary_path is used for running filters on all matches.
# for grepped results (which use content_match), we get # For grepped results (which use content_match), we get
# filename from the beginning of the grepped result which is faster # the path from the beginning of the grepped result which is faster
# then parsing whole snippet # than parsing the whole snippet
def binary_filename def binary_path
@binary_filename ||= content_match ? search_result_filename : parsed_content[:binary_filename] @binary_path ||= content_match ? search_result_path : parsed_content[:binary_path]
end end
def filename def path
@filename ||= encode_utf8(@binary_filename || parsed_content[:binary_filename]) @path ||= encode_utf8(@binary_path || parsed_content[:binary_path])
end end
def basename def basename
...@@ -70,10 +70,6 @@ module Gitlab ...@@ -70,10 +70,6 @@ module Gitlab
@data ||= encode_utf8(@binary_data || parsed_content[:binary_data]) @data ||= encode_utf8(@binary_data || parsed_content[:binary_data])
end end
def path
filename
end
def project_id def project_id
@project_id || @project&.id @project_id || @project&.id
end end
...@@ -83,16 +79,16 @@ module Gitlab ...@@ -83,16 +79,16 @@ module Gitlab
end end
def fetch_blob def fetch_blob
path = [ref, blob_filename] path = [ref, blob_path]
missing_blob = { binary_filename: blob_filename } missing_blob = { binary_path: blob_path }
BatchLoader.for(path).batch(default_value: missing_blob) do |refs, loader| BatchLoader.for(path).batch(default_value: missing_blob) do |refs, loader|
Gitlab::Git::Blob.batch(repository, refs, blob_size_limit: 1024).each do |blob| Gitlab::Git::Blob.batch(repository, refs, blob_size_limit: 1024).each do |blob|
# if the blob couldn't be fetched for some reason, # if the blob couldn't be fetched for some reason,
# show at least the blob filename # show at least the blob path
data = { data = {
id: blob.id, id: blob.id,
binary_filename: blob.path, binary_path: blob.path,
binary_basename: path_without_extension(blob.path), binary_basename: path_without_extension(blob.path),
ref: ref, ref: ref,
startline: 1, startline: 1,
...@@ -107,8 +103,8 @@ module Gitlab ...@@ -107,8 +103,8 @@ module Gitlab
private private
def search_result_filename def search_result_path
content_match.match(FILENAME_REGEXP) { |matches| matches[:filename] } content_match.match(PATH_REGEXP) { |matches| matches[:path] }
end end
def path_without_extension(path) def path_without_extension(path)
...@@ -119,7 +115,7 @@ module Gitlab ...@@ -119,7 +115,7 @@ module Gitlab
strong_memoize(:parsed_content) do strong_memoize(:parsed_content) do
if content_match if content_match
parse_search_result parse_search_result
elsif blob_filename elsif blob_path
fetch_blob fetch_blob
else else
{} {}
...@@ -129,7 +125,7 @@ module Gitlab ...@@ -129,7 +125,7 @@ module Gitlab
def parse_search_result def parse_search_result
ref = nil ref = nil
filename = nil path = nil
basename = nil basename = nil
data = [] data = []
...@@ -138,17 +134,17 @@ module Gitlab ...@@ -138,17 +134,17 @@ module Gitlab
content_match.each_line.each_with_index do |line, index| content_match.each_line.each_with_index do |line, index|
prefix ||= line.match(CONTENT_REGEXP)&.tap do |matches| prefix ||= line.match(CONTENT_REGEXP)&.tap do |matches|
ref = matches[:ref] ref = matches[:ref]
filename = matches[:filename] path = matches[:path]
startline = matches[:startline] startline = matches[:startline]
startline = startline.to_i - index startline = startline.to_i - index
basename = path_without_extension(filename) basename = path_without_extension(path)
end end
data << line.sub(prefix.to_s, '') data << line.sub(prefix.to_s, '')
end end
{ {
binary_filename: filename, binary_path: path,
binary_basename: basename, binary_basename: basename,
ref: ref, ref: ref,
startline: startline, startline: startline,
......
...@@ -12,12 +12,12 @@ module Gitlab ...@@ -12,12 +12,12 @@ module Gitlab
private private
def search_filenames(query) def search_paths(query)
safe_query = Regexp.escape(query.tr(' ', '-')) safe_query = Regexp.escape(query.tr(' ', '-'))
safe_query = Regexp.new(safe_query, Regexp::IGNORECASE) 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 end
end end
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
"properties" : { "properties" : {
"basename": { "type": "string" }, "basename": { "type": "string" },
"data": { "type": "string" }, "data": { "type": "string" },
"path": { "type": ["string"] },
"filename": { "type": ["string"] }, "filename": { "type": ["string"] },
"id": { "type": ["string", "null"] }, "id": { "type": ["string", "null"] },
"project_id": { "type": "integer" }, "project_id": { "type": "integer" },
...@@ -12,7 +13,7 @@ ...@@ -12,7 +13,7 @@
"startline": { "type": "integer" } "startline": { "type": "integer" }
}, },
"required": [ "required": [
"basename", "data", "filename", "id", "ref", "startline", "project_id" "basename", "data", "path", "filename", "id", "ref", "startline", "project_id"
], ],
"additionalProperties": false "additionalProperties": false
} }
......
...@@ -6,11 +6,11 @@ describe Gitlab::FileFinder do ...@@ -6,11 +6,11 @@ describe Gitlab::FileFinder do
subject { described_class.new(project, project.default_branch) } subject { described_class.new(project, project.default_branch) }
it_behaves_like 'file finder' do 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' } let(:expected_file_by_content) { 'CHANGELOG' }
end end
it 'filters by name' do it 'filters by filename' do
results = subject.find('files filename:wm.svg') results = subject.find('files filename:wm.svg')
expect(results.count).to eq(1) expect(results.count).to eq(1)
......
...@@ -79,20 +79,20 @@ describe Gitlab::ProjectSearchResults do ...@@ -79,20 +79,20 @@ describe Gitlab::ProjectSearchResults do
end end
it 'finds by name' do 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 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 expect(Gitlab::Git::Blob).to receive(:batch).once.and_call_original
expected = project.repository.search_files_by_name(query, 'master') expected = project.repository.search_files_by_name(query, 'master')
expect(results.map(&:filename)).to include(*expected) expect(results.map(&:path)).to include(*expected)
end end
it 'finds by content' do 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
end end
...@@ -146,7 +146,7 @@ describe Gitlab::ProjectSearchResults do ...@@ -146,7 +146,7 @@ describe Gitlab::ProjectSearchResults do
let(:blob_type) { 'blobs' } let(:blob_type) { 'blobs' }
let(:disabled_project) { create(:project, :public, :repository, :repository_disabled) } let(:disabled_project) { create(:project, :public, :repository, :repository_disabled) }
let(:private_project) { create(:project, :public, :repository, :repository_private) } 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' } let(:expected_file_by_content) { 'CHANGELOG' }
end end
...@@ -169,7 +169,7 @@ describe Gitlab::ProjectSearchResults do ...@@ -169,7 +169,7 @@ describe Gitlab::ProjectSearchResults do
let(:blob_type) { 'wiki_blobs' } let(:blob_type) { 'wiki_blobs' }
let(:disabled_project) { create(:project, :public, :wiki_repo, :wiki_disabled) } let(:disabled_project) { create(:project, :public, :wiki_repo, :wiki_disabled) }
let(:private_project) { create(:project, :public, :wiki_repo, :wiki_private) } 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' } let(:expected_file_by_content) { 'CHANGELOG.md' }
end end
......
...@@ -15,7 +15,6 @@ describe Gitlab::Search::FoundBlob do ...@@ -15,7 +15,6 @@ describe Gitlab::Search::FoundBlob do
is_expected.to be_an described_class is_expected.to be_an described_class
expect(subject.id).to be_nil expect(subject.id).to be_nil
expect(subject.path).to eq('CHANGELOG') expect(subject.path).to eq('CHANGELOG')
expect(subject.filename).to eq('CHANGELOG')
expect(subject.basename).to eq('CHANGELOG') expect(subject.basename).to eq('CHANGELOG')
expect(subject.ref).to eq('master') expect(subject.ref).to eq('master')
expect(subject.startline).to eq(188) expect(subject.startline).to eq(188)
...@@ -25,12 +24,12 @@ describe Gitlab::Search::FoundBlob do ...@@ -25,12 +24,12 @@ describe Gitlab::Search::FoundBlob do
it 'does not parse content if not needed' do it 'does not parse content if not needed' do
expect(subject).not_to receive(:parse_search_result) expect(subject).not_to receive(:parse_search_result)
expect(subject.project_id).to eq(project.id) expect(subject.project_id).to eq(project.id)
expect(subject.binary_filename).to eq('CHANGELOG') expect(subject.binary_path).to eq('CHANGELOG')
end end
it 'parses content only once when needed' do it 'parses content only once when needed' do
expect(subject).to receive(:parse_search_result).once.and_call_original 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) expect(subject.startline).to eq(188)
end end
...@@ -38,7 +37,7 @@ describe Gitlab::Search::FoundBlob do ...@@ -38,7 +37,7 @@ describe Gitlab::Search::FoundBlob do
let(:search_result) { "master:testdata/project::function1.yaml\x001\x00---\n" } let(:search_result) { "master:testdata/project::function1.yaml\x001\x00---\n" }
it 'returns a valid FoundBlob' do 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.basename).to eq('testdata/project::function1')
expect(subject.ref).to eq('master') expect(subject.ref).to eq('master')
expect(subject.startline).to eq(1) expect(subject.startline).to eq(1)
...@@ -50,7 +49,7 @@ describe Gitlab::Search::FoundBlob do ...@@ -50,7 +49,7 @@ describe Gitlab::Search::FoundBlob do
let(:search_result) { "master:testdata/foo.txt\x001\x00blah:9:blah" } let(:search_result) { "master:testdata/foo.txt\x001\x00blah:9:blah" }
it 'returns a valid FoundBlob' do 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.basename).to eq('testdata/foo')
expect(subject.ref).to eq('master') expect(subject.ref).to eq('master')
expect(subject.startline).to eq(1) expect(subject.startline).to eq(1)
...@@ -62,7 +61,7 @@ describe Gitlab::Search::FoundBlob do ...@@ -62,7 +61,7 @@ describe Gitlab::Search::FoundBlob do
let(:search_result) { "master:testdata/foo.txt\x001\x00blah\x001\x00foo" } let(:search_result) { "master:testdata/foo.txt\x001\x00blah\x001\x00foo" }
it 'returns a valid FoundBlob' do 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.basename).to eq('testdata/foo')
expect(subject.ref).to eq('master') expect(subject.ref).to eq('master')
expect(subject.startline).to eq(1) expect(subject.startline).to eq(1)
...@@ -74,7 +73,7 @@ describe Gitlab::Search::FoundBlob do ...@@ -74,7 +73,7 @@ describe Gitlab::Search::FoundBlob do
let(:results) { project.repository.search_files_by_content('Role models', 'master') } let(:results) { project.repository.search_files_by_content('Role models', 'master') }
it 'returns a valid FoundBlob that ends with an empty line' do 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.basename).to eq('files/markdown/ruby-style-guide')
expect(subject.ref).to eq('master') expect(subject.ref).to eq('master')
expect(subject.startline).to eq(1) expect(subject.startline).to eq(1)
...@@ -87,7 +86,7 @@ describe Gitlab::Search::FoundBlob do ...@@ -87,7 +86,7 @@ describe Gitlab::Search::FoundBlob do
let(:results) { project.repository.search_files_by_content('файл', 'master') } let(:results) { project.repository.search_files_by_content('файл', 'master') }
it 'returns results as UTF-8' do 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.basename).to eq('encoding/russian')
expect(subject.ref).to eq('master') expect(subject.ref).to eq('master')
expect(subject.startline).to eq(1) expect(subject.startline).to eq(1)
...@@ -99,7 +98,7 @@ describe Gitlab::Search::FoundBlob do ...@@ -99,7 +98,7 @@ describe Gitlab::Search::FoundBlob do
let(:results) { project.repository.search_files_by_content('webhook', 'master') } let(:results) { project.repository.search_files_by_content('webhook', 'master') }
it 'returns results as UTF-8' do 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.basename).to eq('encoding/テスト')
expect(subject.ref).to eq('master') expect(subject.ref).to eq('master')
expect(subject.startline).to eq(3) expect(subject.startline).to eq(3)
...@@ -111,7 +110,7 @@ describe Gitlab::Search::FoundBlob do ...@@ -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) } 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 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.basename).to eq('encoding/iso8859')
expect(subject.ref).to eq('master') expect(subject.ref).to eq('master')
expect(subject.startline).to eq(1) expect(subject.startline).to eq(1)
...@@ -124,7 +123,6 @@ describe Gitlab::Search::FoundBlob do ...@@ -124,7 +123,6 @@ describe Gitlab::Search::FoundBlob do
let(:search_result) { "master:CONTRIBUTE.md\x005\x00- [Contribute to GitLab](#contribute-to-gitlab)\n" } 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.path).to eq('CONTRIBUTE.md') }
it { expect(subject.filename).to eq('CONTRIBUTE.md') }
it { expect(subject.basename).to eq('CONTRIBUTE') } it { expect(subject.basename).to eq('CONTRIBUTE') }
end end
...@@ -132,7 +130,6 @@ describe Gitlab::Search::FoundBlob do ...@@ -132,7 +130,6 @@ describe Gitlab::Search::FoundBlob do
let(:search_result) { "master:a/b/c.md\x005\x00a b c\n" } 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.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') } it { expect(subject.basename).to eq('a/b/c') }
end end
end end
...@@ -141,7 +138,7 @@ describe Gitlab::Search::FoundBlob do ...@@ -141,7 +138,7 @@ describe Gitlab::Search::FoundBlob do
context 'when file is under directory' do context 'when file is under directory' do
let(:path) { 'a/b/c.md' } 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 before do
allow(Gitlab::Git::Blob).to receive(:batch).and_return([ allow(Gitlab::Git::Blob).to receive(:batch).and_return([
...@@ -150,7 +147,6 @@ describe Gitlab::Search::FoundBlob do ...@@ -150,7 +147,6 @@ describe Gitlab::Search::FoundBlob do
end end
it { expect(subject.path).to eq('a/b/c.md') } 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') } it { expect(subject.basename).to eq('a/b/c') }
context 'when filename has multiple extensions' do context 'when filename has multiple extensions' do
......
...@@ -15,7 +15,7 @@ describe Gitlab::WikiFileFinder do ...@@ -15,7 +15,7 @@ describe Gitlab::WikiFileFinder do
it_behaves_like 'file finder' do it_behaves_like 'file finder' do
subject { described_class.new(project, project.wiki.default_branch) } 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' } let(:expected_file_by_content) { 'CHANGELOG.md' }
end end
end end
......
...@@ -436,6 +436,7 @@ describe API::Search do ...@@ -436,6 +436,7 @@ describe API::Search do
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response.size).to eq(2) 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') expect(json_response.first['filename']).to eq('PROCESS.md')
end end
......
...@@ -4,19 +4,19 @@ shared_examples 'file finder' do ...@@ -4,19 +4,19 @@ shared_examples 'file finder' do
let(:query) { 'files' } let(:query) { 'files' }
let(:search_results) { subject.find(query) } let(:search_results) { subject.find(query) }
it 'finds by name' do it 'finds by path' do
blob = search_results.find { |blob| blob.filename == expected_file_by_name } 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).to be_a(Gitlab::Search::FoundBlob)
expect(blob.ref).to eq(subject.ref) expect(blob.ref).to eq(subject.ref)
expect(blob.data).not_to be_empty expect(blob.data).not_to be_empty
end end
it 'finds by content' do 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).to be_a(Gitlab::Search::FoundBlob)
expect(blob.ref).to eq(subject.ref) expect(blob.ref).to eq(subject.ref)
expect(blob.data).not_to be_empty expect(blob.data).not_to be_empty
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment