diff options
Diffstat (limited to 'lib/api/lint.rb')
-rw-r--r-- | lib/api/lint.rb | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/api/lint.rb b/lib/api/lint.rb index 71965fc05c9..26619e6924f 100644 --- a/lib/api/lint.rb +++ b/lib/api/lint.rb @@ -6,12 +6,16 @@ module API resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do desc 'Validates a CI YAML configuration with a namespace' do - detail 'Checks if a project’s latest (HEAD of the project’s default branch) .gitlab-ci.yml configuration is - valid' + detail 'Checks if a project’s .gitlab-ci.yml configuration in a given commit (by default HEAD of the + project’s default branch) is valid' success Entities::Ci::Lint::Result tags %w[ci_lint] + failure [ + { code: 404, message: 'Not found' } + ] end params do + optional :sha, type: String, desc: 'The commit hash or name of a repository branch or tag. Defaults to the HEAD of the project’s default branch' optional :dry_run, type: Boolean, default: false, desc: 'Run pipeline creation simulation, or only do static check. This is false by default' optional :include_jobs, type: Boolean, desc: 'If the list of jobs that would exist in a static check or pipeline simulation should be included in the response. This is false by default' @@ -21,12 +25,13 @@ module API get ':id/ci/lint', urgency: :low do authorize_read_code! - if user_project.commit.present? - content = user_project.repository.gitlab_ci_yml_for(user_project.commit.id, user_project.ci_config_path_or_default) - end + sha = params[:sha] || user_project.repository.root_ref_sha + not_found! 'Commit' unless user_project.commit(sha).present? + + content = user_project.repository.gitlab_ci_yml_for(sha, user_project.ci_config_path_or_default) result = Gitlab::Ci::Lint - .new(project: user_project, current_user: current_user) + .new(project: user_project, current_user: current_user, sha: sha) .validate(content, dry_run: params[:dry_run], ref: params[:ref] || user_project.default_branch) present result, with: Entities::Ci::Lint::Result, current_user: current_user, include_jobs: params[:include_jobs] |