Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
cd74ff03
Commit
cd74ff03
authored
Mar 05, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sync snippet after git action
parent
67502abd
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
2 deletions
+58
-2
app/models/snippet.rb
app/models/snippet.rb
+2
-0
app/workers/post_receive.rb
app/workers/post_receive.rb
+5
-0
changelogs/unreleased/fj-update-snippet-from-git-action.yml
changelogs/unreleased/fj-update-snippet-from-git-action.yml
+5
-0
spec/models/snippet_spec.rb
spec/models/snippet_spec.rb
+26
-0
spec/workers/post_receive_spec.rb
spec/workers/post_receive_spec.rb
+20
-2
No files found.
app/models/snippet.rb
View file @
cd74ff03
...
@@ -197,6 +197,8 @@ class Snippet < ApplicationRecord
...
@@ -197,6 +197,8 @@ class Snippet < ApplicationRecord
end
end
def
blobs
def
blobs
return
[]
unless
repository_exists?
repository
.
ls_files
(
repository
.
root_ref
).
map
{
|
file
|
Blob
.
lazy
(
self
,
repository
.
root_ref
,
file
)
}
repository
.
ls_files
(
repository
.
root_ref
).
map
{
|
file
|
Blob
.
lazy
(
self
,
repository
.
root_ref
,
file
)
}
end
end
...
...
app/workers/post_receive.rb
View file @
cd74ff03
...
@@ -77,6 +77,11 @@ class PostReceive # rubocop:disable Scalability/IdempotentWorker
...
@@ -77,6 +77,11 @@ class PostReceive # rubocop:disable Scalability/IdempotentWorker
return
false
unless
user
return
false
unless
user
# We can remove once we implement multi-file snippets
# https://gitlab.com/gitlab-org/gitlab/-/issues/39269
blob
=
snippet
.
blobs
.
first
snippet
.
update
(
file_name:
blob
.
path
,
content:
blob
.
data
)
if
blob
# At the moment, we only expires the repository caches.
# At the moment, we only expires the repository caches.
# In the future we might need to call ProjectCacheWorker
# In the future we might need to call ProjectCacheWorker
# (or the custom class we create) to update the snippet
# (or the custom class we create) to update the snippet
...
...
changelogs/unreleased/fj-update-snippet-from-git-action.yml
0 → 100644
View file @
cd74ff03
---
title
:
Sync snippet after Git action
merge_request
:
26565
author
:
type
:
changed
spec/models/snippet_spec.rb
View file @
cd74ff03
...
@@ -511,6 +511,32 @@ describe Snippet do
...
@@ -511,6 +511,32 @@ describe Snippet do
end
end
end
end
describe
'#blobs'
do
let
(
:snippet
)
{
create
(
:snippet
)
}
context
'when repository does not exist'
do
it
'returns empty array'
do
expect
(
snippet
.
blobs
).
to
be_empty
end
end
context
'when repository exists'
do
let
(
:snippet
)
{
create
(
:snippet
,
:repository
)
}
it
'returns array of blobs'
do
expect
(
snippet
.
blobs
).
to
all
(
be_a
(
Blob
))
end
end
it
'returns a blob representing the snippet data'
do
blob
=
snippet
.
blob
expect
(
blob
).
to
be_a
(
Blob
)
expect
(
blob
.
path
).
to
eq
(
snippet
.
file_name
)
expect
(
blob
.
data
).
to
eq
(
snippet
.
content
)
end
end
describe
'#to_json'
do
describe
'#to_json'
do
let
(
:snippet
)
{
build
(
:snippet
)
}
let
(
:snippet
)
{
build
(
:snippet
)
}
...
...
spec/workers/post_receive_spec.rb
View file @
cd74ff03
...
@@ -421,17 +421,35 @@ describe PostReceive do
...
@@ -421,17 +421,35 @@ describe PostReceive do
perform
perform
end
end
end
end
it
'updates the snippet db information'
do
blob
=
snippet
.
blobs
.
first
expect
(
snippet
).
to
receive
(
:update
).
with
(
file_name:
blob
.
path
,
content:
blob
.
data
)
perform
end
context
'when snippet does not have any blob'
do
it
'does not update snippet db information'
do
allow
(
snippet
).
to
receive
(
:blobs
).
and_return
([])
expect
(
snippet
).
not_to
receive
(
:update
)
perform
end
end
end
end
end
end
context
'with PersonalSnippet'
do
context
'with PersonalSnippet'
do
let!
(
:snippet
)
{
create
(
:personal_snippet
,
author:
project
.
owner
)
}
let!
(
:snippet
)
{
create
(
:personal_snippet
,
:repository
,
author:
project
.
owner
)
}
it_behaves_like
'snippet changes actions'
it_behaves_like
'snippet changes actions'
end
end
context
'with ProjectSnippet'
do
context
'with ProjectSnippet'
do
let!
(
:snippet
)
{
create
(
:project_snippet
,
project:
project
,
author:
project
.
owner
)
}
let!
(
:snippet
)
{
create
(
:project_snippet
,
:repository
,
project:
project
,
author:
project
.
owner
)
}
it_behaves_like
'snippet changes actions'
it_behaves_like
'snippet changes actions'
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment