From d8d04719043c2a3ee6fe6c86d68dc3941d2467e5 Mon Sep 17 00:00:00 2001
From: Nao Hashizume <nhashizume@gitlab.com>
Date: Thu, 27 Apr 2023 06:16:05 +0000
Subject: [PATCH] Add *.vue, *.md, and *.scss to allowlist to reuse frontend
 fixtures

---
 scripts/gitlab_component_helpers.sh           |  2 +-
 spec/tooling/lib/tooling/find_changes_spec.rb | 16 ++++++++++++----
 tooling/bin/find_only_allowed_files_changes   | 12 ++++++++++++
 tooling/bin/find_only_js_changes              | 12 ------------
 tooling/lib/tooling/find_changes.rb           |  6 ++++--
 5 files changed, 29 insertions(+), 19 deletions(-)
 create mode 100755 tooling/bin/find_only_allowed_files_changes
 delete mode 100755 tooling/bin/find_only_js_changes

diff --git a/scripts/gitlab_component_helpers.sh b/scripts/gitlab_component_helpers.sh
index 2e816330eb687..8b31f79d5c588 100644
--- a/scripts/gitlab_component_helpers.sh
+++ b/scripts/gitlab_component_helpers.sh
@@ -118,7 +118,7 @@ function check_fixtures_download() {
   if [[ -z "${CI_MERGE_REQUEST_IID:-}" ]]; then
     return 1
   else
-    if tooling/bin/find_only_js_changes && ! fixtures_archive_doesnt_exist; then
+    if tooling/bin/find_only_allowed_files_changes && ! fixtures_archive_doesnt_exist; then
       return 0
     else
       return 1
diff --git a/spec/tooling/lib/tooling/find_changes_spec.rb b/spec/tooling/lib/tooling/find_changes_spec.rb
index 37e590858cffc..43c3da5699da3 100644
--- a/spec/tooling/lib/tooling/find_changes_spec.rb
+++ b/spec/tooling/lib/tooling/find_changes_spec.rb
@@ -182,8 +182,8 @@
     end
   end
 
-  describe '#only_js_files_changed' do
-    subject { instance.only_js_files_changed }
+  describe '#only_allowed_files_changed' do
+    subject { instance.only_allowed_files_changed }
 
     context 'when fetching changes from changed files' do
       let(:from) { :changed_files }
@@ -200,8 +200,16 @@
         end
       end
 
-      context 'when changed files contain not only *.js changes' do
-        let(:changed_files_file_content) { 'a.js b.rb' }
+      context 'when changed files contain both *.vue and *.js changes' do
+        let(:changed_files_file_content) { 'a.js b.vue' }
+
+        it 'returns true' do
+          expect(subject).to be true
+        end
+      end
+
+      context 'when changed files contain not allowed changes' do
+        let(:changed_files_file_content) { 'a.js b.vue c.rb' }
 
         it 'returns false' do
           expect(subject).to be false
diff --git a/tooling/bin/find_only_allowed_files_changes b/tooling/bin/find_only_allowed_files_changes
new file mode 100755
index 0000000000000..c40048c66faca
--- /dev/null
+++ b/tooling/bin/find_only_allowed_files_changes
@@ -0,0 +1,12 @@
+#!/usr/bin/env ruby
+# frozen_string_literal: true
+
+require_relative '../lib/tooling/find_changes'
+
+if Tooling::FindChanges.new(from: :api).only_allowed_files_changed
+  puts "Only files with extensions #{ALLOWED_FILE_TYPES.join(', ')} were changed"
+  exit 0
+else
+  puts "Changes were made to files with extensions other than #{ALLOWED_FILE_TYPES.join(', ')}"
+  exit 1
+end
diff --git a/tooling/bin/find_only_js_changes b/tooling/bin/find_only_js_changes
deleted file mode 100755
index a69ee64fe141c..0000000000000
--- a/tooling/bin/find_only_js_changes
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/usr/bin/env ruby
-# frozen_string_literal: true
-
-require_relative '../lib/tooling/find_changes'
-
-if Tooling::FindChanges.new(from: :api).only_js_files_changed
-  puts "Only JS files were changed"
-  exit 0
-else
-  puts "Changes were made to files other than JS files"
-  exit 1
-end
diff --git a/tooling/lib/tooling/find_changes.rb b/tooling/lib/tooling/find_changes.rb
index 25381e1a89446..c498c83d24b8a 100755
--- a/tooling/lib/tooling/find_changes.rb
+++ b/tooling/lib/tooling/find_changes.rb
@@ -8,6 +8,8 @@ module Tooling
   class FindChanges
     include Helpers::PredictiveTestsHelper
 
+    ALLOWED_FILE_TYPES = ['.js', '.vue', '.md', '.scss'].freeze
+
     def initialize(
       from:,
       changed_files_pathname: nil,
@@ -41,8 +43,8 @@ def execute
       end
     end
 
-    def only_js_files_changed
-      file_changes.any? && file_changes.all? { |file| file.end_with?('.js') }
+    def only_allowed_files_changed
+      file_changes.any? && file_changes.all? { |file| ALLOWED_FILE_TYPES.include?(File.extname(file)) }
     end
 
     private
-- 
GitLab