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
ff82c583
Commit
ff82c583
authored
Dec 12, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some specs for cross project pipeline creation service
parent
bf9c09d7
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
73 additions
and
4 deletions
+73
-4
ee/app/models/ci/sources/pipeline.rb
ee/app/models/ci/sources/pipeline.rb
+1
-1
ee/app/models/ee/commit_status_enums.rb
ee/app/models/ee/commit_status_enums.rb
+2
-1
ee/app/services/ci/create_cross_project_pipeline_service.rb
ee/app/services/ci/create_cross_project_pipeline_service.rb
+2
-0
ee/spec/services/ci/create_cross_project_pipeline_service_spec.rb
...services/ci/create_cross_project_pipeline_service_spec.rb
+66
-0
spec/factories/ci/bridge.rb
spec/factories/ci/bridge.rb
+1
-1
spec/models/ci/bridge_spec.rb
spec/models/ci/bridge_spec.rb
+1
-1
No files found.
ee/app/models/ci/sources/pipeline.rb
View file @
ff82c583
...
...
@@ -9,7 +9,7 @@ module Ci
belongs_to
:pipeline
,
class_name:
Ci
::
Pipeline
belongs_to
:source_project
,
class_name:
Project
,
foreign_key: :source_project_id
belongs_to
:source_job
,
class_name:
C
i
::
Build
,
foreign_key: :source_job_id
belongs_to
:source_job
,
class_name:
C
ommitStatus
,
foreign_key: :source_job_id
belongs_to
:source_pipeline
,
class_name:
Ci
::
Pipeline
,
foreign_key: :source_pipeline_id
validates
:project
,
presence:
true
...
...
ee/app/models/ee/commit_status_enums.rb
View file @
ff82c583
...
...
@@ -9,7 +9,8 @@ module EE
override
:failure_reasons
def
failure_reasons
super
.
merge
(
protected_environment_failure:
1_000
)
super
.
merge
(
protected_environment_failure:
1_000
,
insufficient_permissions:
1_001
)
end
end
end
...
...
ee/app/services/ci/create_cross_project_pipeline_service.rb
View file @
ff82c583
...
...
@@ -25,6 +25,8 @@ module Ci
private
def
can_create_cross_pipeline?
# TODO should we check update_pipeline in the first condition?
#
can?
(
current_user
,
:create_pipeline
,
project
)
&&
can?
(
current_user
,
:create_pipeline
,
target_project
)
&&
can?
(
@bridge
.
target_user
,
:create_pipeline
,
target_project
)
...
...
ee/spec/services/ci/create_cross_project_pipeline_service_spec.rb
0 → 100644
View file @
ff82c583
require
'spec_helper'
describe
Ci
::
CreateCrossProjectPipelineService
,
'#execute'
do
set
(
:upstream_project
)
{
create
(
:project
,
:repository
)
}
set
(
:downstream_project
)
{
create
(
:project
,
:repository
)
}
set
(
:upstream_pipeline
)
{
create
(
:ci_pipeline
,
project:
upstream_project
)
}
set
(
:user
)
{
create
(
:user
)
}
let
(
:trigger
)
do
{
trigger:
{
project:
downstream_project
.
full_path
,
branch:
'feature'
}
}
end
let
(
:bridge
)
do
create
(
:ci_bridge
,
user:
user
,
options:
trigger
,
pipeline:
upstream_pipeline
)
end
let
(
:service
)
{
described_class
.
new
(
upstream_project
,
user
)
}
before
do
stub_ci_pipeline_to_return_yaml_file
upstream_project
.
add_developer
(
user
)
end
context
'when user does not have ability to create a pipeline'
do
it
'changes status of the bridge build'
do
expect
{
service
.
execute
(
bridge
)
}
.
not_to
change
{
Ci
::
Pipeline
.
count
}
expect
(
bridge
).
to
be_failed
expect
(
bridge
.
failure_reason
).
to
eq
'insufficient_permissions'
end
end
context
'when user can create pipeline in a downstream project'
do
before
do
downstream_project
.
add_developer
(
user
)
end
it
'creates a new pipeline'
do
expect
{
service
.
execute
(
bridge
)
}
.
to
change
{
Ci
::
Pipeline
.
count
}.
by
(
1
)
end
it
'creates a new pipeline in a downstream project'
do
pipeline
=
service
.
execute
(
bridge
)
expect
(
pipeline
.
project
).
to
eq
downstream_project
expect
(
bridge
.
sourced_pipelines
.
first
.
pipeline
).
to
eq
pipeline
expect
(
pipeline
.
source_pipeline
.
source_pipeline
).
to
eq
upstream_pipeline
expect
(
pipeline
.
source_pipeline
.
source_job
).
to
eq
bridge
end
it
'delegates permissions to newly created pipelines'
do
pipeline
=
service
.
execute
(
bridge
)
expect
(
pipeline
.
user
).
to
eq
bridge
.
user
end
end
end
spec/factories/ci/bridge.rb
View file @
ff82c583
...
...
@@ -6,7 +6,7 @@ FactoryBot.define do
ref
'master'
tag
false
created_at
'Di 29. Okt 09:50:00 CET 2013'
status
:
success
status
:
created
pipeline
factory: :ci_pipeline
...
...
spec/models/ci/bridge_spec.rb
View file @
ff82c583
...
...
@@ -5,7 +5,7 @@ describe Ci::Bridge do
set
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
let
(
:bridge
)
do
create
(
:ci_bridge
,
pipeline:
pipeline
)
create
(
:ci_bridge
,
status: :success
,
pipeline:
pipeline
)
end
describe
'#tags'
do
...
...
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