Skip to content
代码片段 群组 项目
提交 bad3e87e 编辑于 作者: Niko Belokolodov's avatar Niko Belokolodov 提交者: Rémy Coutable
浏览文件

Add Customer Success::Impact Check label when metric category changes

上级 a0638278
No related branches found
No related tags found
无相关合并请求
# frozen_string_literal: true
markdown(customer_success.build_message)
# frozen_string_literal: true
require_relative '../../tooling/danger/customer_success'
module Danger
class CustomerSuccess < ::Danger::Plugin
include Tooling::Danger::CustomerSuccess
end
end
# frozen_string_literal: true
require 'rspec-parameterized'
require 'gitlab-dangerfiles'
require 'gitlab/dangerfiles/spec_helper'
require_relative '../../../tooling/danger/customer_success'
RSpec.describe Tooling::Danger::CustomerSuccess do
include_context "with dangerfile"
let(:fake_danger) { DangerSpecHelper.fake_danger.include(described_class) }
let(:customer_success) { fake_danger.new(helper: fake_helper) }
describe 'customer success danger' do
using RSpec::Parameterized::TableSyntax
where do
{
'with data category changes to Ops and no Customer Success::Impact Check label' => {
modified_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml app/models/user.rb),
changed_lines: ['-data_category: cat1', '+data_category: operational'],
customer_labeled: false,
impacted: true,
impacted_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml)
},
'with data category changes and Customer Success::Impact Check label' => {
modified_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml),
changed_lines: ['-data_category: cat1', '+data_category: operational'],
customer_labeled: true,
impacted: false,
impacted_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml)
},
'with metric file changes and no data category changes' => {
modified_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml),
changed_lines: ['-product_stage: growth'],
customer_labeled: false,
impacted: false,
impacted_files: []
},
'with data category changes from Ops' => {
modified_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml app/models/user.rb),
changed_lines: ['-data_category: operational', '+data_category: cat2'],
customer_labeled: false,
impacted: true,
impacted_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml)
},
'with data category removed' => {
modified_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml app/models/user.rb),
changed_lines: ['-data_category: operational'],
customer_labeled: false,
impacted: true,
impacted_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml)
},
'with data category added' => {
modified_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml app/models/user.rb),
changed_lines: ['+data_category: operational'],
customer_labeled: false,
impacted: true,
impacted_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml)
},
'with data category in uppercase' => {
modified_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml app/models/user.rb),
changed_lines: ['+data_category: Operational'],
customer_labeled: false,
impacted: true,
impacted_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml)
}
}
end
with_them do
before do
allow(fake_helper).to receive(:modified_files).and_return(modified_files)
allow(fake_helper).to receive(:changed_lines).and_return(changed_lines)
allow(fake_helper).to receive(:has_scoped_label_with_scope?).and_return(customer_labeled)
allow(fake_helper).to receive(:markdown_list).with(impacted_files)
.and_return(impacted_files.map { |item| "* `#{item}`" }.join("\n"))
end
it 'generates correct message' do
expect(customer_success.build_message).to match_expected_message
end
end
end
def match_expected_message
return be_nil unless impacted
start_with(described_class::CHANGED_SCHEMA_MESSAGE).and(include(*impacted_files))
end
end
# frozen_string_literal: true
module Tooling
module Danger
module CustomerSuccess
CHANGED_SCHEMA_MESSAGE = <<~MSG
Notification to the Customer Success about changes to files with possible breaking downstream processes, add label `Customer Success::Impact Check`.
/label ~"Customer Success::Impact Check"
The following files require a review:
MSG
FILE_PATH_REGEX = %r{((ee|jh)/)?config/metrics/.+\.yml}.freeze
CATEGORY_CHANGED = /data_category: operational/i.freeze
def build_message
return unless impacted?
CHANGED_SCHEMA_MESSAGE + helper.markdown_list(impacted_files)
end
private
def impacted?
!helper.has_scoped_label_with_scope?('Customer Success') && impacted_files.any?
end
def impacted_files
@impacted_files ||=
metric_files.select do |file|
helper.changed_lines(file).any? { |change| metric_category_changed?(change) }
end.compact
end
def metric_files
helper.modified_files.grep(FILE_PATH_REGEX)
end
def metric_category_changed?(change)
change =~ CATEGORY_CHANGED
end
end
end
end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册