2020-09-03 14:08:29 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-03-12 07:09:33 -05:00
|
|
|
return unless helper.ci?
|
2020-09-03 14:08:29 -04:00
|
|
|
|
|
|
|
SPECIALIZATIONS = {
|
|
|
|
database: 'database',
|
|
|
|
backend: 'backend',
|
|
|
|
frontend: 'frontend',
|
2021-11-08 22:42:22 -05:00
|
|
|
ux: 'UX',
|
2020-09-03 14:08:29 -04:00
|
|
|
docs: 'documentation',
|
|
|
|
qa: 'QA',
|
2021-06-21 08:07:45 -04:00
|
|
|
ci_template: 'ci::templates',
|
|
|
|
feature_flag: 'feature flag'
|
2020-09-03 14:08:29 -04:00
|
|
|
}.freeze
|
|
|
|
|
2021-12-03 10:10:36 -05:00
|
|
|
labels_to_add = helper.changes_by_category.each_with_object([]) do |(category, _changes), memo|
|
2020-09-08 05:08:31 -04:00
|
|
|
label = SPECIALIZATIONS[category]
|
2021-11-03 23:13:32 -04:00
|
|
|
next unless label
|
|
|
|
next if gitlab.mr_labels.include?(label)
|
2020-09-08 05:08:31 -04:00
|
|
|
|
2021-11-03 23:13:32 -04:00
|
|
|
# Don't override already-set scoped labels.
|
|
|
|
label_scope = label.split('::')[0...-1].join('::')
|
|
|
|
next if !label_scope.empty? && gitlab.mr_labels.any? { |mr_label| mr_label.start_with?(label_scope) }
|
|
|
|
|
|
|
|
memo << label
|
2020-09-03 14:08:29 -04:00
|
|
|
end
|
|
|
|
|
2022-03-02 16:16:54 -05:00
|
|
|
helper.labels_to_add.concat(labels_to_add) if labels_to_add.any?
|