diff --git a/app/models/project.rb b/app/models/project.rb index 30e8ade99ff3df0f0579b43404c8747284be7e44..c1cb1558132f9cbd1fe20eddb2e67bc07d9626ae 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -429,12 +429,15 @@ class Project < ActiveRecord::Base repository.commit(ref) end - # ref can't be HEAD or SHA, can only be branch/tag name + # ref can't be HEAD, can only be branch/tag name or SHA def latest_success_pipeline_for(ref = 'master') - pipelines.where(ref: ref).success.order(id: :desc) + table = Ci::Pipeline.quoted_table_name + # TODO: Use `where(ref: ref).or(sha: ref)` in Rails 5 + pipelines.where("#{table}.ref = ? OR #{table}.sha = ?", ref, ref). + success.order(id: :desc) end - # ref can't be HEAD or SHA, can only be branch/tag name + # ref can't be HEAD, can only be branch/tag name or SHA def latest_success_builds_for(ref = 'master') Ci::Build.joins(:pipeline). merge(latest_success_pipeline_for(ref)). diff --git a/spec/requests/shared/artifacts_context.rb b/spec/requests/shared/artifacts_context.rb index 635c5646f919166e3db8bd1e13b8eb27dbd664fe..102ae392844ca8ab88642be0c0019a342f3c6cae 100644 --- a/spec/requests/shared/artifacts_context.rb +++ b/spec/requests/shared/artifacts_context.rb @@ -38,6 +38,14 @@ shared_examples 'artifacts from ref successfully' do create(:ci_build, status, :artifacts, pipeline: new_pipeline) end + context 'with sha' do + before do + get path_from_ref(pipeline.sha) + end + + it('gives the file') { verify } + end + context 'with regular branch' do before do pipeline.update(ref: 'master',