Commit f61f34fe authored by Matija Čupić's avatar Matija Čupić
Browse files

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
parent 5479009d6de4
......@@ -51,6 +51,6 @@ def job_from_id
def job_from_ref
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
......@@ -229,6 +229,7 @@ class Pipeline < ApplicationRecord
#
# ref - The name (or names) of the branch(es)/tag(s) to limit the list of
# 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.
def self.newest_first(ref: nil, sha: nil, limit: 100)
relation = order(id: :desc)
......@@ -249,7 +250,7 @@ def self.latest_status(ref = nil)
newest_first(ref: ref).pluck(:status).first
end
def self.latest_successful_for(ref)
def self.latest_successful_for_ref(ref)
newest_first(ref: ref).success.take
end
......
......@@ -720,16 +720,16 @@ def commits_by(oids:)
end
# 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
latest_pipeline = ci_pipelines.latest_successful_for(ref)
latest_pipeline = ci_pipelines.latest_successful_for_ref(ref)
return unless latest_pipeline
latest_pipeline.builds.latest.with_artifacts_archive.find_by(name: job_name)
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
latest_pipeline = ci_pipelines.latest_successful_for_sha(sha)
......@@ -738,8 +738,8 @@ def latest_successful_build_for_sha(job_name, sha = commit(default_branch).id)
latest_pipeline.builds.latest.with_artifacts_archive.find_by(name: job_name)
end
def latest_successful_build_for!(job_name, ref = default_branch)
latest_successful_build_for(job_name, ref) || raise(ActiveRecord::RecordNotFound.new("Couldn't find job #{job_name}"))
def latest_successful_build_for_ref!(job_name, ref = default_branch)
latest_successful_build_for_ref(job_name, ref) || raise(ActiveRecord::RecordNotFound.new("Couldn't find job #{job_name}"))
end
def merge_base_commit(first_commit_id, second_commit_id)
......@@ -1514,12 +1514,12 @@ def latest_successful_pipeline_for_default_branch
end
@latest_successful_pipeline_for_default_branch =
ci_pipelines.latest_successful_for(default_branch)
ci_pipelines.latest_successful_for_ref(default_branch)
end
def latest_successful_pipeline_for(ref = nil)
if ref && ref != default_branch
ci_pipelines.latest_successful_for(ref)
ci_pipelines.latest_successful_for_ref(ref)
else
latest_successful_pipeline_for_default_branch
end
......
......@@ -27,7 +27,7 @@ def authorize_download_artifacts!
requirements: { ref_name: /.+/ } do
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)
end
......@@ -45,7 +45,7 @@ def authorize_download_artifacts!
requirements: { ref_name: /.+/ } do
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
.new(params[:artifact_path])
......
......@@ -14,7 +14,7 @@ def initialize(project, ref, job = nil)
@ref = ref
@job = job
@pipeline = @project.ci_pipelines.latest_successful_for(@ref)
@pipeline = @project.ci_pipelines.latest_successful_for_ref(@ref)
end
def entity
......
......@@ -1799,7 +1799,7 @@ def create_pipeline(status, ref, sha, project)
end
end
describe '.latest_successful_for' do
describe '.latest_successful_for_ref' do
include_context 'with some outdated pipelines'
let!(:latest_successful_pipeline) do
......@@ -1807,7 +1807,7 @@ def create_pipeline(status, ref, sha, project)
end
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)
end
end
......
......@@ -2019,7 +2019,7 @@
end
end
describe '#latest_successful_build_for' do
describe '#latest_successful_build_for_ref' do
let(:project) { create(:project, :repository) }
let(:pipeline) { create_pipeline(project) }
......@@ -2032,7 +2032,7 @@
build1_p2 = create_build(pipeline2, 'test')
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)
end
end
......@@ -2042,12 +2042,12 @@
context 'standalone pipeline' 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)
end
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
end
end
......@@ -2058,7 +2058,7 @@
end
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)
end
end
......@@ -2069,7 +2069,7 @@
pipeline.update(status: 'pending')
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
......@@ -2129,7 +2129,7 @@
end
end
describe '#latest_successful_build_for!' do
describe '#latest_successful_build_for_ref!' do
let(:project) { create(:project, :repository) }
let(:pipeline) { create_pipeline(project) }
......@@ -2142,7 +2142,7 @@
build1_p2 = create_build(pipeline2, 'test')
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)
end
end
......@@ -2152,12 +2152,12 @@
context 'standalone pipeline' 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)
end
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)
end
end
......@@ -2168,7 +2168,7 @@
end
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)
end
end
......@@ -2179,7 +2179,7 @@
pipeline.update(status: 'pending')
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)
end
end
......@@ -4091,7 +4091,7 @@ def enable_lfs
context 'with a ref that is not the default branch' 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')
end
......@@ -4119,7 +4119,7 @@ def enable_lfs
it 'memoizes and returns the latest successful pipeline for the default branch' do
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)
.and_return(pipeline)
.once
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment