2020-09-29 11:10:08 -04:00
|
|
|
# frozen_string_literal: true
|
2021-02-08 01:09:18 -05:00
|
|
|
# rubocop:disable Style/SignalException
|
2020-09-29 11:10:08 -04:00
|
|
|
|
2021-01-11 16:10:36 -05:00
|
|
|
CHANGED_FILES_MESSAGE = <<~MSG
|
2021-01-12 19:10:50 -05:00
|
|
|
For the following files, a review from the [Data team and Product Intelligence team](https://gitlab.com/groups/gitlab-org/growth/product-intelligence/engineers/-/group_members?with_inherited_permissions=exclude) is recommended
|
2021-04-06 08:09:21 -04:00
|
|
|
Please check the ~"product intelligence" [guide](https://docs.gitlab.com/ee/development/usage_ping.html).
|
2020-09-29 11:10:08 -04:00
|
|
|
|
|
|
|
|
|
|
|
%<changed_files>s
|
|
|
|
|
|
|
|
MSG
|
|
|
|
|
2021-02-08 01:09:18 -05:00
|
|
|
UPDATE_DICTIONARY_MESSAGE = <<~MSG
|
2021-02-23 04:10:45 -05:00
|
|
|
When adding, changing, or updating metrics, please update the [Metrics Dictionary](https://docs.gitlab.com/ee/development/usage_ping/dictionary.html)
|
2021-02-08 01:09:18 -05:00
|
|
|
|
|
|
|
```shell
|
|
|
|
bundle exec rake gitlab:usage_data:generate_metrics_dictionary
|
|
|
|
```
|
|
|
|
MSG
|
|
|
|
|
|
|
|
all_changed_files = helper.all_changed_files
|
|
|
|
|
2020-09-29 11:10:08 -04:00
|
|
|
tracking_files = [
|
|
|
|
'lib/gitlab/tracking.rb',
|
|
|
|
'spec/lib/gitlab/tracking_spec.rb',
|
|
|
|
'app/helpers/tracking_helper.rb',
|
|
|
|
'spec/helpers/tracking_helper_spec.rb',
|
|
|
|
'app/assets/javascripts/tracking.js',
|
2021-01-20 07:11:06 -05:00
|
|
|
'spec/frontend/tracking_spec.js',
|
|
|
|
'generator_templates/usage_metric_definition/metric_definition.yml',
|
2021-03-25 08:09:19 -04:00
|
|
|
'lib/generators/gitlab/usage_metric_definition_generator.rb',
|
|
|
|
'lib/generators/gitlab/usage_metric_definition/redis_hll_generator.rb',
|
|
|
|
'spec/lib/generators/gitlab/usage_metric_definition_generator_spec.rb',
|
|
|
|
'spec/lib/generators/gitlab/usage_metric_definition/redis_hll_generator_spec.rb',
|
2021-02-08 01:09:18 -05:00
|
|
|
'config/metrics/schema.json'
|
2020-09-29 11:10:08 -04:00
|
|
|
]
|
|
|
|
|
2021-02-08 01:09:18 -05:00
|
|
|
tracking_changed_files = all_changed_files & tracking_files
|
|
|
|
usage_data_changed_files = all_changed_files.grep(%r{(usage_data)})
|
2021-02-09 07:09:48 -05:00
|
|
|
dictionary_changed_file = all_changed_files.grep(%r{(doc/development/usage_ping/dictionary.md)})
|
2021-03-01 07:11:29 -05:00
|
|
|
metrics_changed_files = all_changed_files.grep(%r{((ee/)?config/metrics/.*\.yml)})
|
2020-09-29 11:10:08 -04:00
|
|
|
|
2021-02-19 07:11:06 -05:00
|
|
|
def matching_files?(file, extension:, pattern:)
|
|
|
|
return unless file.end_with?(extension)
|
|
|
|
|
|
|
|
helper.changed_lines(file).grep(pattern).any?
|
|
|
|
end
|
|
|
|
|
|
|
|
js_patterns = Regexp.union(
|
|
|
|
'Tracking.event',
|
|
|
|
/\btrack\(/,
|
2021-03-26 14:09:16 -04:00
|
|
|
'data-track-event',
|
|
|
|
'data-track-action'
|
2021-02-19 07:11:06 -05:00
|
|
|
)
|
|
|
|
|
2021-03-01 07:11:29 -05:00
|
|
|
dictionary_pattern = Regexp.union(
|
|
|
|
'key_path:',
|
|
|
|
'description:',
|
|
|
|
'product_section:',
|
|
|
|
'product_stage:',
|
|
|
|
'product_group:',
|
|
|
|
'status:',
|
|
|
|
'tier:'
|
|
|
|
)
|
|
|
|
|
2021-02-15 10:08:59 -05:00
|
|
|
snowplow_changed_files = all_changed_files.select do |file|
|
2021-02-19 07:11:06 -05:00
|
|
|
matching_files?(file, extension: '.rb', pattern: %r{Gitlab::Tracking\.event}) ||
|
|
|
|
matching_files?(file, extension: '.js', pattern: js_patterns) ||
|
|
|
|
matching_files?(file, extension: '.vue', pattern: js_patterns) ||
|
|
|
|
matching_files?(file, extension: '.haml', pattern: %r{data: \{ track})
|
2021-02-15 10:08:59 -05:00
|
|
|
end
|
|
|
|
|
2021-03-02 13:11:20 -05:00
|
|
|
required_dictionary_update_changed_files = metrics_changed_files.select do |file|
|
2021-03-01 07:11:29 -05:00
|
|
|
matching_files?(file, extension: '.yml', pattern: dictionary_pattern)
|
|
|
|
end
|
|
|
|
|
|
|
|
matching_changed_files = usage_data_changed_files +
|
|
|
|
tracking_changed_files +
|
|
|
|
metrics_changed_files +
|
|
|
|
dictionary_changed_file +
|
|
|
|
snowplow_changed_files
|
2020-09-29 11:10:08 -04:00
|
|
|
|
2021-02-15 10:08:59 -05:00
|
|
|
if matching_changed_files.any?
|
2020-09-29 11:10:08 -04:00
|
|
|
|
2021-04-06 08:09:21 -04:00
|
|
|
warn format(CHANGED_FILES_MESSAGE, changed_files: helper.markdown_list(matching_changed_files))
|
2021-02-08 01:09:18 -05:00
|
|
|
|
2021-03-02 13:11:20 -05:00
|
|
|
fail format(UPDATE_DICTIONARY_MESSAGE) if required_dictionary_update_changed_files.any? && dictionary_changed_file.empty?
|
2020-09-29 11:10:08 -04:00
|
|
|
|
2021-04-27 11:09:52 -04:00
|
|
|
labels = []
|
|
|
|
labels << 'product intelligence' unless helper.mr_has_labels?('product intelligence')
|
|
|
|
labels << 'product intelligence::review pending' unless helper.mr_has_labels?(['product intelligence::approved', 'product intelligence::review pending'])
|
|
|
|
|
|
|
|
if labels.any?
|
|
|
|
gitlab.api.update_merge_request(gitlab.mr_json['project_id'],
|
|
|
|
gitlab.mr_json['iid'],
|
|
|
|
add_labels: helper.prepare_labels_for_mr(labels))
|
|
|
|
end
|
2020-09-29 11:10:08 -04:00
|
|
|
end
|