Commit 38b9ddea authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'leipert-danger-fix-moved-files' into 'master'

Teach Danger how to pick up renamed files

Closes #52783

See merge request gitlab-org/gitlab-ce!22396
parents 3def0b3e 253e1818
danger.import_plugin('danger/plugins/helper.rb')
danger.import_dangerfile(path: 'danger/metadata')
danger.import_dangerfile(path: 'danger/changes_size')
danger.import_dangerfile(path: 'danger/changelog')
......
......@@ -39,8 +39,6 @@ def database_paths_requiring_review(files)
to_review
end
all_files = git.added_files + git.modified_files
non_geo_db_schema_updated = !git.modified_files.grep(%r{\Adb/schema\.rb}).empty?
geo_db_schema_updated = !git.modified_files.grep(%r{\Aee/db/geo/schema\.rb}).empty?
......@@ -55,7 +53,7 @@ if geo_migration_created && !geo_db_schema_updated
warn format(SCHEMA_NOT_UPDATED_MESSAGE, migrations: 'Geo migrations', schema: gitlab.html_link("ee/db/geo/schema.rb"))
end
db_paths_to_review = database_paths_requiring_review(all_files)
db_paths_to_review = database_paths_requiring_review(helper.all_changed_files)
unless db_paths_to_review.empty?
message 'This merge request adds or changes files that require a ' \
......
......@@ -11,9 +11,7 @@ def docs_paths_requiring_review(files)
end
end
all_files = git.added_files + git.modified_files
docs_paths_to_review = docs_paths_requiring_review(all_files)
docs_paths_to_review = docs_paths_requiring_review(helper.all_changed_files)
unless docs_paths_to_review.empty?
message 'This merge request adds or changes files that require a ' \
......
......@@ -7,7 +7,7 @@ def get_eslint_files(files)
end
end
eslint_candidates = get_eslint_files(git.added_files + git.modified_files)
eslint_candidates = get_eslint_files(helper.all_changed_files)
return if eslint_candidates.empty?
......
# frozen_string_literal: true
module Danger
# Common helper functions for our danger scripts
# If we find ourselves repeating code in our danger files, we might as well put them in here.
class Helper < Plugin
# Returns a list of all files that have been added, modified or renamed.
# `git.modified_files` might contain paths that already have been renamed,
# so we need to remove them from the list.
#
# Considering these changes:
#
# - A new_file.rb
# - D deleted_file.rb
# - M modified_file.rb
# - R renamed_file_before.rb -> renamed_file_after.rb
#
# it will return
# ```
# [ 'new_file.rb', 'modified_file.rb', 'renamed_file_after.rb' ]
# ```
#
# @return [Array<String>]
def all_changed_files
Set.new
.merge(git.added_files.to_a)
.merge(git.modified_files.to_a)
.merge(git.renamed_files.map { |x| x[:after] })
.subtract(git.renamed_files.map { |x| x[:before] })
.to_a
.sort
end
end
end
......@@ -6,7 +6,7 @@ def get_prettier_files(files)
end
end
prettier_candidates = get_prettier_files(git.added_files + git.modified_files)
prettier_candidates = get_prettier_files(helper.all_changed_files)
return if prettier_candidates.empty?
......
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