Commit 90f37b84 authored by Imre Farkas's avatar Imre Farkas

Merge branch 'lm-add-sha-to-ci-config-resolver' into 'master'

Adds sha argument to lint

See merge request gitlab-org/gitlab!64415
parents 04d542bb a728acee
...@@ -18,6 +18,10 @@ module Resolvers ...@@ -18,6 +18,10 @@ module Resolvers
required: true, required: true,
description: 'The project of the CI config.' description: 'The project of the CI config.'
argument :sha, GraphQL::STRING_TYPE,
required: false,
description: "Sha for the pipeline."
argument :content, GraphQL::STRING_TYPE, argument :content, GraphQL::STRING_TYPE,
required: true, required: true,
description: "Contents of `.gitlab-ci.yml`." description: "Contents of `.gitlab-ci.yml`."
...@@ -26,11 +30,11 @@ module Resolvers ...@@ -26,11 +30,11 @@ module Resolvers
required: false, required: false,
description: 'Run pipeline creation simulation, or only do static check.' 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) project = authorized_find!(project_path: project_path)
result = ::Gitlab::Ci::Lint 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) .validate(content, dry_run: dry_run)
response(result).merge(merged_yaml: result.merged_yaml) response(result).merge(merged_yaml: result.merged_yaml)
......
...@@ -52,6 +52,7 @@ Returns [`CiConfig`](#ciconfig). ...@@ -52,6 +52,7 @@ Returns [`CiConfig`](#ciconfig).
| <a id="queryciconfigcontent"></a>`content` | [`String!`](#string) | Contents of `.gitlab-ci.yml`. | | <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="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="queryciconfigprojectpath"></a>`projectPath` | [`ID!`](#id) | The project of the CI config. |
| <a id="queryciconfigsha"></a>`sha` | [`String`](#string) | Sha for the pipeline. |
### `Query.containerRepository` ### `Query.containerRepository`
......
...@@ -15,14 +15,15 @@ RSpec.describe Resolvers::Ci::ConfigResolver do ...@@ -15,14 +15,15 @@ RSpec.describe Resolvers::Ci::ConfigResolver do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :repository, creator: user, namespace: user.namespace) } let_it_be(:project) { create(:project, :repository, creator: user, namespace: user.namespace) }
let_it_be(:sha) { nil }
subject(:response) do subject(:response) do
resolve(described_class, 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 }) ctx: { current_user: user })
end end
context 'with a valid .gitlab-ci.yml' do shared_examples 'a valid config file' do
let(:fake_result) do let(:fake_result) do
::Gitlab::Ci::Lint::Result.new( ::Gitlab::Ci::Lint::Result.new(
merged_yaml: content, merged_yaml: content,
...@@ -37,9 +38,22 @@ RSpec.describe Resolvers::Ci::ConfigResolver do ...@@ -37,9 +38,22 @@ RSpec.describe Resolvers::Ci::ConfigResolver do
end end
it 'lints the ci config file and returns the merged yaml file' do 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[:status]).to eq(:valid)
expect(response[:merged_yaml]).to eq(content)
expect(response[:errors]).to be_empty expect(response[:errors]).to be_empty
expect(::Gitlab::Ci::Lint).to have_received(:new).with(current_user: user, project: project, sha: sha)
end
end
context 'with a valid .gitlab-ci.yml' do
context 'with a sha' do
let(:sha) { '1231231' }
it_behaves_like 'a valid config file'
end
context 'without a sha' do
it_behaves_like 'a valid config file'
end end
end end
......
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