Skip to content
代码片段 群组 项目
提交 4bb2a48e 编辑于 作者: guillaume.micouin-jorda's avatar guillaume.micouin-jorda
浏览文件

Create commit status on commit with a lot of pipelines


if pipeline_id is used, check on all commit pipelines that the pipeline exists

Signed-off-by: default avatarguillaume.micouin-jorda <gmicouin@netcourrier.com>
上级 3b838abf
No related branches found
No related tags found
无相关合并请求
...@@ -8,6 +8,9 @@ class CreateCommitStatusService < BaseService ...@@ -8,6 +8,9 @@ class CreateCommitStatusService < BaseService
delegate :sha, to: :commit delegate :sha, to: :commit
# Default number of pipelines to return
DEFAULT_LIMIT_PIPELINES = 100
def execute(optional_commit_status_params:) def execute(optional_commit_status_params:)
in_lock(pipeline_lock_key, **pipeline_lock_params) do in_lock(pipeline_lock_key, **pipeline_lock_params) do
@optional_commit_status_params = optional_commit_status_params @optional_commit_status_params = optional_commit_status_params
...@@ -60,7 +63,8 @@ def commit ...@@ -60,7 +63,8 @@ def commit
strong_memoize_attr :commit strong_memoize_attr :commit
def first_matching_pipeline def first_matching_pipeline
pipelines = project.ci_pipelines.newest_first(sha: sha, limit: 100) limit = params[:pipeline_id] ? nil : DEFAULT_LIMIT_PIPELINES
pipelines = project.ci_pipelines.newest_first(sha: sha, limit: limit)
pipelines = pipelines.for_ref(params[:ref]) if params[:ref] pipelines = pipelines.for_ref(params[:ref]) if params[:ref]
pipelines = pipelines.id_in(params[:pipeline_id]) if params[:pipeline_id] pipelines = pipelines.id_in(params[:pipeline_id]) if params[:pipeline_id]
pipelines.first pipelines.first
......
...@@ -257,6 +257,10 @@ ...@@ -257,6 +257,10 @@
} }
end end
before do
stub_const("#{described_class}::DEFAULT_LIMIT_PIPELINES", 3)
end
it 'update the correct pipeline', :sidekiq_might_not_need_inline do it 'update the correct pipeline', :sidekiq_might_not_need_inline do
expect { response } expect { response }
.to not_change { ::Ci::Pipeline.count }.from(2) .to not_change { ::Ci::Pipeline.count }.from(2)
...@@ -267,6 +271,24 @@ ...@@ -267,6 +271,24 @@
expect(other_pipeline.reload.status).to eq('success') expect(other_pipeline.reload.status).to eq('success')
end end
it 'create a status on an old pipeline', :sidekiq_might_not_need_inline do
# 3 pipelines more are created to validate that it is possible to set a status on the 4th.
(0..2).each do |_|
project.ci_pipelines.build(source: :push, sha: commit.id, ref: 'master', status: 'created').tap do |p|
p.ensure_project_iid!
p.save!
end
end
expect { response }
.to not_change { ::Ci::Pipeline.count }.from(5)
.and change { ::Ci::Stage.count }.by(1)
.and change { ::CommitStatus.count }.by(1)
expect(first_pipeline.reload.status).to eq('created')
expect(other_pipeline.reload.status).to eq('success')
end
context 'when pipeline_id and sha do not match' do context 'when pipeline_id and sha do not match' do
let(:other_commit) { create(:commit) } let(:other_commit) { create(:commit) }
let(:sha) { other_commit.id } let(:sha) { other_commit.id }
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册