summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-27 15:08:16 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-27 15:08:16 +0000
commitfb73ca3398c2ac49a616ab553e117b0586089702 (patch)
treec2f787ac97df38569c59cd0e967331ec1ead6d7e /lib
parentb6b8f7dc871e73f29af55f06a773136a7242df57 (diff)
downloadgitlab-ce-fb73ca3398c2ac49a616ab553e117b0586089702.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r--lib/api/entities.rb24
-rw-r--r--lib/api/helpers/internal_helpers.rb12
-rw-r--r--lib/api/internal/base.rb4
-rw-r--r--lib/api/issues.rb19
-rw-r--r--lib/api/merge_requests.rb8
-rw-r--r--lib/gitlab/backtrace_cleaner.rb36
-rw-r--r--lib/gitlab/bitbucket_import/importer.rb2
-rw-r--r--lib/gitlab/exception_log_formatter.rb2
-rw-r--r--lib/gitlab/git/rugged_impl/use_rugged.rb2
-rw-r--r--lib/gitlab/gitaly_client.rb4
-rw-r--r--lib/gitlab/profiler.rb10
-rw-r--r--lib/gitlab/repo_path.rb7
-rw-r--r--lib/gitlab/repository_cache.rb3
-rw-r--r--lib/gitlab/repository_set_cache.rb3
-rw-r--r--lib/gitlab/sidekiq_logging/exception_handler.rb2
-rw-r--r--lib/gitlab/workhorse.rb8
-rw-r--r--lib/peek/views/active_record.rb2
-rw-r--r--lib/peek/views/redis_detailed.rb2
18 files changed, 94 insertions, 56 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index cc95be5e3be..c82821c3ca4 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -569,6 +569,20 @@ module API
end
end
+ class IssuableReferences < Grape::Entity
+ expose :short do |issuable|
+ issuable.to_reference
+ end
+
+ expose :relative do |issuable, options|
+ issuable.to_reference(options[:group] || options[:project])
+ end
+
+ expose :full do |issuable|
+ issuable.to_reference(full: true)
+ end
+ end
+
class Diff < Grape::Entity
expose :old_path, :new_path, :a_mode, :b_mode
expose :new_file?, as: :new_file
@@ -676,6 +690,10 @@ module API
end
end
+ expose :references, with: IssuableReferences do |issue|
+ issue
+ end
+
# Calculating the value of subscribed field triggers Markdown
# processing. We can't do that for multiple issues / merge
# requests in a single API request.
@@ -787,10 +805,16 @@ module API
# Deprecated
expose :allow_collaboration, as: :allow_maintainer_to_push, if: -> (merge_request, _) { merge_request.for_fork? }
+ # reference is deprecated in favour of references
+ # Introduced [Gitlab 12.6](https://gitlab.com/gitlab-org/gitlab/merge_requests/20354)
expose :reference do |merge_request, options|
merge_request.to_reference(options[:project])
end
+ expose :references, with: IssuableReferences do |merge_request|
+ merge_request
+ end
+
expose :web_url do |merge_request|
Gitlab::UrlBuilder.build(merge_request)
end
diff --git a/lib/api/helpers/internal_helpers.rb b/lib/api/helpers/internal_helpers.rb
index b03eb5ad440..607e0784415 100644
--- a/lib/api/helpers/internal_helpers.rb
+++ b/lib/api/helpers/internal_helpers.rb
@@ -120,21 +120,13 @@ module API
end
def gl_project_path
- if wiki?
- project.wiki.full_path
- else
- project.full_path
- end
+ repository.full_path
end
# Return the repository depending on whether we want the wiki or the
# regular repository
def repository
- if repo_type.wiki?
- project.wiki.repository
- else
- project.repository
- end
+ @repository ||= repo_type.repository_for(project)
end
# Return the Gitaly Address if it is enabled
diff --git a/lib/api/internal/base.rb b/lib/api/internal/base.rb
index 50142b8641e..11f2a2ea1c0 100644
--- a/lib/api/internal/base.rb
+++ b/lib/api/internal/base.rb
@@ -224,9 +224,9 @@ module API
response.add_merge_request_urls(merge_request_urls)
- # A user is not guaranteed to be returned; an orphaned write deploy
+ # Neither User nor Project are guaranteed to be returned; an orphaned write deploy
# key could be used
- if user
+ if user && project
redirect_message = Gitlab::Checks::ProjectMoved.fetch_message(user.id, project.id)
project_created_message = Gitlab::Checks::ProjectCreated.fetch_message(user.id, project.id)
diff --git a/lib/api/issues.rb b/lib/api/issues.rb
index 4208385a48d..1ef27d9f1b1 100644
--- a/lib/api/issues.rb
+++ b/lib/api/issues.rb
@@ -122,16 +122,15 @@ module API
use :issues_params
end
get ":id/issues" do
- group = find_group!(params[:id])
-
- issues = paginate(find_issues(group_id: group.id, include_subgroups: true))
+ issues = paginate(find_issues(group_id: user_group.id, include_subgroups: true))
options = {
with: Entities::Issue,
with_labels_details: declared_params[:with_labels_details],
current_user: current_user,
issuable_metadata: issuable_meta_data(issues, 'Issue', current_user),
- include_subscribed: false
+ include_subscribed: false,
+ group: user_group
}
present issues, options
@@ -142,9 +141,7 @@ module API
use :issues_stats_params
end
get ":id/issues_statistics" do
- group = find_group!(params[:id])
-
- present issues_statistics(group_id: group.id, include_subgroups: true), with: Grape::Presenters::Presenter
+ present issues_statistics(group_id: user_group.id, include_subgroups: true), with: Grape::Presenters::Presenter
end
end
@@ -161,9 +158,7 @@ module API
use :issues_params
end
get ":id/issues" do
- project = find_project!(params[:id])
-
- issues = paginate(find_issues(project_id: project.id))
+ issues = paginate(find_issues(project_id: user_project.id))
options = {
with: Entities::Issue,
@@ -182,9 +177,7 @@ module API
use :issues_stats_params
end
get ":id/issues_statistics" do
- project = find_project!(params[:id])
-
- present issues_statistics(project_id: project.id), with: Grape::Presenters::Presenter
+ present issues_statistics(project_id: user_project.id), with: Grape::Presenters::Presenter
end
desc 'Get a single project issue' do
diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb
index 794237f8032..0e161d5589a 100644
--- a/lib/api/merge_requests.rb
+++ b/lib/api/merge_requests.rb
@@ -157,11 +157,9 @@ module API
use :merge_requests_params
end
get ":id/merge_requests" do
- group = find_group!(params[:id])
+ merge_requests = find_merge_requests(group_id: user_group.id, include_subgroups: true)
- merge_requests = find_merge_requests(group_id: group.id, include_subgroups: true)
-
- present merge_requests, serializer_options_for(merge_requests)
+ present merge_requests, serializer_options_for(merge_requests).merge(group: user_group)
end
end
@@ -215,7 +213,7 @@ module API
merge_requests = find_merge_requests(project_id: user_project.id)
- options = serializer_options_for(merge_requests)
+ options = serializer_options_for(merge_requests).merge(project: user_project)
options[:project] = user_project
present merge_requests, options
diff --git a/lib/gitlab/backtrace_cleaner.rb b/lib/gitlab/backtrace_cleaner.rb
new file mode 100644
index 00000000000..30ec99808f7
--- /dev/null
+++ b/lib/gitlab/backtrace_cleaner.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module BacktraceCleaner
+ IGNORE_BACKTRACES = %w[
+ config/initializers
+ ee/lib/gitlab/middleware/
+ lib/gitlab/correlation_id.rb
+ lib/gitlab/database/load_balancing/
+ lib/gitlab/etag_caching/
+ lib/gitlab/i18n.rb
+ lib/gitlab/metrics/
+ lib/gitlab/middleware/
+ lib/gitlab/performance_bar/
+ lib/gitlab/profiler.rb
+ lib/gitlab/query_limiting/
+ lib/gitlab/request_context.rb
+ lib/gitlab/request_profiler/
+ lib/gitlab/sidekiq_logging/
+ lib/gitlab/sidekiq_middleware/
+ lib/gitlab/sidekiq_status/
+ lib/gitlab/tracing/
+ lib/gitlab/webpack/dev_server_middleware.rb
+ ].freeze
+
+ IGNORED_BACKTRACES_REGEXP = Regexp.union(IGNORE_BACKTRACES).freeze
+
+ def self.clean_backtrace(backtrace)
+ return unless backtrace
+
+ Array(Rails.backtrace_cleaner.clean(backtrace)).reject do |line|
+ line.match(IGNORED_BACKTRACES_REGEXP)
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/bitbucket_import/importer.rb b/lib/gitlab/bitbucket_import/importer.rb
index 67118aed549..349ca26ec03 100644
--- a/lib/gitlab/bitbucket_import/importer.rb
+++ b/lib/gitlab/bitbucket_import/importer.rb
@@ -42,7 +42,7 @@ module Gitlab
end
def store_pull_request_error(pull_request, ex)
- backtrace = Gitlab::Profiler.clean_backtrace(ex.backtrace)
+ backtrace = Gitlab::BacktraceCleaner.clean_backtrace(ex.backtrace)
error = { type: :pull_request, iid: pull_request.iid, errors: ex.message, trace: backtrace, raw_response: pull_request.raw }
Gitlab::ErrorTracking.log_exception(ex, error)
diff --git a/lib/gitlab/exception_log_formatter.rb b/lib/gitlab/exception_log_formatter.rb
index e0de0219294..92d55213cc2 100644
--- a/lib/gitlab/exception_log_formatter.rb
+++ b/lib/gitlab/exception_log_formatter.rb
@@ -13,7 +13,7 @@ module Gitlab
)
if exception.backtrace
- payload['exception.backtrace'] = Gitlab::Profiler.clean_backtrace(exception.backtrace)
+ payload['exception.backtrace'] = Gitlab::BacktraceCleaner.clean_backtrace(exception.backtrace)
end
end
end
diff --git a/lib/gitlab/git/rugged_impl/use_rugged.rb b/lib/gitlab/git/rugged_impl/use_rugged.rb
index 80b75689334..ca5d533bd75 100644
--- a/lib/gitlab/git/rugged_impl/use_rugged.rb
+++ b/lib/gitlab/git/rugged_impl/use_rugged.rb
@@ -27,7 +27,7 @@ module Gitlab
feature: method_name,
args: args,
duration: duration,
- backtrace: Gitlab::Profiler.clean_backtrace(caller))
+ backtrace: Gitlab::BacktraceCleaner.clean_backtrace(caller))
end
result
diff --git a/lib/gitlab/gitaly_client.rb b/lib/gitlab/gitaly_client.rb
index 25785089a34..9636e75aba1 100644
--- a/lib/gitlab/gitaly_client.rb
+++ b/lib/gitlab/gitaly_client.rb
@@ -179,7 +179,7 @@ module Gitlab
self.query_time += duration
if Gitlab::PerformanceBar.enabled_for_request?
add_call_details(feature: "#{service}##{rpc}", duration: duration, request: request_hash, rpc: rpc,
- backtrace: Gitlab::Profiler.clean_backtrace(caller))
+ backtrace: Gitlab::BacktraceCleaner.clean_backtrace(caller))
end
end
@@ -438,7 +438,7 @@ module Gitlab
def self.count_stack
return unless Gitlab::SafeRequestStore.active?
- stack_string = Gitlab::Profiler.clean_backtrace(caller).drop(1).join("\n")
+ stack_string = Gitlab::BacktraceCleaner.clean_backtrace(caller).drop(1).join("\n")
Gitlab::SafeRequestStore[:stack_counter] ||= Hash.new
diff --git a/lib/gitlab/profiler.rb b/lib/gitlab/profiler.rb
index f2f6180c464..f47ccb8fed9 100644
--- a/lib/gitlab/profiler.rb
+++ b/lib/gitlab/profiler.rb
@@ -107,7 +107,7 @@ module Gitlab
super
- Gitlab::Profiler.clean_backtrace(caller).each do |caller_line|
+ Gitlab::BacktraceCleaner.clean_backtrace(caller).each do |caller_line|
stripped_caller_line = caller_line.sub("#{Rails.root}/", '')
super(" ↳ #{stripped_caller_line}")
@@ -117,14 +117,6 @@ module Gitlab
end
end
- def self.clean_backtrace(backtrace)
- return unless backtrace
-
- Array(Rails.backtrace_cleaner.clean(backtrace)).reject do |line|
- line.match(Regexp.union(IGNORE_BACKTRACES))
- end
- end
-
def self.with_custom_logger(logger)
original_colorize_logging = ActiveSupport::LogSubscriber.colorize_logging
original_activerecord_logger = ActiveRecord::Base.logger
diff --git a/lib/gitlab/repo_path.rb b/lib/gitlab/repo_path.rb
index 030e50dfbf6..1baa2a9e461 100644
--- a/lib/gitlab/repo_path.rb
+++ b/lib/gitlab/repo_path.rb
@@ -32,9 +32,12 @@ module Gitlab
def self.find_project(project_path)
project = Project.find_by_full_path(project_path, follow_redirects: true)
- was_redirected = project && project.full_path.casecmp(project_path) != 0
- [project, was_redirected]
+ [project, redirected?(project, project_path)]
+ end
+
+ def self.redirected?(project, project_path)
+ project && project.full_path.casecmp(project_path) != 0
end
end
end
diff --git a/lib/gitlab/repository_cache.rb b/lib/gitlab/repository_cache.rb
index 56007574b1b..fca8c43da2e 100644
--- a/lib/gitlab/repository_cache.rb
+++ b/lib/gitlab/repository_cache.rb
@@ -7,7 +7,8 @@ module Gitlab
def initialize(repository, extra_namespace: nil, backend: Rails.cache)
@repository = repository
- @namespace = "#{repository.full_path}:#{repository.project.id}"
+ @namespace = "#{repository.full_path}"
+ @namespace += ":#{repository.project.id}" if repository.project
@namespace = "#{@namespace}:#{extra_namespace}" if extra_namespace
@backend = backend
end
diff --git a/lib/gitlab/repository_set_cache.rb b/lib/gitlab/repository_set_cache.rb
index 6d3ac53a787..4797ec0b116 100644
--- a/lib/gitlab/repository_set_cache.rb
+++ b/lib/gitlab/repository_set_cache.rb
@@ -7,7 +7,8 @@ module Gitlab
def initialize(repository, extra_namespace: nil, expires_in: 2.weeks)
@repository = repository
- @namespace = "#{repository.full_path}:#{repository.project.id}"
+ @namespace = "#{repository.full_path}"
+ @namespace += ":#{repository.project.id}" if repository.project
@namespace = "#{@namespace}:#{extra_namespace}" if extra_namespace
@expires_in = expires_in
end
diff --git a/lib/gitlab/sidekiq_logging/exception_handler.rb b/lib/gitlab/sidekiq_logging/exception_handler.rb
index fba74b6c9ed..a6d6819bf8e 100644
--- a/lib/gitlab/sidekiq_logging/exception_handler.rb
+++ b/lib/gitlab/sidekiq_logging/exception_handler.rb
@@ -18,7 +18,7 @@ module Gitlab
data.merge!(job_data) if job_data.present?
end
- data[:error_backtrace] = Gitlab::Profiler.clean_backtrace(job_exception.backtrace) if job_exception.backtrace.present?
+ data[:error_backtrace] = Gitlab::BacktraceCleaner.clean_backtrace(job_exception.backtrace) if job_exception.backtrace.present?
Sidekiq.logger.warn(data)
end
diff --git a/lib/gitlab/workhorse.rb b/lib/gitlab/workhorse.rb
index 713ca31bbc5..29450a33289 100644
--- a/lib/gitlab/workhorse.rb
+++ b/lib/gitlab/workhorse.rb
@@ -22,18 +22,16 @@ module Gitlab
def git_http_ok(repository, repo_type, user, action, show_all_refs: false)
raise "Unsupported action: #{action}" unless ALLOWED_GIT_HTTP_ACTIONS.include?(action.to_s)
- project = repository.project
-
attrs = {
GL_ID: Gitlab::GlId.gl_id(user),
- GL_REPOSITORY: repo_type.identifier_for_subject(project),
+ GL_REPOSITORY: repo_type.identifier_for_subject(repository.project),
GL_USERNAME: user&.username,
ShowAllRefs: show_all_refs,
Repository: repository.gitaly_repository.to_h,
GitConfigOptions: [],
GitalyServer: {
- address: Gitlab::GitalyClient.address(project.repository_storage),
- token: Gitlab::GitalyClient.token(project.repository_storage),
+ address: Gitlab::GitalyClient.address(repository.storage),
+ token: Gitlab::GitalyClient.token(repository.storage),
features: Feature::Gitaly.server_feature_flags
}
}
diff --git a/lib/peek/views/active_record.rb b/lib/peek/views/active_record.rb
index 1bb3ddb964a..ed3470f81f4 100644
--- a/lib/peek/views/active_record.rb
+++ b/lib/peek/views/active_record.rb
@@ -32,7 +32,7 @@ module Peek
detail_store << {
duration: finish - start,
sql: data[:sql].strip,
- backtrace: Gitlab::Profiler.clean_backtrace(caller)
+ backtrace: Gitlab::BacktraceCleaner.clean_backtrace(caller)
}
end
end
diff --git a/lib/peek/views/redis_detailed.rb b/lib/peek/views/redis_detailed.rb
index 84041b6be73..14cabd62025 100644
--- a/lib/peek/views/redis_detailed.rb
+++ b/lib/peek/views/redis_detailed.rb
@@ -23,7 +23,7 @@ module Gitlab
detail_store << {
cmd: args.first,
duration: duration,
- backtrace: ::Gitlab::Profiler.clean_backtrace(caller)
+ backtrace: ::Gitlab::BacktraceCleaner.clean_backtrace(caller)
}
end