<commit_before>describe Travis::API::V3::Models::RepositoryMigration do
  let(:repository) { Factory(:repository) }

  subject { Travis::API::V3::Models::RepositoryMigration.new(repository) }

  before do
    Travis::Features.stubs(:feature_active?).with(:multi_os).returns(true)
    Travis::Features.stubs(:feature_active?).with(:dist_group_expansion).returns(true)
  end

  context 'when migration is enabled globally' do
    before { Travis::Features.expects(:feature_active?).with(:allow_merge_globally).returns(true) }

    context 'when migration is enabled for owner' do
      before { Travis::Features.expects(:owner_active?).with(:allow_migration, repository.owner).returns(true) }

      it 'migrates repository' do
        request = stub_request(:post, "#{Travis.config.merge.api_url}/api/repo/by_github_id/#{repository.id}/migrate")
        subject.migrate!
        expect(request).to have_been_requested
      end
    end

    context 'when migration is disabled for owner' do
      before { Travis::Features.expects(:owner_active?).with(:allow_migration, repository.owner).returns(false) }

      it 'raises error' do
        expect { subject.migrate! }.to raise_error(Travis::API::V3::Models::RepositoryMigration::MigrationDisabledError)
      end
    end
  end

  context 'when migration is disabled globally' do
    before { Travis::Features.expects(:feature_active?).with(:allow_merge_globally).returns(false) }

    it 'raises error' do
      expect { subject.migrate! }.to raise_error(Travis::API::V3::Models::RepositoryMigration::MigrationDisabledError)
    end
  end
end
<commit_msg>Create a global feature flag to enable/disable the migration feature entirely<commit_after>describe Travis::API::V3::Models::RepositoryMigration do
  let(:repository) { Factory(:repository) }

  subject { Travis::API::V3::Models::RepositoryMigration.new(repository) }

  before do
    Travis::Features.stubs(:feature_active?).with(:multi_os).returns(true)
    Travis::Features.stubs(:feature_active?).with(:dist_group_expansion).returns(true)
  end

  context 'when migration is enabled globally' do
    before { Travis::Features.expects(:feature_active?).with(:allow_merge_globally).returns(true) }

    context 'when migration is enabled for owner' do
      before { Travis::Features.expects(:owner_active?).with(:allow_migration, repository.owner).returns(true) }

      it 'migrates repository' do
        request = stub_request(:post, "#{Travis.config.merge.api_url}/api/repo/by_github_id/#{subject.repository.id}/migrate")
        subject.migrate!
        expect(request).to have_been_requested
      end
    end

    context 'when migration is disabled for owner' do
      before { Travis::Features.expects(:owner_active?).with(:allow_migration, repository.owner).returns(false) }

      it 'raises error' do
        expect { subject.migrate! }.to raise_error(Travis::API::V3::Models::RepositoryMigration::MigrationDisabledError)
      end
    end
  end

  context 'when migration is disabled globally' do
    before { Travis::Features.expects(:feature_active?).with(:allow_merge_globally).returns(false) }

    it 'raises error' do
      expect { subject.migrate! }.to raise_error(Travis::API::V3::Models::RepositoryMigration::MigrationDisabledError)
    end
  end
end

{'fraction_non_alphanumeric': 0.12431444241316271, 'fraction_numerical': 0.002437538086532602, 'mean_word_length': 4.810619469026548, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2756068', 'n_tokens_mistral': 977, 'n_tokens_neox': 958, 'n_words': 182}