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
af70ab20
Commit
af70ab20
authored
Jun 29, 2021
by
Furkan Ayhan
Committed by
Fabio Pitino
Jul 08, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove the save flag
parent
43bbf2a0
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
89 additions
and
58 deletions
+89
-58
app/services/ci/pipelines/add_job_service.rb
app/services/ci/pipelines/add_job_service.rb
+5
-5
app/services/ci/retry_build_service.rb
app/services/ci/retry_build_service.rb
+5
-1
app/services/projects/update_pages_service.rb
app/services/projects/update_pages_service.rb
+4
-4
lib/api/commit_statuses.rb
lib/api/commit_statuses.rb
+32
-28
spec/services/ci/pipelines/add_job_service_spec.rb
spec/services/ci/pipelines/add_job_service_spec.rb
+43
-20
No files found.
app/services/ci/pipelines/add_job_service.rb
View file @
af70ab20
...
@@ -11,23 +11,23 @@ module Ci
...
@@ -11,23 +11,23 @@ module Ci
raise
ArgumentError
,
"Pipeline must be persisted for this service to be used"
unless
@pipeline
.
persisted?
raise
ArgumentError
,
"Pipeline must be persisted for this service to be used"
unless
@pipeline
.
persisted?
end
end
def
execute!
(
job
,
save:
true
)
def
execute!
(
job
,
&
block
)
assign_pipeline_attributes
(
job
)
assign_pipeline_attributes
(
job
)
Ci
::
Pipeline
.
transaction
do
Ci
::
Pipeline
.
transaction
do
BulkInsertableAssociations
.
with_bulk_insert
{
job
.
save!
}
if
save
yield
(
job
)
job
.
update_older_statuses_retried!
if
Feature
.
enabled?
(
:ci_fix_commit_status_retried
,
@pipeline
.
project
,
default_enabled: :yaml
)
job
.
update_older_statuses_retried!
if
Feature
.
enabled?
(
:ci_fix_commit_status_retried
,
@pipeline
.
project
,
default_enabled: :yaml
)
end
end
job
ServiceResponse
.
success
(
payload:
{
job:
job
})
rescue
StandardError
=>
e
ServiceResponse
.
error
(
message:
e
.
message
,
payload:
{
job:
job
})
end
end
private
private
def
assign_pipeline_attributes
(
job
)
def
assign_pipeline_attributes
(
job
)
# these also ensures other invariants such as
# a job takes project and ref from the pipeline it belongs to
job
.
pipeline
=
@pipeline
job
.
pipeline
=
@pipeline
job
.
project
=
@pipeline
.
project
job
.
project
=
@pipeline
.
project
job
.
ref
=
@pipeline
.
ref
job
.
ref
=
@pipeline
.
ref
...
...
app/services/ci/retry_build_service.rb
View file @
af70ab20
...
@@ -35,7 +35,11 @@ module Ci
...
@@ -35,7 +35,11 @@ module Ci
check_access!
(
build
)
check_access!
(
build
)
new_build
=
clone_build
(
build
)
new_build
=
clone_build
(
build
)
::
Ci
::
Pipelines
::
AddJobService
.
new
(
build
.
pipeline
).
execute!
(
new_build
)
::
Ci
::
Pipelines
::
AddJobService
.
new
(
build
.
pipeline
).
execute!
(
new_build
)
do
|
job
|
BulkInsertableAssociations
.
with_bulk_insert
do
job
.
save!
end
end
build
.
reset
# refresh the data to get new values of `retried` and `processed`.
build
.
reset
# refresh the data to get new values of `retried` and `processed`.
new_build
new_build
...
...
app/services/projects/update_pages_service.rb
View file @
af70ab20
...
@@ -32,10 +32,10 @@ module Projects
...
@@ -32,10 +32,10 @@ module Projects
# Create status notifying the deployment of pages
# Create status notifying the deployment of pages
@status
=
build_commit_status
@status
=
build_commit_status
::
Ci
::
Pipelines
::
AddJobService
.
new
(
@build
.
pipeline
).
execute!
(
@status
)
::
Ci
::
Pipelines
::
AddJobService
.
new
(
@build
.
pipeline
).
execute!
(
@status
)
do
|
job
|
job
.
enqueue!
@status
.
enqueue
!
job
.
run
!
@status
.
run!
end
raise
InvalidStateError
,
'missing pages artifacts'
unless
build
.
artifacts?
raise
InvalidStateError
,
'missing pages artifacts'
unless
build
.
artifacts?
raise
InvalidStateError
,
'build SHA is outdated for this ref'
unless
latest?
raise
InvalidStateError
,
'build SHA is outdated for this ref'
unless
latest?
...
...
lib/api/commit_statuses.rb
View file @
af70ab20
...
@@ -99,40 +99,26 @@ module API
...
@@ -99,40 +99,26 @@ module API
updatable_optional_attributes
=
%w[target_url description coverage]
updatable_optional_attributes
=
%w[target_url description coverage]
status
.
assign_attributes
(
attributes_for_keys
(
updatable_optional_attributes
))
status
.
assign_attributes
(
attributes_for_keys
(
updatable_optional_attributes
))
if
status
.
valid?
render_validation_error!
(
status
)
unless
status
.
valid?
::
Ci
::
Pipelines
::
AddJobService
.
new
(
pipeline
).
execute!
(
status
,
save:
false
)
else
render_validation_error!
(
status
)
end
begin
response
=
::
Ci
::
Pipelines
::
AddJobService
.
new
(
pipeline
).
execute!
(
status
)
do
|
job
|
case
params
[
:state
]
apply_job_state!
(
job
)
when
'pending'
rescue
::
StateMachines
::
InvalidTransition
=>
e
status
.
enqueue!
render_api_error!
(
e
.
message
,
400
)
when
'running'
end
status
.
enqueue
status
.
run!
when
'success'
status
.
success!
when
'failed'
status
.
drop!
(
:api_failure
)
when
'canceled'
status
.
cancel!
else
render_api_error!
(
'invalid state'
,
400
)
end
if
pipeline
.
latest?
render_validation_error!
(
response
.
payload
[
:job
])
unless
response
.
success?
MergeRequest
.
where
(
source_project:
user_project
,
source_branch:
ref
)
.
update_all
(
head_pipeline_id:
pipeline
.
id
)
end
present
status
,
with:
Entities
::
CommitStatus
if
pipeline
.
latest?
rescue
StateMachines
::
InvalidTransition
=>
e
MergeRequest
render_api_error!
(
e
.
message
,
400
)
.
where
(
source_project:
user_project
,
source_branch:
ref
)
.
update_all
(
head_pipeline_id:
pipeline
.
id
)
end
end
present
response
.
payload
[
:job
],
with:
Entities
::
CommitStatus
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable CodeReuse/ActiveRecord
helpers
do
helpers
do
def
commit
def
commit
strong_memoize
(
:commit
)
do
strong_memoize
(
:commit
)
do
...
@@ -146,6 +132,24 @@ module API
...
@@ -146,6 +132,24 @@ module API
pipelines
=
pipelines
.
for_id
(
params
[
:pipeline_id
])
if
params
[
:pipeline_id
]
pipelines
=
pipelines
.
for_id
(
params
[
:pipeline_id
])
if
params
[
:pipeline_id
]
pipelines
pipelines
end
end
def
apply_job_state!
(
job
)
case
params
[
:state
]
when
'pending'
job
.
enqueue!
when
'running'
job
.
enqueue
job
.
run!
when
'success'
job
.
success!
when
'failed'
job
.
drop!
(
:api_failure
)
when
'canceled'
job
.
cancel!
else
render_api_error!
(
'invalid state'
,
400
)
end
end
end
end
end
end
end
end
...
...
spec/services/ci/pipelines/add_job_service_spec.rb
View file @
af70ab20
...
@@ -17,33 +17,56 @@ RSpec.describe Ci::Pipelines::AddJobService do
...
@@ -17,33 +17,56 @@ RSpec.describe Ci::Pipelines::AddJobService do
end
end
end
end
it
'assigns pipeline attributes to the job'
do
describe
'#execute!'
do
expect
do
subject
(
:execute
)
do
service
.
execute!
(
job
)
service
.
execute!
(
job
)
do
|
job
|
end
.
to
change
{
job
.
slice
(
:pipeline
,
:project
,
:ref
)
}.
to
(
job
.
save!
pipeline:
pipeline
,
project:
pipeline
.
project
,
ref:
pipeline
.
ref
end
)
end
end
it
'returns the job itself'
do
it
'assigns pipeline attributes to the job'
do
expect
(
service
.
execute!
(
job
)).
to
eq
(
job
)
expect
do
end
execute
end
.
to
change
{
job
.
slice
(
:pipeline
,
:project
,
:ref
)
}.
to
(
pipeline:
pipeline
,
project:
pipeline
.
project
,
ref:
pipeline
.
ref
)
end
it
'returns a service response with the job as payload'
do
expect
(
execute
).
to
be_success
expect
(
execute
.
payload
[
:job
]).
to
eq
(
job
)
end
it
'calls update_older_statuses_retried!'
do
it
'calls update_older_statuses_retried!'
do
expect
(
job
).
to
receive
(
:update_older_statuses_retried!
)
expect
(
job
).
to
receive
(
:update_older_statuses_retried!
)
service
.
execute!
(
job
)
execute
end
end
context
'when the FF ci_fix_commit_status_retried is disabled'
do
context
'when the block raises an error'
do
before
do
subject
(
:execute
)
do
stub_feature_flags
(
ci_fix_commit_status_retried:
false
)
service
.
execute!
(
job
)
do
|
job
|
raise
"this is an error"
end
end
it
'returns a service response with the error and the job as payload'
do
expect
(
execute
).
to
be_error
expect
(
execute
.
payload
[
:job
]).
to
eq
(
job
)
expect
(
execute
.
message
).
to
eq
(
'this is an error'
)
end
end
end
it
'does not call update_older_statuses_retried!'
do
context
'when the FF ci_fix_commit_status_retried is disabled'
do
expect
(
job
).
not_to
receive
(
:update_older_statuses_retried!
)
before
do
stub_feature_flags
(
ci_fix_commit_status_retried:
false
)
end
it
'does not call update_older_statuses_retried!'
do
expect
(
job
).
not_to
receive
(
:update_older_statuses_retried!
)
service
.
execute!
(
job
)
execute
end
end
end
end
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