From c3268a6af542921d67c044976a0336f66ce38832 Mon Sep 17 00:00:00 2001 From: Nathan Friend Date: Wed, 24 Apr 2019 09:08:33 -0300 Subject: [PATCH] Add Danger rule for EE/CE templates This commit adds a rule to Danger that warns the developer when their MR includes changes to a CE .vue file that has a counterpart in the EE repo or vice-versa. --- Dangerfile | 2 + danger/ce_ee_vue_templates/Dangerfile | 56 +++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 danger/ce_ee_vue_templates/Dangerfile diff --git a/Dangerfile b/Dangerfile index 3e8cb456003..9e3a08949b0 100644 --- a/Dangerfile +++ b/Dangerfile @@ -1,3 +1,4 @@ +# frozen_string_literal: true danger.import_plugin('danger/plugins/helper.rb') unless helper.release_automation? @@ -16,4 +17,5 @@ unless helper.release_automation? danger.import_dangerfile(path: 'danger/roulette') danger.import_dangerfile(path: 'danger/single_codebase') danger.import_dangerfile(path: 'danger/gitlab_ui_wg') + danger.import_dangerfile(path: 'danger/ce_ee_vue_templates') end diff --git a/danger/ce_ee_vue_templates/Dangerfile b/danger/ce_ee_vue_templates/Dangerfile new file mode 100644 index 00000000000..f7715eb2a89 --- /dev/null +++ b/danger/ce_ee_vue_templates/Dangerfile @@ -0,0 +1,56 @@ +# frozen_string_literal: true +require 'cgi' + +def get_vue_files_with_ce_and_ee_versions(files) + files.select do |file| + if file.end_with?('.vue') + counterpart_path = if file.start_with?('ee/') + file.delete_prefix('ee/') + else + "ee/#{file}" + end + + escaped_path = CGI.escape(counterpart_path) + api_endpoint = "https://gitlab.com/api/v4/projects/gitlab-org%2Fgitlab-ee/repository/files/#{escaped_path}?ref=master" + response = HTTParty.get(api_endpoint) # rubocop:disable Gitlab/HTTParty + response.code != 404 + else + false + end + end +end + +vue_candidates = get_vue_files_with_ce_and_ee_versions(helper.all_changed_files) + +return if vue_candidates.empty? + +message 'This merge request includes changes to Vue files that have both CE and EE versions.' + +markdown(<<~MARKDOWN) + ## Vue `