Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-26 18:08:56 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-26 18:08:56 +0300
commit17ab40ca089e1aef61a83f77ab6df62a72f6ce06 (patch)
tree8eb149293eee90ec2750b6ac5e46a111a806424e /app/services
parent66d4203791a01fdedf668a78818a229ea2c07aad (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services')
-rw-r--r--app/services/ci/create_job_artifacts_service.rb37
-rw-r--r--app/services/ci/retry_build_service.rb3
-rw-r--r--app/services/error_tracking/issue_update_service.rb1
-rw-r--r--app/services/metrics/dashboard/update_dashboard_service.rb89
4 files changed, 118 insertions, 12 deletions
diff --git a/app/services/ci/create_job_artifacts_service.rb b/app/services/ci/create_job_artifacts_service.rb
index e633dc7f633..3aa2b16bc73 100644
--- a/app/services/ci/create_job_artifacts_service.rb
+++ b/app/services/ci/create_job_artifacts_service.rb
@@ -1,8 +1,13 @@
# frozen_string_literal: true
module Ci
- class CreateJobArtifactsService
+ class CreateJobArtifactsService < ::BaseService
ArtifactsExistError = Class.new(StandardError)
+ OBJECT_STORAGE_ERRORS = [
+ Errno::EIO,
+ Google::Apis::ServerError,
+ Signet::RemoteServerError
+ ].freeze
def execute(job, artifacts_file, params, metadata_file: nil)
expire_in = params['expire_in'] ||
@@ -26,18 +31,20 @@ module Ci
expire_in: expire_in)
end
- job.update(artifacts_expire_in: expire_in)
- rescue ActiveRecord::RecordNotUnique => error
- return true if sha256_matches_existing_artifact?(job, params['artifact_type'], artifacts_file)
+ if job.update(artifacts_expire_in: expire_in)
+ success
+ else
+ error(job.errors.messages, :bad_request)
+ end
- Gitlab::ErrorTracking.track_exception(error,
- job_id: job.id,
- project_id: job.project_id,
- uploading_type: params['artifact_type']
- )
+ rescue ActiveRecord::RecordNotUnique => error
+ return success if sha256_matches_existing_artifact?(job, params['artifact_type'], artifacts_file)
- job.errors.add(:base, 'another artifact of the same type already exists')
- false
+ track_exception(error, job, params)
+ error('another artifact of the same type already exists', :bad_request)
+ rescue *OBJECT_STORAGE_ERRORS => error
+ track_exception(error, job, params)
+ error(error.message, :service_unavailable)
end
private
@@ -48,5 +55,13 @@ module Ci
existing_artifact.file_sha256 == artifacts_file.sha256
end
+
+ def track_exception(error, job, params)
+ Gitlab::ErrorTracking.track_exception(error,
+ job_id: job.id,
+ project_id: job.project_id,
+ uploading_type: params['artifact_type']
+ )
+ end
end
end
diff --git a/app/services/ci/retry_build_service.rb b/app/services/ci/retry_build_service.rb
index 838ed789155..87f818ad497 100644
--- a/app/services/ci/retry_build_service.rb
+++ b/app/services/ci/retry_build_service.rb
@@ -5,7 +5,8 @@ module Ci
CLONE_ACCESSORS = %i[pipeline project ref tag options name
allow_failure stage stage_id stage_idx trigger_request
yaml_variables when environment coverage_regex
- description tag_list protected needs resource_group scheduling_type].freeze
+ description tag_list protected needs_attributes
+ resource_group scheduling_type].freeze
def execute(build)
reprocess!(build).tap do |new_build|
diff --git a/app/services/error_tracking/issue_update_service.rb b/app/services/error_tracking/issue_update_service.rb
index e516ac95138..b8235678d1d 100644
--- a/app/services/error_tracking/issue_update_service.rb
+++ b/app/services/error_tracking/issue_update_service.rb
@@ -11,6 +11,7 @@ module ErrorTracking
)
compose_response(response) do
+ project_error_tracking_setting.expire_issues_cache
response[:closed_issue_iid] = update_related_issue&.iid
end
end
diff --git a/app/services/metrics/dashboard/update_dashboard_service.rb b/app/services/metrics/dashboard/update_dashboard_service.rb
new file mode 100644
index 00000000000..316563ecbe7
--- /dev/null
+++ b/app/services/metrics/dashboard/update_dashboard_service.rb
@@ -0,0 +1,89 @@
+# frozen_string_literal: true
+
+# Updates the content of a specified dashboard in .yml file inside `.gitlab/dashboards`
+module Metrics
+ module Dashboard
+ class UpdateDashboardService < ::BaseService
+ ALLOWED_FILE_TYPE = '.yml'
+ USER_DASHBOARDS_DIR = ::Metrics::Dashboard::ProjectDashboardService::DASHBOARD_ROOT
+
+ def execute
+ catch(:error) do
+ throw(:error, error(_(%q(You can't commit to this project)), :forbidden)) unless push_authorized?
+
+ result = ::Files::UpdateService.new(project, current_user, dashboard_attrs).execute
+ throw(:error, result.merge(http_status: :bad_request)) unless result[:status] == :success
+
+ success(result.merge(http_status: :created, dashboard: dashboard_details))
+ end
+ end
+
+ private
+
+ def dashboard_attrs
+ {
+ commit_message: params[:commit_message],
+ file_path: update_dashboard_path,
+ file_content: update_dashboard_content,
+ encoding: 'text',
+ branch_name: branch,
+ start_branch: repository.branch_exists?(branch) ? branch : project.default_branch
+ }
+ end
+
+ def dashboard_details
+ {
+ path: update_dashboard_path,
+ display_name: ::Metrics::Dashboard::ProjectDashboardService.name_for_path(update_dashboard_path),
+ default: false,
+ system_dashboard: false
+ }
+ end
+
+ def push_authorized?
+ Gitlab::UserAccess.new(current_user, project: project).can_push_to_branch?(branch)
+ end
+
+ def branch
+ @branch ||= begin
+ throw(:error, error(_('There was an error updating the dashboard, branch name is invalid.'), :bad_request)) unless valid_branch_name?
+ throw(:error, error(_('There was an error updating the dashboard, branch named: %{branch} already exists.') % { branch: params[:branch] }, :bad_request)) unless new_or_default_branch?
+
+ params[:branch]
+ end
+ end
+
+ def new_or_default_branch?
+ !repository.branch_exists?(params[:branch]) || project.default_branch == params[:branch]
+ end
+
+ def valid_branch_name?
+ Gitlab::GitRefValidator.validate(params[:branch])
+ end
+
+ def update_dashboard_path
+ File.join(USER_DASHBOARDS_DIR, file_name)
+ end
+
+ def target_file_type_valid?
+ File.extname(params[:file_name]) == ALLOWED_FILE_TYPE
+ end
+
+ def file_name
+ @file_name ||= begin
+ throw(:error, error(_('The file name should have a .yml extension'), :bad_request)) unless target_file_type_valid?
+
+ File.basename(CGI.unescape(params[:file_name]))
+ end
+ end
+
+ def update_dashboard_content
+ ::PerformanceMonitoring::PrometheusDashboard.from_json(params[:file_content]).to_yaml
+ end
+
+ def repository
+ @repository ||= project.repository
+ end
+ end
+ end
+end