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
e39652bb
Commit
e39652bb
authored
Nov 15, 2016
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix cache regeneration for Geo and added Specs
parent
ff0508b5
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
179 additions
and
6 deletions
+179
-6
app/services/geo/schedule_repo_update_service.rb
app/services/geo/schedule_repo_update_service.rb
+3
-3
app/workers/geo_repository_update_worker.rb
app/workers/geo_repository_update_worker.rb
+3
-3
spec/services/geo/schedule_repo_update_service_spec.rb
spec/services/geo/schedule_repo_update_service_spec.rb
+55
-0
spec/workers/geo_repository_update_worker_spec.rb
spec/workers/geo_repository_update_worker_spec.rb
+118
-0
No files found.
app/services/geo/schedule_repo_update_service.rb
View file @
e39652bb
module
Geo
module
Geo
class
ScheduleRepoUpdateService
class
ScheduleRepoUpdateService
attr_reader
:id
,
:clone_url
attr_reader
:id
,
:clone_url
,
:push_data
def
initialize
(
params
)
def
initialize
(
params
)
@id
=
params
[
:project_id
]
@id
=
params
[
:project_id
]
@clone_url
=
params
[
:project
][
:git_ssh_url
]
@clone_url
=
params
[
:project
][
:git_ssh_url
]
@push_data
=
{
'type'
:
params
[
:object_kind
],
'before'
:
params
[
:before
],
@push_data
=
{
'type'
=>
params
[
:object_kind
],
'before'
=>
params
[
:before
],
'after'
:
params
[
:newref
],
'ref'
:
params
[
:ref
]
}
'after'
=>
params
[
:newref
],
'ref'
=>
params
[
:ref
]
}
end
end
def
execute
def
execute
...
...
app/workers/geo_repository_update_worker.rb
View file @
e39652bb
...
@@ -5,12 +5,12 @@ class GeoRepositoryUpdateWorker
...
@@ -5,12 +5,12 @@ class GeoRepositoryUpdateWorker
attr_accessor
:project
attr_accessor
:project
def
perform
(
project_id
,
clone_url
,
push_data
)
def
perform
(
project_id
,
clone_url
,
push_data
=
nil
)
@project
=
Project
.
find
(
project_id
)
@project
=
Project
.
find
(
project_id
)
@push_data
=
push_data
@push_data
=
push_data
fetch_repository
(
clone_url
)
fetch_repository
(
clone_url
)
process_hooks
process_hooks
if
push_data
# we should be compatible with old unprocessed data
end
end
private
private
...
@@ -23,7 +23,7 @@ class GeoRepositoryUpdateWorker
...
@@ -23,7 +23,7 @@ class GeoRepositoryUpdateWorker
def
process_hooks
def
process_hooks
if
@push_data
[
'type'
]
==
'push'
if
@push_data
[
'type'
]
==
'push'
branch
=
Gitlab
::
Git
.
branch_ref?
(
@push_data
[
'ref'
])
branch
=
Gitlab
::
Git
.
ref_name
(
@push_data
[
'ref'
])
process_push
(
branch
,
@push_data
[
'after'
])
process_push
(
branch
,
@push_data
[
'after'
])
end
end
end
end
...
...
spec/services/geo/schedule_repo_update_service_spec.rb
0 → 100644
View file @
e39652bb
require
'spec_helper'
describe
Geo
::
ScheduleRepoUpdateService
,
services:
true
do
include
RepoHelpers
let
(
:user
)
{
create
:user
}
let
(
:project
)
{
create
:project
}
let
(
:blankrev
)
{
Gitlab
::
Git
::
BLANK_SHA
}
let
(
:oldrev
)
{
sample_commit
.
parent_id
}
let
(
:newrev
)
{
sample_commit
.
id
}
let
(
:ref
)
{
'refs/heads/master'
}
let
(
:service
)
{
execute_push_service
(
project
,
user
,
oldrev
,
newrev
,
ref
)
}
before
do
project
.
team
<<
[
user
,
:master
]
end
subject
{
described_class
.
new
(
service
.
push_data
)
}
context
'parsed push_data'
do
it
'includes required params'
do
expect
(
subject
.
push_data
).
to
include
(
'type'
,
'before'
,
'after'
,
'ref'
)
end
end
context
'#execute'
do
let
(
:push_data
)
{
service
.
push_data
}
let
(
:args
)
do
[
project
.
id
,
push_data
[
:project
][
:git_ssh_url
],
{
'type'
=>
push_data
[
:object_kind
],
'before'
=>
push_data
[
:before
],
'after'
=>
push_data
[
:newref
],
'ref'
=>
push_data
[
:ref
]
}
]
end
it
'schedule update service'
do
expect
(
GeoRepositoryUpdateWorker
).
to
receive
(
:perform_async
).
with
(
*
args
)
subject
.
execute
end
end
def
execute_push_service
(
project
,
user
,
oldrev
,
newrev
,
ref
)
service
=
GitPushService
.
new
(
project
,
user
,
oldrev:
oldrev
,
newrev:
newrev
,
ref:
ref
)
service
.
execute
service
end
end
spec/workers/geo_repository_update_worker_spec.rb
0 → 100644
View file @
e39652bb
require
'spec_helper'
describe
GeoRepositoryUpdateWorker
do
include
RepoHelpers
let
(
:user
)
{
create
:user
}
let
(
:project
)
{
create
:project
}
let
(
:blankrev
)
{
Gitlab
::
Git
::
BLANK_SHA
}
let
(
:oldrev
)
{
sample_commit
.
parent_id
}
let
(
:newrev
)
{
sample_commit
.
id
}
let
(
:ref
)
{
'refs/heads/master'
}
let
(
:service
)
{
execute_push_service
(
project
,
user
,
oldrev
,
newrev
,
ref
)
}
let
(
:push_data
)
{
service
.
push_data
}
let
(
:parsed_push_data
)
do
{
'type'
=>
push_data
[
:object_kind
],
'before'
=>
push_data
[
:before
],
'after'
=>
push_data
[
:after
],
'ref'
=>
push_data
[
:ref
]
}
end
let
(
:clone_url
)
{
push_data
[
:project
][
:git_ssh_url
]
}
let
(
:performed
)
{
subject
.
perform
(
project
.
id
,
clone_url
,
parsed_push_data
)
}
before
do
project
.
team
<<
[
user
,
:master
]
expect
(
Project
).
to
receive
(
:find
).
at_least
(
:once
).
with
(
project
.
id
)
{
project
}
end
context
'when no repository'
do
before
do
allow
(
project
.
repository
).
to
receive
(
:fetch_geo_mirror
)
allow
(
project
).
to
receive
(
:repository_exists?
)
{
false
}
end
it
'creates a new repository'
do
expect
(
project
).
to
receive
(
:create_repository
)
performed
end
it
'executes after_create hook'
do
expect
(
project
.
repository
).
to
receive
(
:after_create
)
performed
end
end
context
'when empty repository'
do
before
do
allow
(
project
.
repository
).
to
receive
(
:fetch_geo_mirror
)
allow
(
project
).
to
receive
(
:empty_repo?
)
{
true
}
end
it
'executes after_create hook'
do
expect
(
project
.
repository
).
to
receive
(
:after_create
).
at_least
(
:once
)
performed
end
end
context
'#process_hooks'
do
before
{
allow
(
subject
).
to
receive
(
:fetch_repository
)
}
it
'calls if push_data is present'
do
expect
(
subject
).
to
receive
(
:process_hooks
)
performed
end
context
'when no push_data is present'
do
let
(
:parsed_push_data
)
{
nil
}
it
'skips process_hooks'
do
expect
(
subject
).
not_to
receive
(
:process_hooks
)
performed
end
end
end
context
'#process_push'
do
before
{
allow
(
subject
).
to
receive
(
:fetch_repository
)
}
it
'executes after_push_commit'
do
expect
(
project
.
repository
).
to
receive
(
:after_push_commit
).
at_least
(
:once
).
with
(
'master'
,
newrev
)
performed
end
context
'when removing branch'
do
it
'executes after_remove_branch'
do
allow
(
subject
).
to
receive
(
:push_remove_branch?
)
{
true
}
expect
(
project
.
repository
).
to
receive
(
:after_remove_branch
)
performed
end
end
context
'when updating a new branch'
do
it
'executes after_create_branch'
do
allow
(
subject
).
to
receive
(
:push_to_new_branch?
)
{
true
}
expect
(
project
.
repository
).
to
receive
(
:after_create_branch
)
performed
end
end
end
def
execute_push_service
(
project
,
user
,
oldrev
,
newrev
,
ref
)
service
=
GitPushService
.
new
(
project
,
user
,
oldrev:
oldrev
,
newrev:
newrev
,
ref:
ref
)
service
.
execute
service
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