Commit 62ab989b authored by Alina Mihaila's avatar Alina Mihaila Committed by Rémy Coutable

Add changelog and metrics definition warn in Danger

parent 99830bff
......@@ -8,6 +8,11 @@ Please check the ~telemetry [guide](https://docs.gitlab.com/ee/development/telem
MSG
UPDATE_METRICS_DEFINITIONS_MESSAGE = <<~MSG
When adding, changing, or updating metrics, please update the [Usage Statistics definition table](https://docs.gitlab.com/ee/development/telemetry/usage_ping.html#usage-statistics-definitions).
MSG
tracking_files = [
'lib/gitlab/tracking.rb',
'spec/lib/gitlab/tracking_spec.rb',
......@@ -17,13 +22,14 @@ tracking_files = [
'spec/frontend/tracking_spec.js'
]
usage_data_changed_files = git.modified_files.grep(%r{usage_data})
usage_data_changed_files = helper.changed_files(/usage_data/)
snowplow_events_changed_files = git.modified_files & tracking_files
changed_files = (usage_data_changed_files + snowplow_events_changed_files)
if changed_files.any?
warn format(TELEMETRY_CHANGED_FILES_MESSAGE, changed_files: helper.markdown_list(changed_files))
warn format(UPDATE_METRICS_DEFINITIONS_MESSAGE) unless helper.changed_files(/usage_ping\.md/).any?
telemetry_labels = ['telemetry']
telemetry_labels << 'telemetry::review pending' unless helper.mr_has_labels?('telemetry::reviewed')
......
......@@ -250,6 +250,10 @@ module Gitlab
"/label #{labels_list(labels, sep: ' ')}"
end
def changed_files(regex)
all_changed_files.grep(regex)
end
private
def has_database_scoped_labels?(current_mr_labels)
......
......@@ -57,6 +57,24 @@ RSpec.describe Gitlab::Danger::Changelog do
is_expected.to be_truthy
end
end
context 'when MR contains a category that require changelog and a category that require no changelog with changelog label' do
let(:changes_by_category) { { category_with_changelog => nil, category_without_changelog => nil } }
let(:mr_labels) { ['feature'] }
it 'is truthy' do
is_expected.to be_truthy
end
end
context 'when MR contains a category that require changelog and a category that require no changelog with no changelog label' do
let(:changes_by_category) { { category_with_changelog => nil, category_without_changelog => nil } }
let(:mr_labels) { ['tooling'] }
it 'is truthy' do
is_expected.to be_falsey
end
end
end
describe '#found' do
......
......@@ -76,6 +76,14 @@ RSpec.describe Gitlab::Danger::Helper do
end
end
describe "changed_files" do
it 'returns list of changed files matching given regex' do
expect(helper).to receive(:all_changed_files).and_return(%w[migration.rb usage_data.rb])
expect(helper.changed_files(/usage_data/)).to contain_exactly('usage_data.rb')
end
end
describe '#all_ee_changes' do
subject { helper.all_ee_changes }
......
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