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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
932d3251
Commit
932d3251
authored
Aug 24, 2017
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move to Projects::HousecleaningService
parent
5c31c720
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
49 deletions
+47
-49
app/models/project.rb
app/models/project.rb
+1
-1
app/services/projects/housecleaning_service.rb
app/services/projects/housecleaning_service.rb
+40
-0
app/services/projects/import_export/cleanup_service.rb
app/services/projects/import_export/cleanup_service.rb
+0
-42
spec/models/project_spec.rb
spec/models/project_spec.rb
+5
-5
spec/services/projects/housecleaning_service_spec.rb
spec/services/projects/housecleaning_service_spec.rb
+1
-1
No files found.
app/models/project.rb
View file @
932d3251
...
...
@@ -372,7 +372,7 @@ class Project < ActiveRecord::Base
if
Gitlab
::
ImportSources
.
importer_names
.
include?
(
project
.
import_type
)
&&
project
.
repo_exists?
project
.
run_after_commit
do
begin
Projects
::
ImportExport
::
Cleanup
Service
.
new
(
project
).
execute
Projects
::
Housecleaning
Service
.
new
(
project
).
execute
rescue
Projects
::
HousekeepingService
::
LeaseTaken
=>
e
Rails
.
logger
.
info
(
"Could not perform housekeeping for project
#{
project
.
full_path
}
(
#{
project
.
id
}
):
#{
e
}
"
)
end
...
...
app/services/projects/housecleaning_service.rb
0 → 100644
View file @
932d3251
module
Projects
class
HousecleaningService
def
self
.
reserved_refs_names
%w[heads tags merge-requests keep-around environments]
end
def
self
.
reserved_refs_regexp
names
=
reserved_refs_names
.
map
(
&
Regexp
.
method
(
:escape
)).
join
(
'|'
)
%r{
\A
refs/(?:
#{
names
}
)/}
end
def
initialize
(
project
)
@project
=
project
end
# This could raise Projects::HousekeepingService::LeaseTaken
def
execute
Projects
::
HousekeepingService
.
new
(
@project
).
execute
do
garbage_refs
.
each
(
&
rugged
.
references
.
method
(
:delete
))
end
end
private
def
garbage_refs
@garbage_refs
||=
begin
reserved_refs_regexp
=
self
.
class
.
reserved_refs_regexp
rugged
.
references
.
reject
do
|
ref
|
ref
.
name
=~
reserved_refs_regexp
end
end
end
def
rugged
@rugged
||=
@project
.
repository
.
rugged
end
end
end
app/services/projects/import_export/cleanup_service.rb
deleted
100644 → 0
View file @
5c31c720
module
Projects
module
ImportExport
class
CleanupService
def
self
.
reserved_refs_names
%w[heads tags merge-requests keep-around environments]
end
def
self
.
reserved_refs_regexp
names
=
reserved_refs_names
.
map
(
&
Regexp
.
method
(
:escape
)).
join
(
'|'
)
%r{
\A
refs/(?:
#{
names
}
)/}
end
def
initialize
(
project
)
@project
=
project
end
# This could raise Projects::HousekeepingService::LeaseTaken
def
execute
Projects
::
HousekeepingService
.
new
(
@project
).
execute
do
garbage_refs
.
each
(
&
rugged
.
references
.
method
(
:delete
))
end
end
private
def
garbage_refs
@garbage_refs
||=
begin
reserved_refs_regexp
=
self
.
class
.
reserved_refs_regexp
rugged
.
references
.
reject
do
|
ref
|
ref
.
name
=~
reserved_refs_regexp
end
end
end
def
rugged
@rugged
||=
@project
.
repository
.
rugged
end
end
end
end
spec/models/project_spec.rb
View file @
932d3251
...
...
@@ -1563,14 +1563,14 @@ describe Project do
describe
'project import state transitions'
do
context
'state transition: [:started] => [:finished]'
do
let
(
:
cleanup_service
)
{
spy
(
:cleanup
_service
)
}
let
(
:
housecleaning_service
)
{
spy
(
:housecleaning
_service
)
}
let
(
:housekeeping_service
)
{
spy
(
:housekeeping_service
)
}
before
do
allow
(
Projects
::
ImportExport
::
Cleanup
Service
)
.
to
receive
(
:new
)
{
cleanup
_service
}
allow
(
Projects
::
Housecleaning
Service
)
.
to
receive
(
:new
)
{
housecleaning
_service
}
allow
(
cleanup
_service
)
allow
(
housecleaning
_service
)
.
to
receive
(
:execute
)
{
housekeeping_service
.
execute
}
allow
(
Projects
::
HousekeepingService
)
...
...
@@ -1589,7 +1589,7 @@ describe Project do
project
.
import_finish
expect
(
cleanup
_service
).
to
have_received
(
:execute
)
expect
(
housecleaning
_service
).
to
have_received
(
:execute
)
expect
(
housekeeping_service
).
to
have_received
(
:execute
)
end
...
...
spec/services/projects/
import_export/cleanup
_service_spec.rb
→
spec/services/projects/
housecleaning
_service_spec.rb
View file @
932d3251
require
'spec_helper'
describe
Projects
::
ImportExport
::
Cleanup
Service
do
describe
Projects
::
Housecleaning
Service
do
subject
{
described_class
.
new
(
project
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
...
...
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