Commit 6dd183a5 authored by Rémy Coutable's avatar Rémy Coutable

Update gitlab-dangerfiles to 2.6.1

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 2d7120f3
......@@ -2,14 +2,24 @@
require 'gitlab-dangerfiles'
gitlab_dangerfiles = Gitlab::Dangerfiles::Engine.new(self)
gitlab_dangerfiles.import_plugins
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__))
end
return if helper.release_automation?
project_name = ee? ? 'gitlab' : 'gitlab-foss'
danger.import_plugin('danger/plugins/*.rb')
Gitlab::Dangerfiles.for_project(self, project_name) do |gitlab_dangerfiles|
gitlab_dangerfiles.import_plugins
gitlab_dangerfiles.import_dangerfiles
unless helper.release_automation?
danger.import_plugin('danger/plugins/*.rb')
gitlab_dangerfiles.import_dangerfiles(except: %w[simple_roulette])
gitlab_dangerfiles.config.files_to_category = ProjectHelper::CATEGORIES
end
end
return if helper.release_automation?
project_helper.rule_names.each do |rule|
danger.import_dangerfile(path: File.join('danger', rule))
......
......@@ -400,7 +400,7 @@ group :development, :test do
end
group :development, :test, :danger do
gem 'gitlab-dangerfiles', '~> 2.5.0', require: false
gem 'gitlab-dangerfiles', '~> 2.6.1', require: false
end
group :development, :test, :coverage do
......
......@@ -222,7 +222,7 @@ GEM
css_parser (1.7.0)
addressable
daemons (1.3.1)
danger (8.4.1)
danger (8.4.2)
claide (~> 1.0)
claide-plugins (>= 0.9.2)
colored2 (~> 3.1)
......@@ -458,7 +458,7 @@ GEM
terminal-table (~> 1.5, >= 1.5.1)
gitlab-chronic (0.10.5)
numerizer (~> 0.2)
gitlab-dangerfiles (2.5.0)
gitlab-dangerfiles (2.6.1)
danger (>= 8.3.1)
danger-gitlab (>= 8.0.0)
gitlab-experiment (0.6.5)
......@@ -1475,7 +1475,7 @@ DEPENDENCIES
gitaly (~> 14.4.0.pre.rc43)
github-markup (~> 1.7.0)
gitlab-chronic (~> 0.10.5)
gitlab-dangerfiles (~> 2.5.0)
gitlab-dangerfiles (~> 2.6.1)
gitlab-experiment (~> 0.6.5)
gitlab-fog-azure-rm (~> 1.2.0)
gitlab-labkit (~> 0.21.1)
......
......@@ -17,7 +17,7 @@ MSG
return unless helper.ci?
template_paths_to_review = project_helper.changes_by_category[:ci_template]
template_paths_to_review = helper.changes_by_category[:ci_template]
if gitlab.mr_labels.include?('ci::templates') || template_paths_to_review.any?
message 'This merge request adds or changes files that require a ' \
......
......@@ -51,7 +51,7 @@ end
return unless helper.ci?
return if gitlab.mr_labels.include?(DATABASE_APPROVED_LABEL)
db_paths_to_review = project_helper.changes_by_category[:database]
db_paths_to_review = helper.changes_by_category[:database]
if gitlab.mr_labels.include?('database') || db_paths_to_review.any?
message 'This merge request adds or changes files that require a ' \
......
......@@ -13,7 +13,7 @@ For more information, see:
- The [definition of done](https://docs.gitlab.com/ee/development/contributing/merge_request_workflow.html#definition-of-done) documentation.
MSG
docs_paths_to_review = project_helper.changes_by_category[:docs]
docs_paths_to_review = helper.changes_by_category[:docs]
# Documentation should be updated for feature::addition and feature::enhancement
if docs_paths_to_review.empty?
......
......@@ -12,7 +12,7 @@ For MR review guidelines, see the [Service Ping review guidelines](https://docs.
MSG
# exit if not matching files or if no product intelligence labels
product_intelligence_paths_to_review = project_helper.changes_by_category[:product_intelligence]
product_intelligence_paths_to_review = helper.changes_by_category[:product_intelligence]
labels_to_add = product_intelligence.missing_labels
return if product_intelligence_paths_to_review.empty? || labels_to_add.empty?
......
......@@ -89,7 +89,7 @@ def markdown_row_for_spins(category, spins_array)
"| #{helper.label_for_category(category)} | #{reviewer_note} | #{maintainer_note} |"
end
changes = project_helper.changes_by_category
changes = helper.changes_by_category
# Ignore any files that are known but uncategorized. Prompt for any unknown files
changes.delete(:none)
......@@ -114,9 +114,7 @@ categories << :product_intelligence if helper.mr_labels.include?("product intell
categories.delete(:product_intelligence) unless helper.mr_labels.include?("growth experiment")
if changes.any?
project = project_helper.project_name
random_roulette_spins = roulette.spin(project, categories, timezone_experiment: false)
random_roulette_spins = roulette.spin(nil, categories, timezone_experiment: false)
rows = random_roulette_spins.map do |spin|
markdown_row_for_spins(spin.category, [spin])
......
......@@ -14,7 +14,7 @@ SPECIALIZATIONS = {
feature_flag: 'feature flag'
}.freeze
labels_to_add = project_helper.changes_by_category.each_with_object([]) do |(category, _changes), memo|
labels_to_add = helper.changes_by_category.each_with_object([]) do |(category, _changes), memo|
label = SPECIALIZATIONS[category]
next unless label
next if gitlab.mr_labels.include?(label)
......
......@@ -50,7 +50,7 @@ if has_ee_app_changes && has_spec_changes && !(has_app_changes || has_ee_spec_ch
end
# Forbidding a new file addition under `/spec/controllers` or `/ee/spec/controllers`
if project_helper.changes.added.files.grep(%r{^(ee/)?spec/controllers/}).any?
if helper.changes.added.files.grep(%r{^(ee/)?spec/controllers/}).any?
warn CONTROLLER_SPEC_DEPRECATION_MESSAGE
end
......
......@@ -3,7 +3,7 @@
require 'rspec-parameterized'
require 'gitlab-dangerfiles'
require 'danger'
require 'danger/plugins/helper'
require 'danger/plugins/internal/helper'
require 'gitlab/dangerfiles/spec_helper'
require_relative '../../../danger/plugins/project_helper'
......@@ -20,22 +20,7 @@ RSpec.describe Tooling::Danger::ProjectHelper do
before do
allow(project_helper).to receive(:helper).and_return(fake_helper)
end
describe '#changes' do
it 'returns an array of Change objects' do
expect(project_helper.changes).to all(be_an(Gitlab::Dangerfiles::Change))
end
it 'groups changes by change type' do
changes = project_helper.changes
expect(changes.added.files).to eq(added_files)
expect(changes.modified.files).to eq(modified_files)
expect(changes.deleted.files).to eq(deleted_files)
expect(changes.renamed_before.files).to eq([renamed_before_file])
expect(changes.renamed_after.files).to eq([renamed_after_file])
end
allow(fake_helper).to receive(:config).and_return(double(files_to_category: described_class::CATEGORIES))
end
describe '#categories_for_file' do
......@@ -247,7 +232,7 @@ RSpec.describe Tooling::Danger::ProjectHelper do
end
with_them do
subject { project_helper.categories_for_file(path) }
subject { project_helper.helper.categories_for_file(path) }
it { is_expected.to eq(expected_categories) }
end
......@@ -275,7 +260,7 @@ RSpec.describe Tooling::Danger::ProjectHelper do
changed_files.each do |file|
allow(fake_git).to receive(:diff_for_file).with(file) { double(:diff, patch: patch) }
expect(project_helper.categories_for_file(file)).to eq(expected_categories)
expect(project_helper.helper.categories_for_file(file)).to eq(expected_categories)
end
end
end
......@@ -321,93 +306,13 @@ RSpec.describe Tooling::Danger::ProjectHelper do
it 'returns all changed files starting with ee/' do
changes = double
expect(project_helper).to receive(:changes).and_return(changes)
expect(fake_helper).to receive(:changes).and_return(changes)
expect(changes).to receive(:files).and_return(%w[fr/ee/beer.rb ee/wine.rb ee/lib/ido.rb ee.k])
is_expected.to match_array(%w[ee/wine.rb ee/lib/ido.rb])
end
end
describe '#project_name' do
subject { project_helper.project_name }
it 'returns gitlab if ee? returns true' do
expect(project_helper).to receive(:ee?) { true }
is_expected.to eq('gitlab')
end
it 'returns gitlab-ce if ee? returns false' do
expect(project_helper).to receive(:ee?) { false }
is_expected.to eq('gitlab-foss')
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 }
......
......@@ -3,7 +3,7 @@
require 'rspec-parameterized'
require 'gitlab-dangerfiles'
require 'danger'
require 'danger/plugins/helper'
require 'danger/plugins/internal/helper'
require 'gitlab/dangerfiles/spec_helper'
require_relative '../../../tooling/danger/specs'
......
......@@ -159,8 +159,8 @@ module Tooling
def required_reasons
[].tap do |reasons|
reasons << :db_changes if project_helper.changes.added.has_category?(:migration)
reasons << :feature_flag_removed if project_helper.changes.deleted.has_category?(:feature_flag)
reasons << :db_changes if helper.changes.added.has_category?(:migration)
reasons << :feature_flag_removed if helper.changes.deleted.has_category?(:feature_flag)
end
end
......@@ -221,7 +221,7 @@ module Tooling
end
def categories_need_changelog?
(project_helper.changes.categories - NO_CHANGELOG_CATEGORIES).any?
(helper.changes.categories - NO_CHANGELOG_CATEGORIES).any?
end
def mr_without_no_changelog_label?
......
......@@ -176,18 +176,6 @@ module Tooling
%r{\.js\z} => :frontend
}.freeze
def changes_by_category
helper.changes_by_category(CATEGORIES)
end
def changes
helper.changes(CATEGORIES)
end
def categories_for_file(file)
helper.categories_for_file(file, CATEGORIES)
end
def local_warning_message
"#{MESSAGE_PREFIX} Only the following Danger rules can be run locally: #{LOCAL_RULES.join(', ')}"
end
......@@ -203,11 +191,7 @@ module Tooling
end
def all_ee_changes
changes.files.grep(%r{\Aee/})
end
def project_name
ee? ? 'gitlab' : 'gitlab-foss'
helper.changes.files.grep(%r{\Aee/})
end
def file_lines(filename)
......@@ -223,11 +207,6 @@ module Tooling
def read_file(filename)
File.read(filename)
end
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__))
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