Skip to content
Snippets Groups Projects
Commit f1a57558 authored by GitLab Bot's avatar GitLab Bot
Browse files

Add latest changes from gitlab-org/gitlab@master

parent 1ae627c6
No related branches found
No related tags found
No related merge requests found
Showing
with 42290 additions and 3892 deletions
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Loading
Loading
@@ -18,7 +18,8 @@ class AutomatedCleanup
].freeze
 
def self.ee?
ENV['CI_PROJECT_NAME'] == 'gitlab-ee' || File.exist?('CHANGELOG-EE.md')
# Support former project name for `dev`
%w[gitlab gitlab-ee].include?(ENV['CI_PROJECT_NAME'])
end
 
def initialize(project_path: ENV['CI_PROJECT_PATH'], gitlab_token: ENV['GITLAB_BOT_REVIEW_APPS_CLEANUP_TOKEN'])
Loading
Loading
Loading
Loading
@@ -12,7 +12,8 @@ end
 
module Trigger
def self.ee?
ENV['CI_PROJECT_NAME'] == 'gitlab-ee' || File.exist?('CHANGELOG-EE.md')
# Support former project name for `dev`
%w[gitlab gitlab-ee].include?(ENV['CI_PROJECT_NAME'])
end
 
class Base
Loading
Loading
Loading
Loading
@@ -94,14 +94,24 @@ describe ApplicationController do
request.path = '/-/peek'
end
 
it_behaves_like 'not setting gon variables'
# TODO:
# remove line below once `privacy_policy_update_callout`
# feature flag is removed and `gon` reverts back to
# to not setting any variables.
it_behaves_like 'setting gon variables'
# it_behaves_like 'not setting gon variables'
end
end
 
context 'with json format' do
let(:format) { :json }
 
it_behaves_like 'not setting gon variables'
# TODO:
# remove line below once `privacy_policy_update_callout`
# feature flag is removed and `gon` reverts back to
# to not setting any variables.
it_behaves_like 'setting gon variables'
# it_behaves_like 'not setting gon variables'
end
end
 
Loading
Loading
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Ci::Build::Rules::Rule::Clause::Changes do
describe '#satisfied_by?' do
it_behaves_like 'a glob matching rule' do
let(:pipeline) { build(:ci_pipeline) }
before do
allow(pipeline).to receive(:modified_paths).and_return(files.keys)
end
subject { described_class.new(globs).satisfied_by?(pipeline, nil) }
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Ci::Build::Rules::Rule::Clause::Exists do
describe '#satisfied_by?' do
it_behaves_like 'a glob matching rule' do
let(:project) { create(:project, :custom_repo, files: files) }
let(:pipeline) { build(:ci_pipeline, project: project, sha: project.repository.head_commit.sha) }
subject { described_class.new(globs).satisfied_by?(pipeline, nil) }
end
end
end
Loading
Loading
@@ -103,6 +103,52 @@ describe Gitlab::Ci::Config::Entry::Rules::Rule do
end
end
 
context 'when using a long list as an invalid changes: clause' do
let(:config) { { changes: ['app/'] * 51 } }
it { is_expected.not_to be_valid }
it 'returns errors' do
expect(subject.errors).to include(/changes is too long \(maximum is 50 characters\)/)
end
end
context 'when using a exists: clause' do
let(:config) { { exists: %w[app/ lib/ spec/ other/* paths/**/*.rb] } }
it { is_expected.to be_valid }
end
context 'when using a string as an invalid exists: clause' do
let(:config) { { exists: 'a regular string' } }
it { is_expected.not_to be_valid }
it 'reports an error about invalid policy' do
expect(subject.errors).to include(/should be an array of strings/)
end
end
context 'when using a list as an invalid exists: clause' do
let(:config) { { exists: [1, 2] } }
it { is_expected.not_to be_valid }
it 'returns errors' do
expect(subject.errors).to include(/exists should be an array of strings/)
end
end
context 'when using a long list as an invalid exists: clause' do
let(:config) { { exists: ['app/'] * 51 } }
it { is_expected.not_to be_valid }
it 'returns errors' do
expect(subject.errors).to include(/exists is too long \(maximum is 50 characters\)/)
end
end
context 'specifying a delayed job' do
let(:config) { { if: '$THIS || $THAT', when: 'delayed', start_in: '15 minutes' } }
 
