From 4330c6502dc1b26fa87de046152336bfcc90aec8 Mon Sep 17 00:00:00 2001 From: Dylan Griffith <dyl.griffith@gmail.com> Date: Fri, 16 Feb 2024 09:25:05 +0000 Subject: [PATCH] Add gitlab-housekeper CI template to run in CI --- .gitlab/ci/gitlab-gems.gitlab-ci.yml | 3 ++ .../gitlab-housekeeper.gemspec | 2 +- .../gitlab/housekeeper/keeps/rubocop_fixer.rb | 2 +- .../spec/gitlab/housekeeper/git_spec.rb | 1 + .../housekeeper/keeps/rubocop_fixer_spec.rb | 35 ++++++++++--------- 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/.gitlab/ci/gitlab-gems.gitlab-ci.yml b/.gitlab/ci/gitlab-gems.gitlab-ci.yml index 802ad9a5a8a92..c590512039629 100644 --- a/.gitlab/ci/gitlab-gems.gitlab-ci.yml +++ b/.gitlab/ci/gitlab-gems.gitlab-ci.yml @@ -41,3 +41,6 @@ include: - local: .gitlab/ci/templates/gem.gitlab-ci.yml inputs: gem_name: "gitlab-database-lock_retries" + - local: .gitlab/ci/templates/gem.gitlab-ci.yml + inputs: + gem_name: "gitlab-housekeeper" diff --git a/gems/gitlab-housekeeper/gitlab-housekeeper.gemspec b/gems/gitlab-housekeeper/gitlab-housekeeper.gemspec index ca78d3136b7c6..192b9d9b9f49e 100644 --- a/gems/gitlab-housekeeper/gitlab-housekeeper.gemspec +++ b/gems/gitlab-housekeeper/gitlab-housekeeper.gemspec @@ -20,9 +20,9 @@ Gem::Specification.new do |spec| spec.executables = ['gitlab-housekeeper'] spec.add_runtime_dependency 'activesupport' + spec.add_runtime_dependency 'awesome_print' spec.add_runtime_dependency 'httparty' spec.add_runtime_dependency 'rubocop' - spec.add_runtime_dependency 'awesome_print' spec.add_development_dependency 'gitlab-styles' spec.add_development_dependency 'rspec-rails' diff --git a/gems/gitlab-housekeeper/lib/gitlab/housekeeper/keeps/rubocop_fixer.rb b/gems/gitlab-housekeeper/lib/gitlab/housekeeper/keeps/rubocop_fixer.rb index 06f13b7921365..5a78e7c584c7c 100644 --- a/gems/gitlab-housekeeper/lib/gitlab/housekeeper/keeps/rubocop_fixer.rb +++ b/gems/gitlab-housekeeper/lib/gitlab/housekeeper/keeps/rubocop_fixer.rb @@ -70,7 +70,7 @@ def each_allowed_rubocop_rule end end - def remove_first_exclusions(rule, file, remove_count) + def remove_first_exclusions(_rule, file, remove_count) content = File.read(file) skipped = 0 diff --git a/gems/gitlab-housekeeper/spec/gitlab/housekeeper/git_spec.rb b/gems/gitlab-housekeeper/spec/gitlab/housekeeper/git_spec.rb index df4f815928733..524c0fa21c21f 100644 --- a/gems/gitlab-housekeeper/spec/gitlab/housekeeper/git_spec.rb +++ b/gems/gitlab-housekeeper/spec/gitlab/housekeeper/git_spec.rb @@ -17,6 +17,7 @@ def setup_master_branch File.write(file_in_master, 'File already in master!') ::Gitlab::Housekeeper::Shell.execute('git', 'init') + ::Gitlab::Housekeeper::Shell.execute('git', 'config', '--local', 'user.email', 'test@example.com') ::Gitlab::Housekeeper::Shell.execute('git', 'checkout', '-b', 'master') ::Gitlab::Housekeeper::Shell.execute('git', 'add', file_in_master) ::Gitlab::Housekeeper::Shell.execute('git', 'commit', '-m', 'Initial commit!') diff --git a/gems/gitlab-housekeeper/spec/gitlab/housekeeper/keeps/rubocop_fixer_spec.rb b/gems/gitlab-housekeeper/spec/gitlab/housekeeper/keeps/rubocop_fixer_spec.rb index 2b145794f5818..80dad94dc4f7d 100644 --- a/gems/gitlab-housekeeper/spec/gitlab/housekeeper/keeps/rubocop_fixer_spec.rb +++ b/gems/gitlab-housekeeper/spec/gitlab/housekeeper/keeps/rubocop_fixer_spec.rb @@ -2,26 +2,10 @@ require 'spec_helper' +# rubocop:disable RSpec/MultipleMemoizedHelpers RSpec.describe ::Gitlab::Housekeeper::Keeps::RubocopFixer do let(:todo_dir) { Dir.mktmpdir } - let(:rule1_file) { Pathname(todo_dir).join('rule1.yml').to_s } - let(:rule2_file) { Pathname(todo_dir).join('rule2.yml').to_s } - let(:not_autocorrectable_file) { Pathname(todo_dir).join('not_autocorrectable.yml').to_s } - let(:todo_dir_pattern) { Pathname(todo_dir).join('**/*.yml').to_s } - - before do - dir = Pathname.new(todo_dir) - FileUtils.cp('spec/fixtures/rubocop_todo1.yml', rule1_file) - FileUtils.cp('spec/fixtures/rubocop_todo2.yml', rule2_file) - FileUtils.cp('spec/fixtures/rubocop_todo_not_autocorrectable.yml', not_autocorrectable_file) - end - - after do - FileUtils.remove_entry(todo_dir) - end - let(:rubocop_fixer) { described_class.new(todo_dir_pattern: todo_dir_pattern, limit_fixes: 5) } - let(:rule1_violating_files) do [ 'rule1_violation1.rb', @@ -45,6 +29,22 @@ ] end + let(:rule1_file) { Pathname(todo_dir).join('rule1.yml').to_s } + let(:rule2_file) { Pathname(todo_dir).join('rule2.yml').to_s } + let(:not_autocorrectable_file) { Pathname(todo_dir).join('not_autocorrectable.yml').to_s } + let(:todo_dir_pattern) { Pathname(todo_dir).join('**/*.yml').to_s } + + before do + Pathname.new(todo_dir) + FileUtils.cp('spec/fixtures/rubocop_todo1.yml', rule1_file) + FileUtils.cp('spec/fixtures/rubocop_todo2.yml', rule2_file) + FileUtils.cp('spec/fixtures/rubocop_todo_not_autocorrectable.yml', not_autocorrectable_file) + end + + after do + FileUtils.remove_entry(todo_dir) + end + describe '#each_change' do it 'iterates over todo_dir_pattern files' do yielded_times = 0 @@ -116,3 +116,4 @@ end end end +# rubocop:enable RSpec/MultipleMemoizedHelpers -- GitLab