diff --git a/lib/obs_deploy/check_diff.rb b/lib/obs_deploy/check_diff.rb index 3f723a5..f567629 100644 --- a/lib/obs_deploy/check_diff.rb +++ b/lib/obs_deploy/check_diff.rb @@ -49,6 +49,12 @@ def migrations GitDiffParser.parse(github_diff).files.select { |f| f =~ %r{db/migrate} } end + def data_migrations + return [] unless data_migration? + + GitDiffParser.parse(github_diff).files.select { |f| f =~ %r{db/data} } + end + def package_url URI("#{@server}/public/build/#{@project}/#{@product}/x86_64/obs-server") end diff --git a/lib/obs_deploy/cli/commands/get_pending_migration.rb b/lib/obs_deploy/cli/commands/get_pending_migration.rb index 7e4ebc8..2ee8d82 100644 --- a/lib/obs_deploy/cli/commands/get_pending_migration.rb +++ b/lib/obs_deploy/cli/commands/get_pending_migration.rb @@ -18,12 +18,14 @@ def call(url:, targeturl:, ignore_certificate:, **) end migrations = ObsDeploy::CheckDiff.new(server: url, target_server: targeturl).migrations + data_migrations = ObsDeploy::CheckDiff.new(server: url, target_server: targeturl).data_migrations - if migrations.empty? + if migrations.empty? && data_migrations.empty? puts 'No pending migrations' exit(0) else - puts migrations + puts migrations if migrations + puts data_migrations if data_migrations exit(1) end end diff --git a/spec/check_diff_spec.rb b/spec/check_diff_spec.rb index 231c029..938abf1 100644 --- a/spec/check_diff_spec.rb +++ b/spec/check_diff_spec.rb @@ -140,4 +140,40 @@ end end end + + describe '#data_migrations' do + subject { check_diff.data_migrations } + + context 'no pending data migration' do + let(:diff_url) { "https://github.com/openSUSE/open-build-service/compare/#{running_commit}...#{package_commit}.diff" } + let(:fixture_file) { File.new('spec/fixtures/github_diff_without_migration.txt') } + let(:running_commit) { 'bc7f6c0' } + let(:package_commit) { '554e943' } + before do + allow(check_diff).to receive(:obs_running_commit).and_return(running_commit) + allow(check_diff).to receive(:package_commit).and_return(package_commit) + stub_request(:get, diff_url).to_return(fixture_file) + end + + it { expect(check_diff.github_diff).not_to be_empty } + it { expect(check_diff.data_migration?).to be false } + end + + context 'data is present' do + let(:diff_url) { "https://github.com/openSUSE/open-build-service/compare/#{running_commit}...#{package_commit}.diff" } + before do + allow(check_diff).to receive(:obs_running_commit).and_return(running_commit) + allow(check_diff).to receive(:package_commit).and_return(package_commit) + stub_request(:get, diff_url).to_return(fixture_file) + end + + context 'pending data migration' do + let(:fixture_file) { File.new('spec/fixtures/github_diff_with_data_migration.txt') } + let(:data_migration_file) { 'db/data/20200424080753_generate_web_notifications.rb' } + let(:running_commit) { '2392177' } + let(:package_commit) { '8c6783b' } + it { expect(subject.first).to include(data_migration_file) } + end + end + end end