Loading
Loading
@@ -198,6 +244,12 @@ describe Gitlab::Ci::Config::Entry::Rules::Rule do
expect(entry.value).to eq(config)
end
end
context 'when using a exists: clause' do
let(:config) { { exists: %w[app/ lib/ spec/ other/* paths/**/*.rb] } }
it { is_expected.to eq(config) }
end
end
 
describe '.default' do
Loading
Loading
Loading
Loading
@@ -88,28 +88,28 @@ describe Gitlab::Danger::Helper do
 
it 'returns true if CI_PROJECT_NAME if set to gitlab' do
stub_env('CI_PROJECT_NAME', 'gitlab')
expect(File).not_to receive(:exist?)
expect(Dir).not_to receive(:exist?)
 
is_expected.to be_truthy
end
 
it 'delegates to CHANGELOG-EE.md existence if CI_PROJECT_NAME is set to something else' do
stub_env('CI_PROJECT_NAME', 'something else')
expect(File).to receive(:exist?).with('../../CHANGELOG-EE.md') { true }
expect(Dir).to receive(:exist?).with('../../ee') { true }
 
is_expected.to be_truthy
end
 
it 'returns true if CHANGELOG-EE.md exists' do
it 'returns true if ee exists' do
stub_env('CI_PROJECT_NAME', nil)
expect(File).to receive(:exist?).with('../../CHANGELOG-EE.md') { true }
expect(Dir).to receive(:exist?).with('../../ee') { true }
 
is_expected.to be_truthy
end
 
it "returns false if CHANGELOG-EE.md doesn't exist" do
it "returns false if ee doesn't exist" do
stub_env('CI_PROJECT_NAME', nil)
expect(File).to receive(:exist?).with('../../CHANGELOG-EE.md') { false }
expect(Dir).to receive(:exist?).with('../../ee') { false }
 
is_expected.to be_falsy
end
Loading
Loading
Loading
Loading
@@ -1755,6 +1755,30 @@ describe Ci::Pipeline, :mailer do
end
end
 
