Commit 655fb346 authored by Ash McKenzie's avatar Ash McKenzie

Update some Danger rules to not rely upon CI

Convert a bunch of Danger rules so they can run
locally.
parent 68d6831a
# frozen_string_literal: true # frozen_string_literal: true
SCHEMA_NOT_UPDATED_MESSAGE = <<~MSG gitlab_danger = GitlabDanger.new(helper.gitlab_helper)
**New %<migrations>s added but %<schema>s wasn't updated.**
SCHEMA_NOT_UPDATED_MESSAGE_SHORT = <<~MSG
New %<migrations>s added but %<schema>s wasn't updated.
MSG
SCHEMA_NOT_UPDATED_MESSAGE_FULL = <<~MSG
**#{SCHEMA_NOT_UPDATED_MESSAGE_SHORT}**
Usually, when adding new %<migrations>s, %<schema>s should be Usually, when adding new %<migrations>s, %<schema>s should be
updated too (unless the migration isn't changing the DB schema updated too (unless the migration isn't changing the DB schema
...@@ -29,14 +35,18 @@ geo_db_schema_updated = !git.modified_files.grep(%r{\Aee/db/geo/schema\.rb}).emp ...@@ -29,14 +35,18 @@ geo_db_schema_updated = !git.modified_files.grep(%r{\Aee/db/geo/schema\.rb}).emp
non_geo_migration_created = !git.added_files.grep(%r{\A(db/(post_)?migrate)/}).empty? non_geo_migration_created = !git.added_files.grep(%r{\A(db/(post_)?migrate)/}).empty?
geo_migration_created = !git.added_files.grep(%r{\Aee/db/geo/(post_)?migrate/}).empty? geo_migration_created = !git.added_files.grep(%r{\Aee/db/geo/(post_)?migrate/}).empty?
format_str = gitlab_danger.ci? ? SCHEMA_NOT_UPDATED_MESSAGE_FULL : SCHEMA_NOT_UPDATED_MESSAGE_SHORT
if non_geo_migration_created && !non_geo_db_schema_updated if non_geo_migration_created && !non_geo_db_schema_updated
warn format(SCHEMA_NOT_UPDATED_MESSAGE, migrations: 'migrations', schema: gitlab.html_link("db/schema.rb")) warn format(format_str, migrations: 'migrations', schema: gitlab_danger.html_link("db/schema.rb"))
end end
if geo_migration_created && !geo_db_schema_updated 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")) warn format(format_str, migrations: 'Geo migrations', schema: gitlab_danger.html_link("ee/db/geo/schema.rb"))
end end
return unless gitlab_danger.ci?
db_paths_to_review = helper.changes_by_category[:database] db_paths_to_review = helper.changes_by_category[:database]
if gitlab.mr_labels.include?('database') || db_paths_to_review.any? if gitlab.mr_labels.include?('database') || db_paths_to_review.any?
......
...@@ -6,20 +6,22 @@ unless docs_paths_to_review.empty? ...@@ -6,20 +6,22 @@ unless docs_paths_to_review.empty?
message 'This merge request adds or changes files that require a review ' \ message 'This merge request adds or changes files that require a review ' \
'from the Technical Writing team.' 'from the Technical Writing team.'
if GitlabDanger.new(helper.gitlab_helper).ci?
markdown(<<~MARKDOWN) markdown(<<~MARKDOWN)
## Documentation review ## Documentation review
The following files require a review from a technical writer: The following files require a review from a technical writer:
* #{docs_paths_to_review.map { |path| "`#{path}`" }.join("\n* ")} * #{docs_paths_to_review.map { |path| "`#{path}`" }.join("\n* ")}
The review does not need to block merging this merge request. See the: The review does not need to block merging this merge request. See the:
- [DevOps stages](https://about.gitlab.com/handbook/product/categories/#devops-stages) for the appropriate technical writer for this review. - [DevOps stages](https://about.gitlab.com/handbook/product/categories/#devops-stages) for the appropriate technical writer for this review.
- [Documentation workflows](https://docs.gitlab.com/ee/development/documentation/workflow.html) for information on when to assign a merge request for review. - [Documentation workflows](https://docs.gitlab.com/ee/development/documentation/workflow.html) for information on when to assign a merge request for review.
MARKDOWN MARKDOWN
unless gitlab.mr_labels.include?('Documentation') unless gitlab.mr_labels.include?('Documentation')
warn 'This merge request is missing the ~Documentation label.' warn 'This merge request is missing the ~Documentation label.'
end end
end
end end
# frozen_string_literal: true # frozen_string_literal: true
return unless helper.all_changed_files.include? 'yarn.lock' return unless helper.all_changed_files.include?('yarn.lock')
duplicate = `node_modules/.bin/yarn-deduplicate --list --strategy fewer yarn.lock` duplicate = `node_modules/.bin/yarn-deduplicate --list --strategy fewer yarn.lock`
.split(/$/) .split(/$/)
...@@ -11,7 +11,8 @@ return if duplicate.empty? ...@@ -11,7 +11,8 @@ return if duplicate.empty?
warn 'This merge request has introduced duplicated yarn dependencies.' warn 'This merge request has introduced duplicated yarn dependencies.'
markdown(<<~MARKDOWN) if GitlabDanger.new(helper.gitlab_helper).ci?
markdown(<<~MARKDOWN)
## Duplicate yarn dependencies ## Duplicate yarn dependencies
The following dependencies should be de-duplicated: The following dependencies should be de-duplicated:
...@@ -24,4 +25,5 @@ markdown(<<~MARKDOWN) ...@@ -24,4 +25,5 @@ markdown(<<~MARKDOWN)
node_modules/.bin/yarn-deduplicate --strategy fewer yarn.lock \\ node_modules/.bin/yarn-deduplicate --strategy fewer yarn.lock \\
&& yarn install && yarn install
``` ```
MARKDOWN MARKDOWN
end
...@@ -13,7 +13,8 @@ return if eslint_candidates.empty? ...@@ -13,7 +13,8 @@ return if eslint_candidates.empty?
warn 'This merge request changed files with disabled eslint rules. Please consider fixing them.' warn 'This merge request changed files with disabled eslint rules. Please consider fixing them.'
markdown(<<~MARKDOWN) if GitlabDanger.new(helper.gitlab_helper).ci?
markdown(<<~MARKDOWN)
## Disabled eslint rules ## Disabled eslint rules
The following files have disabled `eslint` rules. Please consider fixing them: The following files have disabled `eslint` rules. Please consider fixing them:
...@@ -26,4 +27,5 @@ markdown(<<~MARKDOWN) ...@@ -26,4 +27,5 @@ markdown(<<~MARKDOWN)
node_modules/.bin/eslint --report-unused-disable-directives --no-inline-config \\ node_modules/.bin/eslint --report-unused-disable-directives --no-inline-config \\
#{eslint_candidates.map { |path| " '#{path}'" }.join(" \\\n")} #{eslint_candidates.map { |path| " '#{path}'" }.join(" \\\n")}
``` ```
MARKDOWN MARKDOWN
end
...@@ -16,6 +16,7 @@ if files_to_fix.any? ...@@ -16,6 +16,7 @@ if files_to_fix.any?
warn 'This merge request adds files that do not enforce frozen string literal. ' \ warn 'This merge request adds files that do not enforce frozen string literal. ' \
'See https://gitlab.com/gitlab-org/gitlab-ce/issues/47424 for more information.' 'See https://gitlab.com/gitlab-org/gitlab-ce/issues/47424 for more information.'
if GitlabDanger.new(helper.gitlab_helper).ci?
markdown(<<~MARKDOWN) markdown(<<~MARKDOWN)
## Enable Frozen String Literal ## Enable Frozen String Literal
...@@ -23,4 +24,5 @@ if files_to_fix.any? ...@@ -23,4 +24,5 @@ if files_to_fix.any?
* #{files_to_fix.map { |path| "`#{path}`" }.join("\n* ")} * #{files_to_fix.map { |path| "`#{path}`" }.join("\n* ")}
MARKDOWN MARKDOWN
end
end end
GEMFILE_LOCK_NOT_UPDATED_MESSAGE = <<~MSG.freeze GEMFILE_LOCK_NOT_UPDATED_MESSAGE_SHORT = <<~MSG.freeze
**%<gemfile>s was updated but %<gemfile_lock>s wasn't updated.** %<gemfile>s was updated but %<gemfile_lock>s wasn't updated.
MSG
GEMFILE_LOCK_NOT_UPDATED_MESSAGE_FULL = <<~MSG.freeze
**#{GEMFILE_LOCK_NOT_UPDATED_MESSAGE_SHORT}**
Usually, when %<gemfile>s is updated, you should run Usually, when %<gemfile>s is updated, you should run
``` ```
...@@ -19,5 +23,14 @@ gemfile_modified = git.modified_files.include?("Gemfile") ...@@ -19,5 +23,14 @@ gemfile_modified = git.modified_files.include?("Gemfile")
gemfile_lock_modified = git.modified_files.include?("Gemfile.lock") gemfile_lock_modified = git.modified_files.include?("Gemfile.lock")
if gemfile_modified && !gemfile_lock_modified if gemfile_modified && !gemfile_lock_modified
warn format(GEMFILE_LOCK_NOT_UPDATED_MESSAGE, gemfile: gitlab.html_link("Gemfile"), gemfile_lock: gitlab.html_link("Gemfile.lock")) gitlab_danger = GitlabDanger.new(helper.gitlab_helper)
format_str = gitlab_danger.ci? ? GEMFILE_LOCK_NOT_UPDATED_MESSAGE_FULL : GEMFILE_LOCK_NOT_UPDATED_MESSAGE_SHORT
message = format(format_str,
gemfile: gitlab_danger.html_link("Gemfile"),
gemfile_lock: gitlab_danger.html_link("Gemfile.lock")
)
warn(message)
end end
...@@ -19,7 +19,8 @@ return if unpretty.empty? ...@@ -19,7 +19,8 @@ return if unpretty.empty?
warn 'This merge request changed frontend files without pretty printing them.' warn 'This merge request changed frontend files without pretty printing them.'
markdown(<<~MARKDOWN) if GitlabDanger.new(helper.gitlab_helper).ci?
markdown(<<~MARKDOWN)
## Pretty print Frontend files ## Pretty print Frontend files
The following files should have been pretty printed with `prettier`: The following files should have been pretty printed with `prettier`:
...@@ -36,4 +37,5 @@ markdown(<<~MARKDOWN) ...@@ -36,4 +37,5 @@ markdown(<<~MARKDOWN)
Also consider auto-formatting [on-save]. Also consider auto-formatting [on-save].
[on-save]: https://docs.gitlab.com/ee/development/new_fe_guide/style/prettier.html [on-save]: https://docs.gitlab.com/ee/development/new_fe_guide/style/prettier.html
MARKDOWN MARKDOWN
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