Commit 0d038abc authored by Rémy Coutable's avatar Rémy Coutable

danger: Use the changes_size Dangerfile from gitlab-dangerfiles

This opens up the possibility to actually re-use Danger rules accross
projects.
Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 7082dd0a
......@@ -2,11 +2,15 @@
require 'gitlab-dangerfiles'
Gitlab::Dangerfiles.import_plugins(danger)
danger.import_plugin('danger/plugins/*.rb')
gitlab_dangerfiles = Gitlab::Dangerfiles::Engine.new(self)
gitlab_dangerfiles.import_plugins
return if helper.release_automation?
danger.import_plugin('danger/plugins/*.rb')
gitlab_dangerfiles.import_dangerfiles
project_helper.rule_names.each do |rule|
danger.import_dangerfile(path: File.join('danger', rule))
end
......
......@@ -403,7 +403,7 @@ group :development, :test do
end
group :development, :test, :danger do
gem 'gitlab-dangerfiles', '~> 1.1.1', require: false
gem 'gitlab-dangerfiles', '~> 2.0.0', require: false
end
group :development, :test, :coverage do
......
......@@ -447,7 +447,7 @@ GEM
terminal-table (~> 1.5, >= 1.5.1)
gitlab-chronic (0.10.5)
numerizer (~> 0.2)
gitlab-dangerfiles (1.1.1)
gitlab-dangerfiles (2.0.0)
danger-gitlab
gitlab-experiment (0.5.3)
activesupport (>= 3.0)
......@@ -1449,7 +1449,7 @@ DEPENDENCIES
gitaly (~> 13.11.0.pre.rc1)
github-markup (~> 1.7.0)
gitlab-chronic (~> 0.10.5)
gitlab-dangerfiles (~> 1.1.1)
gitlab-dangerfiles (~> 2.0.0)
gitlab-experiment (~> 0.5.3)
gitlab-fog-azure-rm (~> 1.0.1)
gitlab-fog-google (~> 1.13)
......
# frozen_string_literal: true
# FIXME: git.info_for_file raises the following error
# /usr/local/bundle/gems/git-1.4.0/lib/git/lib.rb:956:in `command': (Danger::DSLError)
# [!] Invalid `Dangerfile` file:
# [!] Invalid `Dangerfile` file: git '--git-dir=/builds/gitlab-org/gitlab/.git' '--work-tree=/builds/gitlab-org/gitlab' cat-file '-t' '' 2>&1:fatal: Not a valid object name
# This seems to be the same as https://github.com/danger/danger/issues/535.
# locale_files_updated = git.modified_files.select { |path| path.start_with?('locale') }
# locale_files_updated.each do |locale_file_updated|
# git_stats = git.info_for_file(locale_file_updated)
# message "Git stats for #{locale_file_updated}: #{git_stats[:insertions]} insertions, #{git_stats[:deletions]} insertions"
# end
if git.lines_of_code > 2_000
warn "This merge request is definitely too big (#{git.lines_of_code} lines changed), please split it into multiple merge requests."
elsif git.lines_of_code > 500
warn "This merge request is quite big (#{git.lines_of_code} lines changed), please consider splitting it into multiple merge requests."
end
......@@ -55,7 +55,7 @@ if gitlab.mr_labels.include?('database') || db_paths_to_review.any?
markdown(DB_MESSAGE)
markdown(DB_FILES_MESSAGE + helper.markdown_list(db_paths_to_review)) if db_paths_to_review.any?
unless helper.has_database_scoped_labels?(gitlab.mr_labels)
unless helper.has_database_scoped_labels?
gitlab.api.update_merge_request(gitlab.mr_json['project_id'],
gitlab.mr_json['iid'],
add_labels: 'database::review pending')
......
......@@ -13,7 +13,7 @@ group: "%<group>s"
SUGGEST_COMMENT
def check_feature_flag_yaml(feature_flag)
mr_group_label = helper.group_label(gitlab.mr_labels)
mr_group_label = helper.group_label
if feature_flag.group.nil?
message_for_feature_flag_missing_group!(feature_flag: feature_flag, mr_group_label: mr_group_label)
......
......@@ -220,7 +220,7 @@ RSpec.describe Tooling::Danger::ProjectHelper do
describe '.local_warning_message' do
it 'returns an informational message with rules that can run' do
expect(described_class.local_warning_message).to eq('==> Only the following Danger rules can be run locally: changelog, changes_size, commit_messages, database, datateam, documentation, duplicate_yarn_dependencies, eslint, karma, pajamas, pipeline, prettier, product_intelligence, utility_css')
expect(described_class.local_warning_message).to eq('==> Only the following Danger rules can be run locally: changelog, commit_messages, database, datateam, documentation, duplicate_yarn_dependencies, eslint, karma, pajamas, pipeline, prettier, product_intelligence, utility_css')
end
end
......
......@@ -5,7 +5,6 @@ module Tooling
module ProjectHelper
LOCAL_RULES ||= %w[
changelog
changes_size
commit_messages
database
datateam
......@@ -176,26 +175,12 @@ module Tooling
ee? ? 'gitlab' : 'gitlab-foss'
end
def missing_database_labels(current_mr_labels)
labels = if has_database_scoped_labels?(current_mr_labels)
['database']
else
['database', 'database::review pending']
end
labels - current_mr_labels
end
private
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
def has_database_scoped_labels?(current_mr_labels)
current_mr_labels.any? { |label| label.start_with?('database::') }
end
end
end
end
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