Rename latest_successful to be more explicit
* Reword Project#latest_successful_build_for to Project#latest_successful_build_for_ref * Reword Ci::Pipeline#latest_successful_for to Ci::Pipeline#latest_successful_build_for_ref
This commit is contained in:
parent
1eab065714
commit
38ab1ae2f2
|
@ -51,6 +51,6 @@ class Projects::BuildArtifactsController < Projects::ApplicationController
|
||||||
def job_from_ref
|
def job_from_ref
|
||||||
return unless @ref_name
|
return unless @ref_name
|
||||||
|
|
||||||
project.latest_successful_build_for(params[:job], @ref_name)
|
project.latest_successful_build_for_ref(params[:job], @ref_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -229,6 +229,7 @@ module Ci
|
||||||
#
|
#
|
||||||
# ref - The name (or names) of the branch(es)/tag(s) to limit the list of
|
# ref - The name (or names) of the branch(es)/tag(s) to limit the list of
|
||||||
# pipelines to.
|
# pipelines to.
|
||||||
|
# sha - The commit SHA (or mutliple SHAs) to limit the list of pipelines to.
|
||||||
# limit - This limits a backlog search, default to 100.
|
# limit - This limits a backlog search, default to 100.
|
||||||
def self.newest_first(ref: nil, sha: nil, limit: 100)
|
def self.newest_first(ref: nil, sha: nil, limit: 100)
|
||||||
relation = order(id: :desc)
|
relation = order(id: :desc)
|
||||||
|
@ -249,7 +250,7 @@ module Ci
|
||||||
newest_first(ref: ref).pluck(:status).first
|
newest_first(ref: ref).pluck(:status).first
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.latest_successful_for(ref)
|
def self.latest_successful_for_ref(ref)
|
||||||
newest_first(ref: ref).success.take
|
newest_first(ref: ref).success.take
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -720,16 +720,16 @@ class Project < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
# ref can't be HEAD, can only be branch/tag name
|
# ref can't be HEAD, can only be branch/tag name
|
||||||
def latest_successful_build_for(job_name, ref = default_branch)
|
def latest_successful_build_for_ref(job_name, ref = default_branch)
|
||||||
return unless ref
|
return unless ref
|
||||||
|
|
||||||
latest_pipeline = ci_pipelines.latest_successful_for(ref)
|
latest_pipeline = ci_pipelines.latest_successful_for_ref(ref)
|
||||||
return unless latest_pipeline
|
return unless latest_pipeline
|
||||||
|
|
||||||
latest_pipeline.builds.latest.with_artifacts_archive.find_by(name: job_name)
|
latest_pipeline.builds.latest.with_artifacts_archive.find_by(name: job_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def latest_successful_build_for_sha(job_name, sha = commit(default_branch).id)
|
def latest_successful_build_for_sha(job_name, sha)
|
||||||
return unless sha
|
return unless sha
|
||||||
|
|
||||||
latest_pipeline = ci_pipelines.latest_successful_for_sha(sha)
|
latest_pipeline = ci_pipelines.latest_successful_for_sha(sha)
|
||||||
|
@ -738,8 +738,8 @@ class Project < ApplicationRecord
|
||||||
latest_pipeline.builds.latest.with_artifacts_archive.find_by(name: job_name)
|
latest_pipeline.builds.latest.with_artifacts_archive.find_by(name: job_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def latest_successful_build_for!(job_name, ref = default_branch)
|
def latest_successful_build_for_ref!(job_name, ref = default_branch)
|
||||||
latest_successful_build_for(job_name, ref) || raise(ActiveRecord::RecordNotFound.new("Couldn't find job #{job_name}"))
|
latest_successful_build_for_ref(job_name, ref) || raise(ActiveRecord::RecordNotFound.new("Couldn't find job #{job_name}"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def merge_base_commit(first_commit_id, second_commit_id)
|
def merge_base_commit(first_commit_id, second_commit_id)
|
||||||
|
@ -1514,12 +1514,12 @@ class Project < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
@latest_successful_pipeline_for_default_branch =
|
@latest_successful_pipeline_for_default_branch =
|
||||||
ci_pipelines.latest_successful_for(default_branch)
|
ci_pipelines.latest_successful_for_ref(default_branch)
|
||||||
end
|
end
|
||||||
|
|
||||||
def latest_successful_pipeline_for(ref = nil)
|
def latest_successful_pipeline_for(ref = nil)
|
||||||
if ref && ref != default_branch
|
if ref && ref != default_branch
|
||||||
ci_pipelines.latest_successful_for(ref)
|
ci_pipelines.latest_successful_for_ref(ref)
|
||||||
else
|
else
|
||||||
latest_successful_pipeline_for_default_branch
|
latest_successful_pipeline_for_default_branch
|
||||||
end
|
end
|
||||||
|
|
|
@ -27,7 +27,7 @@ module API
|
||||||
requirements: { ref_name: /.+/ } do
|
requirements: { ref_name: /.+/ } do
|
||||||
authorize_download_artifacts!
|
authorize_download_artifacts!
|
||||||
|
|
||||||
latest_build = user_project.latest_successful_build_for!(params[:job], params[:ref_name])
|
latest_build = user_project.latest_successful_build_for_ref!(params[:job], params[:ref_name])
|
||||||
|
|
||||||
present_carrierwave_file!(latest_build.artifacts_file)
|
present_carrierwave_file!(latest_build.artifacts_file)
|
||||||
end
|
end
|
||||||
|
@ -45,7 +45,7 @@ module API
|
||||||
requirements: { ref_name: /.+/ } do
|
requirements: { ref_name: /.+/ } do
|
||||||
authorize_download_artifacts!
|
authorize_download_artifacts!
|
||||||
|
|
||||||
build = user_project.latest_successful_build_for!(params[:job], params[:ref_name])
|
build = user_project.latest_successful_build_for_ref!(params[:job], params[:ref_name])
|
||||||
|
|
||||||
path = Gitlab::Ci::Build::Artifacts::Path
|
path = Gitlab::Ci::Build::Artifacts::Path
|
||||||
.new(params[:artifact_path])
|
.new(params[:artifact_path])
|
||||||
|
|
|
@ -14,7 +14,7 @@ module Gitlab
|
||||||
@ref = ref
|
@ref = ref
|
||||||
@job = job
|
@job = job
|
||||||
|
|
||||||
@pipeline = @project.ci_pipelines.latest_successful_for(@ref)
|
@pipeline = @project.ci_pipelines.latest_successful_for_ref(@ref)
|
||||||
end
|
end
|
||||||
|
|
||||||
def entity
|
def entity
|
||||||
|
|
|
@ -1799,7 +1799,7 @@ describe Ci::Pipeline, :mailer do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '.latest_successful_for' do
|
describe '.latest_successful_for_ref' do
|
||||||
include_context 'with some outdated pipelines'
|
include_context 'with some outdated pipelines'
|
||||||
|
|
||||||
let!(:latest_successful_pipeline) do
|
let!(:latest_successful_pipeline) do
|
||||||
|
@ -1807,7 +1807,7 @@ describe Ci::Pipeline, :mailer do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the latest successful pipeline' do
|
it 'returns the latest successful pipeline' do
|
||||||
expect(described_class.latest_successful_for('ref'))
|
expect(described_class.latest_successful_for_ref('ref'))
|
||||||
.to eq(latest_successful_pipeline)
|
.to eq(latest_successful_pipeline)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2019,7 +2019,7 @@ describe Project do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#latest_successful_build_for' do
|
describe '#latest_successful_build_for_ref' do
|
||||||
let(:project) { create(:project, :repository) }
|
let(:project) { create(:project, :repository) }
|
||||||
let(:pipeline) { create_pipeline(project) }
|
let(:pipeline) { create_pipeline(project) }
|
||||||
|
|
||||||
|
@ -2032,7 +2032,7 @@ describe Project do
|
||||||
build1_p2 = create_build(pipeline2, 'test')
|
build1_p2 = create_build(pipeline2, 'test')
|
||||||
create_build(pipeline2, 'test2')
|
create_build(pipeline2, 'test2')
|
||||||
|
|
||||||
expect(project.latest_successful_build_for(build1_p2.name))
|
expect(project.latest_successful_build_for_ref(build1_p2.name))
|
||||||
.to eq(build1_p2)
|
.to eq(build1_p2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2042,12 +2042,12 @@ describe Project do
|
||||||
|
|
||||||
context 'standalone pipeline' do
|
context 'standalone pipeline' do
|
||||||
it 'returns builds for ref for default_branch' do
|
it 'returns builds for ref for default_branch' do
|
||||||
expect(project.latest_successful_build_for(build.name))
|
expect(project.latest_successful_build_for_ref(build.name))
|
||||||
.to eq(build)
|
.to eq(build)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns empty relation if the build cannot be found' do
|
it 'returns empty relation if the build cannot be found' do
|
||||||
expect(project.latest_successful_build_for('TAIL'))
|
expect(project.latest_successful_build_for_ref('TAIL'))
|
||||||
.to be_nil
|
.to be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2058,7 +2058,7 @@ describe Project do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'gives the latest build from latest pipeline' do
|
it 'gives the latest build from latest pipeline' do
|
||||||
expect(project.latest_successful_build_for(build.name))
|
expect(project.latest_successful_build_for_ref(build.name))
|
||||||
.to eq(build)
|
.to eq(build)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2069,7 +2069,7 @@ describe Project do
|
||||||
pipeline.update(status: 'pending')
|
pipeline.update(status: 'pending')
|
||||||
pending_build = create_build(pipeline)
|
pending_build = create_build(pipeline)
|
||||||
|
|
||||||
expect(project.latest_successful_build_for(pending_build.name)).to be_nil
|
expect(project.latest_successful_build_for_ref(pending_build.name)).to be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2129,7 +2129,7 @@ describe Project do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#latest_successful_build_for!' do
|
describe '#latest_successful_build_for_ref!' do
|
||||||
let(:project) { create(:project, :repository) }
|
let(:project) { create(:project, :repository) }
|
||||||
let(:pipeline) { create_pipeline(project) }
|
let(:pipeline) { create_pipeline(project) }
|
||||||
|
|
||||||
|
@ -2142,7 +2142,7 @@ describe Project do
|
||||||
build1_p2 = create_build(pipeline2, 'test')
|
build1_p2 = create_build(pipeline2, 'test')
|
||||||
create_build(pipeline2, 'test2')
|
create_build(pipeline2, 'test2')
|
||||||
|
|
||||||
expect(project.latest_successful_build_for(build1_p2.name))
|
expect(project.latest_successful_build_for_ref!(build1_p2.name))
|
||||||
.to eq(build1_p2)
|
.to eq(build1_p2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2152,12 +2152,12 @@ describe Project do
|
||||||
|
|
||||||
context 'standalone pipeline' do
|
context 'standalone pipeline' do
|
||||||
it 'returns builds for ref for default_branch' do
|
it 'returns builds for ref for default_branch' do
|
||||||
expect(project.latest_successful_build_for!(build.name))
|
expect(project.latest_successful_build_for_ref!(build.name))
|
||||||
.to eq(build)
|
.to eq(build)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns exception if the build cannot be found' do
|
it 'returns exception if the build cannot be found' do
|
||||||
expect { project.latest_successful_build_for!(build.name, 'TAIL') }
|
expect { project.latest_successful_build_for_ref!(build.name, 'TAIL') }
|
||||||
.to raise_error(ActiveRecord::RecordNotFound)
|
.to raise_error(ActiveRecord::RecordNotFound)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2168,7 +2168,7 @@ describe Project do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'gives the latest build from latest pipeline' do
|
it 'gives the latest build from latest pipeline' do
|
||||||
expect(project.latest_successful_build_for!(build.name))
|
expect(project.latest_successful_build_for_ref!(build.name))
|
||||||
.to eq(build)
|
.to eq(build)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2179,7 +2179,7 @@ describe Project do
|
||||||
pipeline.update(status: 'pending')
|
pipeline.update(status: 'pending')
|
||||||
pending_build = create_build(pipeline)
|
pending_build = create_build(pipeline)
|
||||||
|
|
||||||
expect { project.latest_successful_build_for!(pending_build.name) }
|
expect { project.latest_successful_build_for_ref!(pending_build.name) }
|
||||||
.to raise_error(ActiveRecord::RecordNotFound)
|
.to raise_error(ActiveRecord::RecordNotFound)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -4091,7 +4091,7 @@ describe Project do
|
||||||
|
|
||||||
context 'with a ref that is not the default branch' do
|
context 'with a ref that is not the default branch' do
|
||||||
it 'returns the latest successful pipeline for the given ref' do
|
it 'returns the latest successful pipeline for the given ref' do
|
||||||
expect(project.ci_pipelines).to receive(:latest_successful_for).with('foo')
|
expect(project.ci_pipelines).to receive(:latest_successful_for_ref).with('foo')
|
||||||
|
|
||||||
project.latest_successful_pipeline_for('foo')
|
project.latest_successful_pipeline_for('foo')
|
||||||
end
|
end
|
||||||
|
@ -4119,7 +4119,7 @@ describe Project do
|
||||||
it 'memoizes and returns the latest successful pipeline for the default branch' do
|
it 'memoizes and returns the latest successful pipeline for the default branch' do
|
||||||
pipeline = double(:pipeline)
|
pipeline = double(:pipeline)
|
||||||
|
|
||||||
expect(project.ci_pipelines).to receive(:latest_successful_for)
|
expect(project.ci_pipelines).to receive(:latest_successful_for_ref)
|
||||||
.with(project.default_branch)
|
.with(project.default_branch)
|
||||||
.and_return(pipeline)
|
.and_return(pipeline)
|
||||||
.once
|
.once
|
||||||
|
|
Loading…
Reference in New Issue