Commit dd902ebc authored by James Lopez's avatar James Lopez

Merge branch 'fj-39199-create-snippet-repository' into 'master'

Create snippet repository after it is created

Closes #39199

See merge request gitlab-org/gitlab!22269
parents 5a3d660a 677b69b1
...@@ -24,7 +24,9 @@ module Snippets ...@@ -24,7 +24,9 @@ module Snippets
spam_check(snippet, current_user) spam_check(snippet, current_user)
snippet_saved = snippet.with_transaction_returning_status do snippet_saved = snippet.with_transaction_returning_status do
snippet.save if snippet.save && snippet.store_mentions!
create_repository_for(snippet, current_user)
end
end end
if snippet_saved if snippet_saved
...@@ -36,5 +38,11 @@ module Snippets ...@@ -36,5 +38,11 @@ module Snippets
snippet_error_response(snippet, 400) snippet_error_response(snippet, 400)
end end
end end
private
def create_repository_for(snippet, user)
snippet.create_repository if Feature.enabled?(:version_snippets, user)
end
end 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 ...@@ -143,6 +143,34 @@ describe Snippets::CreateService do
end end
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 context 'when Project Snippet' do
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
...@@ -155,6 +183,7 @@ describe Snippets::CreateService do ...@@ -155,6 +183,7 @@ describe Snippets::CreateService do
it_behaves_like 'spam check is performed' it_behaves_like 'spam check is performed'
it_behaves_like 'snippet create data is tracked' it_behaves_like 'snippet create data is tracked'
it_behaves_like 'an error service response when save fails' it_behaves_like 'an error service response when save fails'
it_behaves_like 'creates repository'
end end
context 'when PersonalSnippet' do context 'when PersonalSnippet' do
...@@ -165,6 +194,7 @@ describe Snippets::CreateService do ...@@ -165,6 +194,7 @@ describe Snippets::CreateService do
it_behaves_like 'spam check is performed' it_behaves_like 'spam check is performed'
it_behaves_like 'snippet create data is tracked' it_behaves_like 'snippet create data is tracked'
it_behaves_like 'an error service response when save fails' it_behaves_like 'an error service response when save fails'
it_behaves_like 'creates repository'
end end
end 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