2019-04-24 08:08:33 -04:00
|
|
|
# frozen_string_literal: true
|
2019-09-06 07:21:53 -04:00
|
|
|
|
2021-03-12 07:09:33 -05:00
|
|
|
require 'gitlab-dangerfiles'
|
2019-09-06 07:21:53 -04:00
|
|
|
|
2021-12-03 10:10:36 -05:00
|
|
|
def ee?
|
|
|
|
# Support former project name for `dev` and support local Danger run
|
|
|
|
%w[gitlab gitlab-ee].include?(ENV['CI_PROJECT_NAME']) || Dir.exist?(File.expand_path('ee', __dir__))
|
|
|
|
end
|
2021-05-03 14:10:17 -04:00
|
|
|
|
2021-12-03 10:10:36 -05:00
|
|
|
project_name = ee? ? 'gitlab' : 'gitlab-foss'
|
2021-05-03 14:10:17 -04:00
|
|
|
|
2021-12-03 10:10:36 -05:00
|
|
|
Gitlab::Dangerfiles.for_project(self, project_name) do |gitlab_dangerfiles|
|
|
|
|
gitlab_dangerfiles.import_plugins
|
2021-05-05 08:10:33 -04:00
|
|
|
|
2021-12-03 10:10:36 -05:00
|
|
|
unless helper.release_automation?
|
|
|
|
danger.import_plugin('danger/plugins/*.rb')
|
|
|
|
gitlab_dangerfiles.import_dangerfiles(except: %w[simple_roulette])
|
|
|
|
gitlab_dangerfiles.config.files_to_category = ProjectHelper::CATEGORIES
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return if helper.release_automation?
|
2021-05-05 08:10:33 -04:00
|
|
|
|
2021-03-12 07:09:33 -05:00
|
|
|
project_helper.rule_names.each do |rule|
|
|
|
|
danger.import_dangerfile(path: File.join('danger', rule))
|
2019-04-04 07:26:01 -04:00
|
|
|
end
|
2020-05-25 08:08:23 -04:00
|
|
|
|
2020-05-26 08:08:22 -04:00
|
|
|
anything_to_post = status_report.values.any? { |data| data.any? }
|
|
|
|
|
2021-10-27 14:13:16 -04:00
|
|
|
return unless helper.ci?
|
|
|
|
|
2021-11-12 13:12:20 -05:00
|
|
|
def post_labels
|
2021-10-27 14:13:16 -04:00
|
|
|
gitlab.api.update_merge_request(gitlab.mr_json['project_id'],
|
|
|
|
gitlab.mr_json['iid'],
|
|
|
|
add_labels: project_helper.labels_to_add.join(','))
|
2021-11-12 13:12:20 -05:00
|
|
|
rescue Gitlab::Error::Forbidden
|
|
|
|
labels = project_helper.labels_to_add.map { |label| %Q(~"#{label}") }
|
|
|
|
warn("This Merge Request needs to be labelled with #{labels.join(' ')}. Please request a reviewer or maintainer to add them.")
|
|
|
|
end
|
|
|
|
|
|
|
|
if project_helper.labels_to_add.any?
|
|
|
|
post_labels
|
2021-10-27 14:13:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
if anything_to_post
|
2020-05-26 08:08:22 -04:00
|
|
|
markdown("**If needed, you can retry the [`danger-review` job](#{ENV['CI_JOB_URL']}) that generated this comment.**")
|
|
|
|
end
|