Create repository when snippet is created

When the snippet is successfully created through
the service, the snippet repository is created.
parent d3ee57b1
......@@ -24,7 +24,9 @@ module Snippets
spam_check(snippet, current_user)
snippet_saved = snippet.with_transaction_returning_status do
snippet.save
if snippet.save && snippet.store_mentions!
create_repository_for(snippet, current_user)
end
end
if snippet_saved
......@@ -36,5 +38,11 @@ module Snippets
snippet_error_response(snippet, 400)
end
end
private
def create_repository_for(snippet, user)
snippet.create_repository if Feature.enabled?(:version_snippets, user)
end
end
end
---
title: Create snippet repository when it's created
merge_request: 22269
author:
type: added
......@@ -143,6 +143,34 @@ describe Snippets::CreateService do
end
end
shared_examples 'creates repository' do
it do
subject
expect(snippet.repository_exists?).to be_truthy
end
context 'when snippet creation fails' do
let(:extra_opts) { { content: nil } }
it 'does not create repository' do
subject
expect(snippet.repository_exists?).to be_falsey
end
end
context 'when feature flag :version_snippets is disabled' do
it 'does not create snippet repository' do
stub_feature_flags(version_snippets: false)
subject
expect(snippet.repository_exists?).to be_falsey
end
end
end
context 'when Project Snippet' do
let_it_be(:project) { create(:project) }
......@@ -155,6 +183,7 @@ describe Snippets::CreateService do
it_behaves_like 'spam check is performed'
it_behaves_like 'snippet create data is tracked'
it_behaves_like 'an error service response when save fails'
it_behaves_like 'creates repository'
end
context 'when PersonalSnippet' do
......@@ -165,6 +194,7 @@ describe Snippets::CreateService do
it_behaves_like 'spam check is performed'
it_behaves_like 'snippet create data is tracked'
it_behaves_like 'an error service response when save fails'
it_behaves_like 'creates repository'
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment