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
45e4a2a5
Commit
45e4a2a5
authored
Mar 03, 2021
by
gentcys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix commit latest pipeline status with child pipeline
parent
c4b8fe7e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
18 deletions
+39
-18
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+5
-18
changelogs/unreleased/fix-commit-status-with-child-pipeline.yml
...logs/unreleased/fix-commit-status-with-child-pipeline.yml
+5
-0
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+29
-0
No files found.
app/models/ci/pipeline.rb
View file @
45e4a2a5
...
...
@@ -394,26 +394,13 @@ module Ci
# given we simply get the latest pipelines for the commits, regardless
# of what refs the pipelines belong to.
def
self
.
latest_pipeline_per_commit
(
commits
,
ref
=
nil
)
p1
=
arel_table
p2
=
arel_table
.
alias
sql
=
select
(
'DISTINCT ON (sha) *'
)
.
where
(
sha:
commits
)
.
order
(
:sha
,
id: :desc
)
# This LEFT JOIN will filter out all but the newest row for every
# combination of (project_id, sha) or (project_id, sha, ref) if a ref is
# given.
cond
=
p1
[
:sha
].
eq
(
p2
[
:sha
])
.
and
(
p1
[
:project_id
].
eq
(
p2
[
:project_id
]))
.
and
(
p1
[
:id
].
lt
(
p2
[
:id
]))
sql
=
sql
.
where
(
ref:
ref
)
if
ref
cond
=
cond
.
and
(
p1
[
:ref
].
eq
(
p2
[
:ref
]))
if
ref
join
=
p1
.
join
(
p2
,
Arel
::
Nodes
::
OuterJoin
).
on
(
cond
)
relation
=
where
(
sha:
commits
)
.
where
(
p2
[
:id
].
eq
(
nil
))
.
joins
(
join
.
join_sources
)
relation
=
relation
.
where
(
ref:
ref
)
if
ref
relation
.
each_with_object
({})
do
|
pipeline
,
hash
|
sql
.
each_with_object
({})
do
|
pipeline
,
hash
|
hash
[
pipeline
.
sha
]
=
pipeline
end
end
...
...
changelogs/unreleased/fix-commit-status-with-child-pipeline.yml
0 → 100644
View file @
45e4a2a5
---
title
:
Filter out pipelines that were excluded in the relation scope in Ci::Pipeline#latest_pipeline_per_commit
merge_request
:
55657
author
:
Cong Chen @gentcys
type
:
fixed
spec/models/ci/pipeline_spec.rb
View file @
45e4a2a5
...
...
@@ -2282,6 +2282,35 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
)
end
end
context
'when method is scoped'
do
let!
(
:commit_123_ref_master_parent_pipeline
)
do
create
(
:ci_pipeline
,
sha:
'123'
,
ref:
'master'
,
project:
project
)
end
let!
(
:commit_123_ref_master_child_pipeline
)
do
create
(
:ci_pipeline
,
sha:
'123'
,
ref:
'master'
,
project:
project
,
child_of:
commit_123_ref_master_parent_pipeline
)
end
it
'returns the latest pipeline after applying the scope'
do
result
=
described_class
.
ci_sources
.
latest_pipeline_per_commit
(
%w[123]
,
'master'
)
expect
(
result
).
to
match
(
'123'
=>
commit_123_ref_master_parent_pipeline
)
end
end
end
describe
'.latest_successful_ids_per_project'
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