Commit e812cfc1 authored by Arturo Herrero's avatar Arturo Herrero

Merge branch 'lm-empty-state-config' into 'master'

Updates use of sha for linting

See merge request gitlab-org/gitlab!55865
parents a7762c7c 7e2d97df
......@@ -99,10 +99,18 @@ module Gitlab
initial_config
end
def find_sha(project)
branches = project&.repository&.branches || []
unless branches.empty?
project.repository.root_ref_sha
end
end
def build_context(project:, sha:, user:, parent_pipeline:)
Config::External::Context.new(
project: project,
sha: sha || project&.repository&.root_ref_sha,
sha: sha || find_sha(project),
user: user,
parent_pipeline: parent_pipeline,
variables: project&.predefined_variables&.to_runner_variables)
......
......@@ -21,7 +21,7 @@ module Gitlab
def initialize(project:, current_user:, sha: nil)
@project = project
@current_user = current_user
@sha = sha || project.repository.commit.sha
@sha = sha || project.repository.commit&.sha
end
def validate(content, dry_run: false)
......
......@@ -406,6 +406,24 @@ RSpec.describe API::Lint do
end
end
context 'with an empty repository' do
let_it_be(:empty_project) { create(:project_empty_repo) }
let_it_be(:yaml_content) do
File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))
end
before do
empty_project.add_developer(api_user)
end
it 'passes validation without errors' do
post api("/projects/#{empty_project.id}/ci/lint", api_user), params: { content: yaml_content }
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['valid']).to eq(true)
expect(json_response['errors']).to eq([])
end
end
context 'when unauthenticated' do
let_it_be(:api_user) { nil }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment