Commit e2b8d49f authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'fix-ee-dir-check-for-danger' into 'master'

Fix ee/ directory detection for Danger roulette (Fix empty roulette reviewers from certain forks)

See merge request gitlab-org/gitlab!74539
parents ffff7832 2d1a8ead
......@@ -7,8 +7,10 @@ require 'danger/plugins/helper'
require 'gitlab/dangerfiles/spec_helper'
require_relative '../../../danger/plugins/project_helper'
require_relative '../../../spec/support/helpers/stub_env'
RSpec.describe Tooling::Danger::ProjectHelper do
include StubENV
include_context "with dangerfile"
let(:fake_danger) { DangerSpecHelper.fake_danger.include(described_class) }
......@@ -341,6 +343,70 @@ RSpec.describe Tooling::Danger::ProjectHelper do
end
end
describe '#ee?' do
subject { project_helper.__send__(:ee?) }
let(:ee_dir) { File.expand_path('../../../ee', __dir__) }
context 'when ENV["CI_PROJECT_NAME"] is set' do
before do
stub_env('CI_PROJECT_NAME', ci_project_name)
end
context 'when ENV["CI_PROJECT_NAME"] is gitlab' do
let(:ci_project_name) { 'gitlab' }
it 'returns true' do
is_expected.to eq(true)
end
end
context 'when ENV["CI_PROJECT_NAME"] is gitlab-ee' do
let(:ci_project_name) { 'gitlab-ee' }
it 'returns true' do
is_expected.to eq(true)
end
end
context 'when ENV["CI_PROJECT_NAME"] is gitlab-foss' do
let(:ci_project_name) { 'gitlab-foss' }
it 'resolves to Dir.exist?' do
expected = Dir.exist?(ee_dir)
expect(Dir).to receive(:exist?).with(ee_dir).and_call_original
is_expected.to eq(expected)
end
end
end
context 'when ENV["CI_PROJECT_NAME"] is absent' do
before do
stub_env('CI_PROJECT_NAME', nil)
expect(Dir).to receive(:exist?).with(ee_dir).and_return(has_ee_dir)
end
context 'when ee/ directory exists' do
let(:has_ee_dir) { true }
it 'returns true' do
is_expected.to eq(true)
end
end
context 'when ee/ directory does not exist' do
let(:has_ee_dir) { false }
it 'returns false' do
is_expected.to eq(false)
end
end
end
end
describe '#file_lines' do
let(:filename) { 'spec/foo_spec.rb' }
let(:file_spy) { spy }
......
......@@ -224,7 +224,7 @@ module Tooling
def ee?
# Support former project name for `dev` and support local Danger run
%w[gitlab gitlab-ee].include?(ENV['CI_PROJECT_NAME']) || Dir.exist?(File.expand_path('../../../ee', __dir__))
%w[gitlab gitlab-ee].include?(ENV['CI_PROJECT_NAME']) || Dir.exist?(File.expand_path('../../ee', __dir__))
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