Skip to content
Snippets Groups Projects
Commit 98d693f9 authored by Laura Montemayor's avatar Laura Montemayor
Browse files

Adds sha argument to lint

Changelog: added
parent 7ac4827e
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -18,6 +18,10 @@ class ConfigResolver < BaseResolver
required: true,
description: 'The project of the CI config.'
 
argument :sha, GraphQL::STRING_TYPE,
required: false,
description: "Sha for the pipeline."
argument :content, GraphQL::STRING_TYPE,
required: true,
description: "Contents of `.gitlab-ci.yml`."
Loading
Loading
@@ -26,11 +30,11 @@ class ConfigResolver < BaseResolver
required: false,
description: 'Run pipeline creation simulation, or only do static check.'
 
def resolve(project_path:, content:, dry_run: false)
def resolve(project_path:, content:, sha: nil, dry_run: false)
project = authorized_find!(project_path: project_path)
 
result = ::Gitlab::Ci::Lint
.new(project: project, current_user: context[:current_user])
.new(project: project, current_user: context[:current_user], sha: sha)
.validate(content, dry_run: dry_run)
 
response(result).merge(merged_yaml: result.merged_yaml)
Loading
Loading
Loading
Loading
@@ -52,6 +52,7 @@ Returns [`CiConfig`](#ciconfig).
| <a id="queryciconfigcontent"></a>`content` | [`String!`](#string) | Contents of `.gitlab-ci.yml`. |
| <a id="queryciconfigdryrun"></a>`dryRun` | [`Boolean`](#boolean) | Run pipeline creation simulation, or only do static check. |
| <a id="queryciconfigprojectpath"></a>`projectPath` | [`ID!`](#id) | The project of the CI config. |
| <a id="queryciconfigsha"></a>`sha` | [`String`](#string) | Sha for the pipeline. |
 
### `Query.containerRepository`
 
Loading
Loading
Loading
Loading
@@ -15,10 +15,11 @@
 
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :repository, creator: user, namespace: user.namespace) }
let_it_be(:sha) { nil }
 
subject(:response) do
resolve(described_class,
args: { project_path: project.full_path, content: content },
args: { project_path: project.full_path, content: content, sha: sha },
ctx: { current_user: user })
end
 
Loading
Loading
@@ -36,10 +37,20 @@
File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci_includes.yml'))
end
 
it 'lints the ci config file and returns the merged yaml file' do
expect(response[:merged_yaml]).to eq(content)
expect(response[:status]).to eq(:valid)
expect(response[:errors]).to be_empty
context 'with a sha' do
let(:sha) { '1231231' }
it 'lints the ci config file and returns the merged yaml file' do
expect(response[:status]).to eq(:valid)
expect(::Gitlab::Ci::Lint).to have_received(:new).with(current_user: user, project: project, sha: sha)
end
end
context 'without a sha' do
it 'lints the ci config file and returns the merged yaml file' do
expect(response[:merged_yaml]).to eq(content)
expect(response[:errors]).to be_empty
end
end
end
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment