Commit a9167729 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Merge branch 'update-gitlab-dangerfiles-to-2.6.1' into 'master'

Update gitlab-dangerfiles to 2.6.1

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