Skip to content
Snippets Groups Projects
Unverified Commit d7a8ccbc authored by Lukas Eipert's avatar Lukas Eipert
Browse files

Create helper to get all changed files

Danger apparently has three different objects which could contain files
you often want to check:

 - git.added_files
 - git.modified_files
 - git.renamed_files

The problem: If a file is renamed, `modified_files` contains the file
path before the rename. In some Danger checks we use `added_files` +
`modified_files`, which might contain the deleted paths of renamed
files, but missing the new paths of renamed files.

So we need to consider `renamed_files` as well.
parent 28d412e5
No related branches found
No related tags found
No related merge requests found
danger.import_plugin('danger/plugins/common_helpers.rb')
danger.import_dangerfile(path: 'danger/metadata')
danger.import_dangerfile(path: 'danger/changes_size')
danger.import_dangerfile(path: 'danger/changelog')
Loading
Loading
Loading
Loading
@@ -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?
 
Loading
Loading
@@ -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(common_helpers.all_changed_files)
 
unless db_paths_to_review.empty?
message 'This merge request adds or changes files that require a ' \
Loading
Loading
Loading
Loading
@@ -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(common_helpers.all_changed_files)
 
unless docs_paths_to_review.empty?
message 'This merge request adds or changes files that require a ' \
Loading
Loading
Loading
Loading
@@ -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(common_helpers.all_changed_files)
 
return if eslint_candidates.empty?
 
Loading
Loading
# 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 CommonHelpers < Plugin
# Returns a list of all files that have been added, modified or renamed
#
# 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
(git.added_files +
git.modified_files +
git.renamed_files.map { |x| x[:after] } -
git.renamed_files.map { |x| x[:before] }).sort
end
end
end
Loading
Loading
@@ -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(common_helpers.all_changed_files)
 
return if prettier_candidates.empty?
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment