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
af86b8c2
Commit
af86b8c2
authored
Jul 18, 2016
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Latest success pipelines (rather than builds)
parent
85409a5a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
22 deletions
+51
-22
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+8
-0
app/models/commit_status.rb
app/models/commit_status.rb
+2
-2
app/models/project.rb
app/models/project.rb
+2
-5
spec/models/build_spec.rb
spec/models/build_spec.rb
+27
-8
spec/requests/shared/artifacts_context.rb
spec/requests/shared/artifacts_context.rb
+12
-7
No files found.
app/models/ci/pipeline.rb
View file @
af86b8c2
...
...
@@ -18,6 +18,14 @@ module Ci
after_touch
:update_state
after_save
:keep_around_commits
scope
:latest
,
->
do
max_id
=
unscope
(
:select
).
select
(
"max(
#{
table_name
}
.id)"
).
group
(
:ref
)
where
(
id:
max_id
)
end
def
self
.
truncate_sha
(
sha
)
sha
[
0
...
8
]
end
...
...
app/models/commit_status.rb
View file @
af86b8c2
...
...
@@ -18,8 +18,8 @@ class CommitStatus < ActiveRecord::Base
scope
:latest
,
->
do
max_id
=
unscope
(
:select
).
select
(
"max(
#{
table_name
}
.id)"
).
group
(
:name
,
:commit_id
)
select
(
"max(
#{
table_name
}
.id)"
).
group
(
:name
,
:commit_id
)
where
(
id:
max_id
)
end
...
...
app/models/project.rb
View file @
af86b8c2
...
...
@@ -430,12 +430,9 @@ class Project < ActiveRecord::Base
end
def
latest_success_builds_for
(
ref
=
'HEAD'
)
builds_for
(
ref
).
success
.
latest
end
def
builds_for
(
ref
=
'HEAD'
)
Ci
::
Build
.
joins
(
:pipeline
).
merge
(
Ci
::
Pipeline
.
where
(
ref:
ref
,
project:
self
))
merge
(
pipelines
.
where
(
ref:
ref
).
success
.
latest
).
with_artifacts
end
def
merge_base_commit
(
first_commit_id
,
second_commit_id
)
...
...
spec/models/build_spec.rb
View file @
af86b8c2
...
...
@@ -6,7 +6,8 @@ describe Ci::Build, models: true do
let
(
:pipeline
)
do
create
(
:ci_pipeline
,
project:
project
,
sha:
project
.
commit
.
id
,
ref:
'fix'
)
ref:
'fix'
,
status:
'success'
)
end
let
(
:build
)
{
create
(
:ci_build
,
pipeline:
pipeline
)
}
...
...
@@ -694,20 +695,38 @@ describe Ci::Build, models: true do
end
describe
'Project#latest_success_builds_for'
do
let
(
:build
)
do
create
(
:ci_build
,
:artifacts
,
:success
,
pipeline:
pipeline
)
end
before
do
build
.
update
(
status:
'success'
)
build
end
it
'returns builds from ref'
do
builds
=
project
.
latest_success_builds_for
(
'fix'
)
context
'with succeed pipeline'
do
it
'returns builds from ref'
do
builds
=
project
.
latest_success_builds_for
(
'fix'
)
expect
(
builds
).
to
contain_exactly
(
build
)
end
it
'returns empty relation if the build cannot be found'
do
builds
=
project
.
latest_success_builds_for
(
'TAIL'
).
all
expect
(
builds
).
to
contain_exactly
(
build
)
expect
(
builds
).
to
be_empty
end
end
it
'returns empty relation if the build cannot be found'
do
builds
=
project
.
latest_success_builds_for
(
'TAIL'
).
all
context
'with pending pipeline'
do
before
do
pipeline
.
update
(
status:
'pending'
)
end
expect
(
builds
).
to
be_empty
it
'returns empty relation'
do
builds
=
project
.
latest_success_builds_for
(
'fix'
).
all
expect
(
builds
).
to
be_empty
end
end
end
end
spec/requests/shared/artifacts_context.rb
View file @
af86b8c2
...
...
@@ -25,7 +25,7 @@ shared_examples 'artifacts from ref with 404' do
context
'has no such build'
do
before
do
get
path_from_ref
(
pipeline
.
sha
,
'NOBUILD'
)
get
path_from_ref
(
pipeline
.
ref
,
'NOBUILD'
)
end
it
(
'gives 404'
)
{
verify
}
...
...
@@ -33,6 +33,11 @@ shared_examples 'artifacts from ref with 404' do
end
shared_examples
'artifacts from ref successfully'
do
def
create_new_pipeline
(
status
)
new_pipeline
=
create
(
:ci_pipeline
,
status:
'success'
)
create
(
:ci_build
,
status
,
:artifacts
,
pipeline:
new_pipeline
)
end
context
'with regular branch'
do
before
do
pipeline
.
update
(
ref:
'master'
,
...
...
@@ -59,10 +64,10 @@ shared_examples 'artifacts from ref successfully' do
it
(
'gives the file'
)
{
verify
}
end
context
'with latest
build
'
do
context
'with latest
pipeline
'
do
before
do
3
.
times
do
# creating some old
build
s
create
(
:ci_build
,
:success
,
:artifacts
,
pipeline:
pipeline
)
3
.
times
do
# creating some old
pipeline
s
create
_new_pipeline
(
:success
)
end
end
...
...
@@ -73,10 +78,10 @@ shared_examples 'artifacts from ref successfully' do
it
(
'gives the file'
)
{
verify
}
end
context
'with success
build
'
do
context
'with success
pipeline
'
do
before
do
build
# make sure
build
was old, but still the latest success one
create
(
:ci_build
,
:pending
,
:artifacts
,
pipeline:
pipeline
)
build
# make sure
pipeline
was old, but still the latest success one
create
_new_pipeline
(
:pending
)
end
before
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