diff --git a/danger/specs/Dangerfile b/danger/specs/Dangerfile index bfc8a4b234442eaf58c3d8dc803bf4bca87be60a..1b6e2a5b34a6e3d1009248737fb0acbe95617f7a 100644 --- a/danger/specs/Dangerfile +++ b/danger/specs/Dangerfile @@ -1,5 +1,7 @@ # frozen_string_literal: true +return if helper.revert_mr? + NO_SPECS_LABELS = [ 'maintenance::pipelines', 'maintenance::refactor', diff --git a/spec/tooling/danger/specs/feature_category_suggestion_spec.rb b/spec/tooling/danger/specs/feature_category_suggestion_spec.rb index ea8a00afac1dcbb5d64640907763c6ce7b88d799..a95d6276eef56a2be32f2409c85389093264f5d0 100644 --- a/spec/tooling/danger/specs/feature_category_suggestion_spec.rb +++ b/spec/tooling/danger/specs/feature_category_suggestion_spec.rb @@ -12,6 +12,7 @@ let(:fake_danger) { DangerSpecHelper.fake_danger.include(Tooling::Danger::Specs) } let(:fake_project_helper) { instance_double('Tooling::Danger::ProjectHelper') } let(:filename) { 'spec/foo_spec.rb' } + let(:feature_category) { ', feature_category: <see config/feature_categories.yml>' } let(:template) do <<~SUGGESTION_MARKDOWN.chomp @@ -35,22 +36,22 @@ " end", " describe 'GET \"time_summary\"' do", " end", - " RSpec.describe Projects::SummaryController do", + " RSpec.describe Projects::SummaryController, foo: :bar do", " let_it_be(:user) { create(:user) }", " end", " describe 'GET \"time_summary\"' do", " end", " \n", - "RSpec.describe Projects :aggregate_failures,", + "RSpec.describe Projects, :aggregate_failures,", " feature_category :team_planning do", " \n", - "RSpec.describe Epics :aggregate_failures,", + "RSpec.describe Epics, :aggregate_failures,", " ee: true do", "\n", - "RSpec.describe Issues :aggregate_failures,", + "RSpec.describe Issues, :aggregate_failures,", " feature_category: :team_planning do", "\n", - "RSpec.describe MergeRequest :aggregate_failures,", + "RSpec.describe MergeRequest, :aggregate_failures,", " :js,", " feature_category: :team_planning do" ] @@ -63,12 +64,12 @@ "+ let_it_be(:user) { create(:user) }", "- end", "+ describe 'GET \"time_summary\"' do", - "+ RSpec.describe Projects::SummaryController do", - "+RSpec.describe Projects :aggregate_failures,", + "+ RSpec.describe Projects::SummaryController, foo: :bar do", + "+RSpec.describe Projects, :aggregate_failures,", "+ feature_category: :team_planning do", - "+RSpec.describe Epics :aggregate_failures,", + "+RSpec.describe Epics, :aggregate_failures,", "+ ee: true do", - "+RSpec.describe Issues :aggregate_failures,", + "+RSpec.describe Issues, :aggregate_failures,", "+RSpec.describe MergeRequest :aggregate_failures,", "+ :js,", "+ feature_category: :team_planning do", @@ -86,9 +87,9 @@ it 'adds suggestions at the correct lines', :aggregate_failures do [ - { suggested_line: "RSpec.describe Projects::SummaryController do", number: 5 }, - { suggested_line: " RSpec.describe Projects::SummaryController do", number: 10 }, - { suggested_line: "RSpec.describe Epics :aggregate_failures,", number: 19 } + { suggested_line: "RSpec.describe Projects::SummaryController#{feature_category} do", number: 5 }, + { suggested_line: " RSpec.describe Projects::SummaryController, foo: :bar#{feature_category} do", number: 10 }, + { suggested_line: "RSpec.describe Epics, :aggregate_failures#{feature_category},", number: 19 } ].each do |test_case| comment = format(template, suggested_line: test_case[:suggested_line]) diff --git a/tooling/danger/specs/feature_category_suggestion.rb b/tooling/danger/specs/feature_category_suggestion.rb index 00cb99f368bfc7fc31ae8bc69743686248335264..c34f6e23ab89cd976883c93c343ab4142ae60d6c 100644 --- a/tooling/danger/specs/feature_category_suggestion.rb +++ b/tooling/danger/specs/feature_category_suggestion.rb @@ -31,11 +31,36 @@ def suggest next if lines_to_check.any? { |line| line.include?(FEATURE_CATEGORY_KEYWORD) } - suggested_line = file_lines[line_number] + suggested_line = add_feature_category(file_lines[line_number]) markdown(comment(SUGGESTION, suggested_line), file: filename, line: line_number.succ) end end + + private + + def add_feature_category(line) + return line unless line + + line = line.dup + + feature_category = 'feature_category: <see config/feature_categories.yml>' + + # RSpec.describe Epics do + index = line.index(/ do\b/) + + if index + # RSpec.describe Epics, feature_category: ... do + line[index] = ", #{feature_category} " + else + # RSpec.describe Epics, :aggregate_failures, + index = line.index(/,$/) + # RSpec.describe Epics, :aggregate_failures, feature_category: ..., + line[index] = ", #{feature_category}," if index + end + + line + end end end end