summaryrefslogtreecommitdiff
path: root/Dangerfile
blob: ca729f1b9416ac0a3d5c3d3c60c24e23216f1ca6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# frozen_string_literal: true

require 'gitlab-dangerfiles'

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

project_name = ee? ? 'gitlab' : 'gitlab-foss'

Gitlab::Dangerfiles.for_project(self, project_name) do |gitlab_dangerfiles|
  gitlab_dangerfiles.import_plugins

  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?

project_helper.rule_names.each do |rule|
  danger.import_dangerfile(path: File.join('danger', rule))
end

anything_to_post = status_report.values.any? { |data| data.any? }

return unless helper.ci?

def post_labels
  gitlab.api.update_merge_request(gitlab.mr_json['project_id'],
                                  gitlab.mr_json['iid'],
                                  add_labels: project_helper.labels_to_add.join(','))
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
end

if anything_to_post
  markdown("**If needed, you can retry the [`danger-review` job](#{ENV['CI_JOB_URL']}) that generated this comment.**")
end