From 16792fd74edd7c4f06c0afc859005cb49ee80ca9 Mon Sep 17 00:00:00 2001
From: Doug Stull <dstull@gitlab.com>
Date: Tue, 24 Nov 2020 09:50:40 +0000
Subject: [PATCH] Add condition to danger file for changelog placement

- for db changes we should always be in non ee.
---
 danger/changelog/Dangerfile    | 6 +++++-
 danger/database/Dangerfile     | 4 +---
 lib/gitlab/danger/changelog.rb | 1 +
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/danger/changelog/Dangerfile b/danger/changelog/Dangerfile
index 971c6a2a7b9..06593a04093 100644
--- a/danger/changelog/Dangerfile
+++ b/danger/changelog/Dangerfile
@@ -46,13 +46,17 @@ def check_changelog_path(path)
   ee_changes = helper.all_ee_changes.dup
   ee_changes.delete(path)
 
-  if ee_changes.any? && !changelog.ee_changelog?
+  if ee_changes.any? && !changelog.ee_changelog? && !changelog.db_changes?
     warn "This MR has a Changelog file outside `ee/`, but code changes in `ee/`. Consider moving the Changelog file into `ee/`."
   end
 
   if ee_changes.empty? && changelog.ee_changelog?
     warn "This MR has a Changelog file in `ee/`, but no code changes in `ee/`. Consider moving the Changelog file outside `ee/`."
   end
+
+  if ee_changes.any? && changelog.ee_changelog? && changelog.db_changes?
+    warn "This MR has a Changelog file inside `ee/`, but there are database changes which [requires](https://docs.gitlab.com/ee/development/changelog.html#what-warrants-a-changelog-entry) the Changelog placement to be outside of `ee/`. Consider moving the Changelog file outside `ee/`."
+  end
 end
 
 if git.modified_files.include?("CHANGELOG.md")
diff --git a/danger/database/Dangerfile b/danger/database/Dangerfile
index 2ccfdcffaea..67a9b53fe3a 100644
--- a/danger/database/Dangerfile
+++ b/danger/database/Dangerfile
@@ -2,9 +2,7 @@
 
 gitlab_danger = GitlabDanger.new(helper.gitlab_helper)
 
-SCHEMA_NOT_UPDATED_MESSAGE_SHORT = <<~MSG
-New %<migrations>s added but %<schema>s wasn't updated.
-MSG
+SCHEMA_NOT_UPDATED_MESSAGE_SHORT = "New %<migrations>s added but %<schema>s wasn't updated"
 
 SCHEMA_NOT_UPDATED_MESSAGE_FULL = <<~MSG
 **#{SCHEMA_NOT_UPDATED_MESSAGE_SHORT}**
diff --git a/lib/gitlab/danger/changelog.rb b/lib/gitlab/danger/changelog.rb
index 607ca1200a0..92af6849b2f 100644
--- a/lib/gitlab/danger/changelog.rb
+++ b/lib/gitlab/danger/changelog.rb
@@ -39,6 +39,7 @@ module Gitlab
       def required?
         git.added_files.any? { |path| path =~ %r{\Adb/(migrate|post_migrate)/} }
       end
+      alias_method :db_changes?, :required?
 
       def optional?
         categories_need_changelog? && without_no_changelog_label?
-- 
2.30.9