debian-mirror-gitlab/db/fixtures/development/12_snippets.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
1.3 KiB
Ruby
Raw Normal View History

2020-01-01 13:55:28 +05:30
require './spec/support/sidekiq_middleware'
2017-08-17 22:00:37 +05:30
2020-10-24 23:57:45 +05:30
SNIPPET_REPO_URL = "https://gitlab.com/gitlab-org/gitlab-snippet-test.git"
2021-01-29 00:20:46 +05:30
BUNDLE_PATH = File.join(Rails.root, 'db/fixtures/development/gitlab-snippet-test.bundle')
class Gitlab::Seeder::SnippetRepository
def initialize(snippet)
@snippet = snippet
end
def import
if File.exists?(BUNDLE_PATH)
@snippet.repository.create_from_bundle(BUNDLE_PATH)
else
@snippet.repository.import_repository(SNIPPET_REPO_URL)
@snippet.repository.bundle_to_disk(BUNDLE_PATH)
end
end
def self.cleanup
File.delete(BUNDLE_PATH) if File.exists?(BUNDLE_PATH)
rescue => e
warn "\nError cleaning up snippet bundle: #{e}"
end
end
2015-04-26 12:48:37 +05:30
2020-10-24 23:57:45 +05:30
Gitlab::Seeder.quiet do
20.times do |i|
2019-12-26 22:10:19 +05:30
user = User.not_mass_generated.sample
2014-09-02 18:07:02 +05:30
2020-10-24 23:57:45 +05:30
user.snippets.create({
type: 'PersonalSnippet',
2015-09-11 14:41:01 +05:30
title: FFaker::Lorem.sentence(3),
2020-10-24 23:57:45 +05:30
file_name: 'file.rb',
2015-04-26 12:48:37 +05:30
visibility_level: Gitlab::VisibilityLevel.values.sample,
2020-10-24 23:57:45 +05:30
content: 'foo'
}).tap do |snippet|
2022-07-23 23:45:48 +05:30
snippet.repository.expire_exists_cache
2020-10-24 23:57:45 +05:30
unless snippet.repository_exists?
2021-01-29 00:20:46 +05:30
Gitlab::Seeder::SnippetRepository.new(snippet).import
2020-10-24 23:57:45 +05:30
end
snippet.track_snippet_repository(snippet.repository.storage)
snippet.statistics.refresh!
end
2015-04-26 12:48:37 +05:30
2014-09-02 18:07:02 +05:30
print('.')
end
2021-01-29 00:20:46 +05:30
Gitlab::Seeder::SnippetRepository.cleanup
2014-09-02 18:07:02 +05:30
end