describe '#all_worktree_paths' do
let(:files) { { 'main.go' => '', 'mocks/mocks.go' => '' } }
let(:project) { create(:project, :custom_repo, files: files) }
let(:pipeline) { build(:ci_pipeline, project: project, sha: project.repository.head_commit.sha) }
it 'returns all file paths cached' do
expect(project.repository).to receive(:ls_files).with(pipeline.sha).once.and_call_original
expect(pipeline.all_worktree_paths).to eq(files.keys)
expect(pipeline.all_worktree_paths).to eq(files.keys)
end
end
describe '#top_level_worktree_paths' do
let(:files) { { 'main.go' => '', 'mocks/mocks.go' => '' } }
let(:project) { create(:project, :custom_repo, files: files) }
let(:pipeline) { build(:ci_pipeline, project: project, sha: project.repository.head_commit.sha) }
it 'returns top-level file paths cached' do
expect(project.repository).to receive(:tree).with(pipeline.sha).once.and_call_original
expect(pipeline.top_level_worktree_paths).to eq(['main.go'])
expect(pipeline.top_level_worktree_paths).to eq(['main.go'])
end
end
describe '#has_kubernetes_active?' do
context 'when kubernetes is active' do
context 'when user configured kubernetes from CI/CD > Clusters' do
Loading
Loading
# frozen_string_literal: true
require 'spec_helper'
describe Ci::CreatePipelineService do
context 'rules' do
let(:user) { create(:admin) }
let(:ref) { 'refs/heads/master' }
let(:source) { :push }
let(:service) { described_class.new(project, user, { ref: ref }) }
let(:pipeline) { service.execute(source) }
let(:build_names) { pipeline.builds.pluck(:name) }
before do
stub_ci_pipeline_yaml_file(config)
allow_any_instance_of(Ci::BuildScheduleWorker).to receive(:perform).and_return(true)
end
context 'exists:' do
let(:config) do
<<-EOY
regular-job:
script: 'echo Hello, World!'
rules-job:
script: "echo hello world, $CI_COMMIT_REF_NAME"
rules:
- exists:
- README.md
when: manual
- exists:
- app.rb
when: on_success
delayed-job:
script: "echo See you later, World!"
rules:
- exists:
- README.md
when: delayed
start_in: 4 hours
EOY
end
let(:regular_job) { pipeline.builds.find_by(name: 'regular-job') }
let(:rules_job) { pipeline.builds.find_by(name: 'rules-job') }
let(:delayed_job) { pipeline.builds.find_by(name: 'delayed-job') }
context 'with matches' do
let(:project) { create(:project, :custom_repo, files: { 'README.md' => '' }) }
it 'creates two jobs' do
expect(pipeline).to be_persisted
expect(build_names).to contain_exactly('regular-job', 'rules-job', 'delayed-job')
end
it 'sets when: for all jobs' do
expect(regular_job.when).to eq('on_success')
expect(rules_job.when).to eq('manual')
expect(delayed_job.when).to eq('delayed')
expect(delayed_job.options[:start_in]).to eq('4 hours')
end
end
context 'with matches on the second rule' do
let(:project) { create(:project, :custom_repo, files: { 'app.rb' => '' }) }
it 'includes both jobs' do
expect(pipeline).to be_persisted
expect(build_names).to contain_exactly('regular-job', 'rules-job')
end
it 'sets when: for the created rules job based on the second clause' do
expect(regular_job.when).to eq('on_success')
expect(rules_job.when).to eq('on_success')
end
end
context 'without matches' do
let(:project) { create(:project, :custom_repo, files: { 'useless_script.rb' => '' }) }
it 'only persists the job without rules' do
expect(pipeline).to be_persisted
expect(regular_job).to be_persisted
expect(rules_job).to be_nil
expect(delayed_job).to be_nil
end
it 'sets when: for the created job' do
expect(regular_job.when).to eq('on_success')
end
end
end
end
end
# frozen_string_literal: true
RSpec.shared_examples 'a glob matching rule' do
using RSpec::Parameterized::TableSyntax
where(:case_name, :globs, :files, :satisfied) do
'exact top-level match' | ['Dockerfile'] | { 'Dockerfile' => '', 'Gemfile' => '' } | true
'exact top-level no match' | ['Dockerfile'] | { 'Gemfile' => '' } | false
'pattern top-level match' | ['Docker*'] | { 'Dockerfile' => '', 'Gemfile' => '' } | true
'pattern top-level no match' | ['Docker*'] | { 'Gemfile' => '' } | false
'exact nested match' | ['project/build.properties'] | { 'project/build.properties' => '' } | true
'exact nested no match' | ['project/build.properties'] | { 'project/README.md' => '' } | false
'pattern nested match' | ['src/**/*.go'] | { 'src/gitlab.com/goproject/goproject.go' => '' } | true
'pattern nested no match' | ['src/**/*.go'] | { 'src/gitlab.com/goproject/README.md' => '' } | false
'ext top-level match' | ['*.go'] | { 'main.go' => '', 'cmd/goproject/main.go' => '' } | true
'ext nested no match' | ['*.go'] | { 'cmd/goproject/main.go' => '' } | false
'ext slash no match' | ['/*.go'] | { 'main.go' => '', 'cmd/goproject/main.go' => '' } | false
end
with_them do
it { is_expected.to eq(satisfied) }
end
end
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