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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
503f2136
Commit
503f2136
authored
Oct 06, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure that every job has a stage assigned
parent
823a9d35
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
3 deletions
+75
-3
app/models/commit_status.rb
app/models/commit_status.rb
+27
-1
spec/models/commit_status_spec.rb
spec/models/commit_status_spec.rb
+48
-2
No files found.
app/models/commit_status.rb
View file @
503f2136
...
@@ -14,7 +14,6 @@ class CommitStatus < ActiveRecord::Base
...
@@ -14,7 +14,6 @@ class CommitStatus < ActiveRecord::Base
delegate
:sha
,
:short_sha
,
to: :pipeline
delegate
:sha
,
:short_sha
,
to: :pipeline
validates
:pipeline
,
presence:
true
,
unless: :importing?
validates
:pipeline
,
presence:
true
,
unless: :importing?
validates
:name
,
presence:
true
,
unless: :importing?
validates
:name
,
presence:
true
,
unless: :importing?
alias_attribute
:author
,
:user
alias_attribute
:author
,
:user
...
@@ -46,6 +45,21 @@ class CommitStatus < ActiveRecord::Base
...
@@ -46,6 +45,21 @@ class CommitStatus < ActiveRecord::Base
runner_system_failure:
4
runner_system_failure:
4
}
}
##
# We still create some CommitStatuses outside of CreatePipelineService.
#
# These are pages deployments and external statuses.
#
before_create
do
|
status
|
next
if
status
.
stage_id
.
present?
||
importing?
ensure_pipeline_stage!
do
|
stage
|
status
.
run_after_commit
do
StageUpdateWorker
.
perform_async
(
stage
.
id
)
end
end
end
state_machine
:status
do
state_machine
:status
do
event
:process
do
event
:process
do
transition
[
:skipped
,
:manual
]
=>
:created
transition
[
:skipped
,
:manual
]
=>
:created
...
@@ -174,4 +188,16 @@ class CommitStatus < ActiveRecord::Base
...
@@ -174,4 +188,16 @@ class CommitStatus < ActiveRecord::Base
v
=~
/\d+/
?
v
.
to_i
:
v
v
=~
/\d+/
?
v
.
to_i
:
v
end
end
end
end
private
def
ensure_pipeline_stage!
attributes
=
{
name:
stage
,
pipeline:
pipeline
,
project:
project
}
Ci
::
Stage
.
create!
(
attributes
).
tap
do
|
stage
|
self
.
stage_id
=
stage
.
id
yield
stage
end
end
end
end
spec/models/commit_status_spec.rb
View file @
503f2136
require
'spec_helper'
require
'spec_helper'
describe
CommitStatus
do
describe
CommitStatus
do
l
et
(
:project
)
{
create
(
:project
,
:repository
)
}
s
et
(
:project
)
{
create
(
:project
,
:repository
)
}
l
et
(
:pipeline
)
do
s
et
(
:pipeline
)
do
create
(
:ci_pipeline
,
project:
project
,
sha:
project
.
commit
.
id
)
create
(
:ci_pipeline
,
project:
project
,
sha:
project
.
commit
.
id
)
end
end
...
@@ -464,4 +464,50 @@ describe CommitStatus do
...
@@ -464,4 +464,50 @@ describe CommitStatus do
it
{
is_expected
.
to
be_script_failure
}
it
{
is_expected
.
to
be_script_failure
}
end
end
end
end
describe
'ensure stage assignment'
do
context
'when commit status has a stage_id assigned'
do
let!
(
:stage
)
do
create
(
:ci_stage_entity
,
project:
project
,
pipeline:
pipeline
)
end
let
(
:commit_status
)
do
create
(
:commit_status
,
stage_id:
stage
.
id
,
name:
'rspec'
,
stage:
'test'
)
end
it
'does not create a new stage'
do
expect
{
commit_status
}.
not_to
change
{
Ci
::
Stage
.
count
}
expect
(
commit_status
.
stage_id
).
to
eq
stage
.
id
end
end
context
'when commit status does not have a stage_id assigned'
do
let
(
:commit_status
)
do
create
(
:commit_status
,
name:
'rspec'
,
stage:
'test'
,
status: :success
)
end
let
(
:stage
)
{
Ci
::
Stage
.
first
}
it
'creates a new stage'
do
expect
{
commit_status
}.
to
change
{
Ci
::
Stage
.
count
}.
by
(
1
)
expect
(
stage
.
name
).
to
eq
'test'
expect
(
stage
.
project
).
to
eq
commit_status
.
project
expect
(
stage
.
pipeline
).
to
eq
commit_status
.
pipeline
expect
(
stage
.
status
).
to
eq
commit_status
.
status
expect
(
commit_status
.
stage_id
).
to
eq
stage
.
id
end
end
context
'when commit status is being imported'
do
let
(
:commit_status
)
do
create
(
:commit_status
,
name:
'rspec'
,
stage:
'test'
,
importing:
true
)
end
it
'does not create a new stage'
do
expect
{
commit_status
}.
not_to
change
{
Ci
::
Stage
.
count
}
expect
(
commit_status
.
stage_id
).
not_to
be_present
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