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
Jérome Perrin
gitlab-ce
Commits
3eae0641
Commit
3eae0641
authored
Aug 10, 2016
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce Pipeline#latest and Pipeline.latest_for:
So that we could easily access it for the view
parent
6234b327
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
4 deletions
+56
-4
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+10
-2
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+46
-2
No files found.
app/models/ci/pipeline.rb
View file @
3eae0641
...
@@ -21,8 +21,12 @@ module Ci
...
@@ -21,8 +21,12 @@ module Ci
after_save
:keep_around_commits
after_save
:keep_around_commits
# ref can't be HEAD or SHA, can only be branch/tag name
# ref can't be HEAD or SHA, can only be branch/tag name
scope
:latest_successful_for
,
->
(
ref
=
default_branch
)
do
scope
:latest_successful_for
,
->
(
ref
)
do
where
(
ref:
ref
).
success
.
order
(
id: :desc
).
limit
(
1
)
latest
(
ref
).
success
end
scope
:latest_for
,
->
(
ref
)
do
where
(
ref:
ref
).
order
(
id: :desc
).
limit
(
1
)
end
end
def
self
.
truncate_sha
(
sha
)
def
self
.
truncate_sha
(
sha
)
...
@@ -98,6 +102,10 @@ module Ci
...
@@ -98,6 +102,10 @@ module Ci
end
end
end
end
def
latest
project
.
pipelines
.
latest_for
(
ref
).
first
end
def
latest?
def
latest?
return
false
unless
ref
return
false
unless
ref
commit
=
project
.
commit
(
ref
)
commit
=
project
.
commit
(
ref
)
...
...
spec/models/ci/pipeline_spec.rb
View file @
3eae0641
require
'spec_helper'
require
'spec_helper'
describe
Ci
::
Pipeline
,
models:
true
do
describe
Ci
::
Pipeline
,
models:
true
do
let
(
:project
)
{
FactoryGirl
.
create
:empty_project
}
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:pipeline
)
{
FactoryGirl
.
create
:ci_pipeline
,
project:
project
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
belong_to
(
:user
)
}
it
{
is_expected
.
to
belong_to
(
:user
)
}
...
@@ -481,6 +481,50 @@ describe Ci::Pipeline, models: true do
...
@@ -481,6 +481,50 @@ describe Ci::Pipeline, models: true do
end
end
end
end
context
'with non-empty project'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:pipeline
)
{
create_pipeline
}
describe
'#latest?'
do
context
'with latest sha'
do
it
'returns true'
do
expect
(
pipeline
).
to
be_latest
end
end
context
'with not latest sha'
do
before
do
pipeline
.
update
(
sha:
project
.
commit
(
"
#{
project
.
default_branch
}
~1"
).
sha
)
end
it
'returns false'
do
expect
(
pipeline
).
not_to
be_latest
end
end
end
describe
'#latest'
do
let
(
:previous_pipeline
)
{
create_pipeline
}
before
do
previous_pipeline
pipeline
end
it
'gives the latest pipeline'
do
expect
(
previous_pipeline
.
latest
).
to
eq
(
pipeline
)
end
end
def
create_pipeline
create
(
:ci_pipeline
,
project:
project
,
ref:
project
.
default_branch
,
sha:
project
.
commit
.
sha
)
end
end
describe
'#manual_actions'
do
describe
'#manual_actions'
do
subject
{
pipeline
.
manual_actions
}
subject
{
pipeline
.
manual_actions
}
...
...
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