Support regex-based filtering for SearchFilesByName in the repository model
Problem
Our Repository
model doesn't currently support regex-based filtering to SearchFilesByName
. We need this to be possible in order to search for all matching paths in a repository. This is needed in order to support wildcards when specifying include paths in .gitlab-ci.yml.
Possible solution:
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index 1a3409c1f84..d3f45e7a3eb 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -994,13 +994,13 @@ def can_be_merged?(source_sha, target_branch)
end
end
- def search_files_by_name(query, ref)
+ def search_files_by_name(query, ref, filter_glob = "")
safe_query = Regexp.escape(query.sub(%r{^/*}, ""))
ref ||= root_ref
return [] if empty? || safe_query.blank?
- gitaly_repository_client.search_files_by_name(ref, safe_query)
+ gitaly_repository_client.search_files_by_name(ref, safe_query, filter_glob)
end
def find_commits_by_message(query, ref, path, limit, offset)
diff --git a/lib/gitlab/gitaly_client/repository_service.rb b/lib/gitlab/gitaly_client/repository_service.rb
index 20ad6d0184b..43eaf5bf75d 100644
--- a/lib/gitlab/gitaly_client/repository_service.rb
+++ b/lib/gitlab/gitaly_client/repository_service.rb
@@ -327,8 +327,8 @@ def raw_changes_between(from, to)
GitalyClient.call(@storage, :repository_service, :get_raw_changes, request, timeout: GitalyClient.fast_timeout)
end
- def search_files_by_name(ref, query)
- request = Gitaly::SearchFilesByNameRequest.new(repository: @gitaly_repo, ref: ref, query: query)
+ def search_files_by_name(ref, query, filter)
+ request = Gitaly::SearchFilesByNameRequest.new(repository: @gitaly_repo, ref: ref, query: query, filter: filter)
GitalyClient.call(@storage, :repository_service, :search_files_by_name, request, timeout: GitalyClient.fast_timeout).flat_map(&:files)
end
gitaly!2262 (merged)
Related MR:Edited by Furkan Ayhan