Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
2be13fa865a2
Commit
bafec400
authored
Apr 06, 2015
by
Valery Sizov
Browse files
CI forking: tests
parent
e8889aeb4d72
Changes
6
Hide whitespace changes
Inline
Side-by-side
app/models/project_services/gitlab_ci_service.rb
View file @
2be13fa8
...
...
@@ -18,6 +18,8 @@
#
class
GitlabCiService
<
CiService
API_PREFIX
=
"api/v1"
prop_accessor
:project_url
,
:token
validates
:project_url
,
presence:
true
,
if: :activated?
validates
:token
,
presence:
true
,
if: :activated?
...
...
@@ -59,7 +61,7 @@ def commit_status(sha, ref)
end
end
def
regist
er_fork
(
new_project
,
user
_token
)
def
fork_
regist
ration
(
new_project
,
private
_token
)
params
=
{
id:
new_project
.
id
,
name_with_namespace:
new_project
.
name_with_namespace
,
...
...
@@ -69,12 +71,12 @@ def register_fork(new_project, user_token)
}
HTTParty
.
post
(
regist
er_fork
_path
,
fork_
regist
ration
_path
,
body:
{
project_id:
project
.
id
,
project_token:
token
,
user
_token:
user
_token
,
data:
params
.
to_yaml
},
private
_token:
private
_token
,
data:
params
},
verify:
false
)
end
...
...
@@ -95,10 +97,6 @@ def builds_path
project_url
+
"?ref="
+
project
.
default_branch
end
def
register_fork_path
project_url
.
sub
(
/projects\/\d*/
,
'api/v1/forks'
)
end
def
status_img_path
project_url
+
"/status.png?ref="
+
project
.
default_branch
end
...
...
@@ -121,4 +119,10 @@ def fields
{
type:
'text'
,
name:
'project_url'
,
placeholder:
'http://ci.gitlabhq.com/projects/3'
}
]
end
private
def
fork_registration_path
project_url
.
sub
(
/projects\/\d*/
,
"
#{
API_PREFIX
}
/forks"
)
end
end
app/services/projects/fork_service.rb
View file @
2be13fa8
...
...
@@ -50,7 +50,7 @@ def execute
end
if
@from_project
.
gitlab_ci?
ForkRegistrat
or
Worker
.
perform_async
(
@from_project
.
id
,
project
.
id
,
@current_user
.
private_token
)
ForkRegistrat
ion
Worker
.
perform_async
(
@from_project
.
id
,
project
.
id
,
@current_user
.
private_token
)
end
rescue
=>
ex
project
.
errors
.
add
(
:base
,
'Fork transaction failed.'
)
...
...
app/workers/fork_registrat
or
_worker.rb
→
app/workers/fork_registrat
ion
_worker.rb
View file @
2be13fa8
class
ForkRegistrat
or
Worker
class
ForkRegistrat
ion
Worker
include
Sidekiq
::
Worker
sidekiq_options
queue: :default
...
...
@@ -7,6 +7,6 @@ def perform(from_project_id, to_project_id, private_token)
from_project
=
Project
.
find
(
from_project_id
)
to_project
=
Project
.
find
(
to_project_id
)
from_project
.
gitlab_ci_service
.
regist
er_fork
(
to_project
,
private_token
)
from_project
.
gitlab_ci_service
.
fork_
regist
ration
(
to_project
,
private_token
)
end
end
spec/models/project_services/gitlab_ci_service_spec.rb
View file @
2be13fa8
...
...
@@ -46,4 +46,25 @@
it
{
expect
(
@service
.
build_page
(
"2ab7834c"
,
'master'
)).
to
eq
(
"http://ci.gitlab.org/projects/2/refs/master/commits/2ab7834c"
)}
end
end
describe
"Fork registration"
do
before
do
@old_project
=
create
(
:empty_project
)
@project
=
create
(
:empty_project
)
@user
=
create
(
:user
)
@service
=
GitlabCiService
.
new
@service
.
stub
(
service_hook:
true
,
project_url:
'http://ci.gitlab.org/projects/2'
,
token:
'verySecret'
,
project:
@old_project
)
end
it
"performs http reuquest to ci"
do
stub_request
(
:post
,
"http://ci.gitlab.org/api/v1/forks"
)
@service
.
fork_registration
(
@project
,
@user
.
private_token
)
end
end
end
spec/services/projects/fork_service_spec.rb
View file @
2be13fa8
...
...
@@ -40,6 +40,17 @@
expect
(
@to_project
.
errors
[
:base
]).
not_to
include
(
"Fork transaction failed."
)
end
end
context
'GitLab CI is enabled'
do
it
"calls fork registrator for CI"
do
@from_project
.
build_missing_services
@from_project
.
gitlab_ci_service
.
update_attributes
(
active:
true
)
expect
(
ForkRegistrationWorker
).
to
receive
(
:perform_async
)
fork_project
(
@from_project
,
@to_user
)
end
end
end
describe
:fork_to_namespace
do
...
...
@@ -89,7 +100,8 @@
def
fork_project
(
from_project
,
user
,
fork_success
=
true
,
params
=
{})
context
=
Projects
::
ForkService
.
new
(
from_project
,
user
,
params
)
shell
=
double
(
'gitlab_shell'
).
stub
(
fork_repository:
fork_success
)
shell
=
double
(
'gitlab_shell'
)
shell
.
stub
(
fork_repository:
fork_success
)
context
.
stub
(
gitlab_shell:
shell
)
context
.
execute
end
...
...
spec/workers/fork_registration_worker_spec.rb
0 → 100644
View file @
2be13fa8
require
'spec_helper'
describe
ForkRegistrationWorker
do
context
"as a resque worker"
do
it
"reponds to #perform"
do
expect
(
ForkRegistrationWorker
.
new
).
to
respond_to
(
:perform
)
end
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