debian-mirror-gitlab/lib/api/lint.rb

72 lines
2.6 KiB
Ruby
Raw Permalink Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2016-09-29 09:46:39 +05:30
module API
2021-01-03 14:25:43 +05:30
class Lint < ::API::Base
2021-01-29 00:20:46 +05:30
feature_category :pipeline_authoring
2016-09-29 09:46:39 +05:30
namespace :ci do
desc 'Validation of .gitlab-ci.yml content'
params do
requires :content, type: String, desc: 'Content of .gitlab-ci.yml'
2021-01-03 14:25:43 +05:30
optional :include_merged_yaml, type: Boolean, desc: 'Whether or not to include merged CI config yaml in the response'
2016-09-29 09:46:39 +05:30
end
post '/lint' do
2021-02-11 23:33:58 +05:30
unauthorized! unless Gitlab::CurrentSettings.signup_enabled? && current_user
2021-01-03 14:25:43 +05:30
result = Gitlab::Ci::YamlProcessor.new(params[:content], user: current_user).execute
2016-09-29 09:46:39 +05:30
status 200
2021-03-08 18:12:59 +05:30
response = if result.errors.empty?
2021-01-29 00:20:46 +05:30
{ status: 'valid', errors: [], warnings: result.warnings }
2021-01-03 14:25:43 +05:30
else
2021-03-08 18:12:59 +05:30
{ status: 'invalid', errors: result.errors, warnings: result.warnings }
2021-01-03 14:25:43 +05:30
end
response.tap do |response|
response[:merged_yaml] = result.merged_yaml if params[:include_merged_yaml]
2016-09-29 09:46:39 +05:30
end
end
end
2021-01-03 14:25:43 +05:30
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
desc 'Validation of .gitlab-ci.yml content' do
detail 'This feature was introduced in GitLab 13.5.'
end
params do
optional :dry_run, type: Boolean, default: false, desc: 'Run pipeline creation simulation, or only do static check.'
end
get ':id/ci/lint' do
authorize! :download_code, user_project
content = user_project.repository.gitlab_ci_yml_for(user_project.commit.id, user_project.ci_config_path_or_default)
result = Gitlab::Ci::Lint
.new(project: user_project, current_user: current_user)
.validate(content, dry_run: params[:dry_run])
present result, with: Entities::Ci::Lint::Result, current_user: current_user
end
end
2021-01-29 00:20:46 +05:30
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
desc 'Validation of .gitlab-ci.yml content' do
detail 'This feature was introduced in GitLab 13.6.'
end
params do
requires :content, type: String, desc: 'Content of .gitlab-ci.yml'
optional :dry_run, type: Boolean, default: false, desc: 'Run pipeline creation simulation, or only do static check.'
end
post ':id/ci/lint' do
2021-02-11 23:33:58 +05:30
authorize! :create_pipeline, user_project
2021-01-29 00:20:46 +05:30
result = Gitlab::Ci::Lint
.new(project: user_project, current_user: current_user)
.validate(params[:content], dry_run: params[:dry_run])
status 200
present result, with: Entities::Ci::Lint::Result, current_user: current_user
end
end
2016-09-29 09:46:39 +05:30
end
end