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
aa290573
Commit
aa290573
authored
Jan 24, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a new service for creating detached CI/CD jobs
parent
e7333324
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
10 deletions
+54
-10
app/models/commit_status.rb
app/models/commit_status.rb
+3
-1
app/services/ci/create_job_service.rb
app/services/ci/create_job_service.rb
+12
-0
app/services/projects/update_pages_service.rb
app/services/projects/update_pages_service.rb
+10
-8
lib/api/commit_statuses.rb
lib/api/commit_statuses.rb
+9
-1
spec/services/ci/create_job_service_spec.rb
spec/services/ci/create_job_service_spec.rb
+20
-0
No files found.
app/models/commit_status.rb
View file @
aa290573
...
...
@@ -50,7 +50,9 @@ class CommitStatus < ActiveRecord::Base
##
# We still create some CommitStatuses outside of CreatePipelineService.
#
# These are pages deployments and external statuses.
# These are pages deployments and external statuses. We now handle these
# using CreateJobService, but we still need to ensure that a job has a
# stage assigned. TODO, In future releases we will add model validation.
#
before_create
unless: :importing?
do
Ci
::
EnsureStageService
.
new
(
project
,
user
).
execute
(
self
)
do
|
stage
|
...
...
app/services/ci/create_job_service.rb
0 → 100644
View file @
aa290573
module
Ci
class
CreateJobService
<
BaseService
def
execute
(
subject
=
nil
)
(
subject
||
yield
).
tap
do
|
subject
|
Ci
::
EnsureStageService
.
new
(
project
,
current_user
)
.
execute
(
subject
)
subject
.
save!
end
end
end
end
app/services/projects/update_pages_service.rb
View file @
aa290573
...
...
@@ -58,14 +58,16 @@ module Projects
end
def
create_status
GenericCommitStatus
.
new
(
project:
project
,
pipeline:
build
.
pipeline
,
user:
build
.
user
,
ref:
build
.
ref
,
stage:
'deploy'
,
name:
'pages:deploy'
)
Ci
::
CreateJobService
.
new
(
project
,
build
.
user
).
execute
do
GenericCommitStatus
.
new
(
project:
project
,
pipeline:
build
.
pipeline
,
user:
build
.
user
,
ref:
build
.
ref
,
stage:
'deploy'
,
name:
'pages:deploy'
)
end
end
def
extract_archive!
(
temp_path
)
...
...
lib/api/commit_statuses.rb
View file @
aa290573
...
...
@@ -69,6 +69,7 @@ module API
name
=
params
[
:name
]
||
params
[
:context
]
||
'default'
pipeline
=
@project
.
pipeline_for
(
ref
,
commit
.
sha
)
unless
pipeline
pipeline
=
@project
.
pipelines
.
create!
(
source: :external
,
...
...
@@ -90,7 +91,14 @@ module API
optional_attributes
=
attributes_for_keys
(
%w[target_url description coverage]
)
status
.
update
(
optional_attributes
)
if
optional_attributes
.
any?
status
.
assign_attributes
(
optional_attributes
)
if
optional_attributes
.
any?
if
status
.
new_record?
Ci
::
CreateJobService
.
new
(
@project
,
current_user
).
execute
(
status
)
else
status
.
save!
end
render_validation_error!
(
status
)
if
status
.
invalid?
begin
...
...
spec/services/ci/create_job_service_spec.rb
0 → 100644
View file @
aa290573
require
'spec_helper'
describe
Ci
::
CreateJobService
,
'#execute'
do
set
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:user
)
{
create
(
:admin
)
}
let
(
:status
)
{
build
(
:ci_build
)
}
let
(
:service
)
{
described_class
.
new
(
project
,
user
)
}
it
'persists job object instantiated in the block'
do
expect
(
service
.
execute
{
status
}).
to
be_persisted
end
it
'persists a job instance passed as an argument'
do
expect
(
service
.
execute
(
status
)).
to
be_persisted
end
it
'ensures that a job has a stage assigned'
do
expect
(
service
.
execute
(
status
).
stage_id
).
to
be_present
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