Commit 0538e1e9 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Support SHA for downloading artifacts:

So if we also query against SHA, we could actually support SHA.
If there's a branch or tag also named like SHA this could be
ambiguous, but since we could already do that in Git, I think
it's probably fine, people would be aware they shouldn't use
the same name anyway.
parent fba2ec45
...@@ -429,12 +429,15 @@ class Project < ActiveRecord::Base ...@@ -429,12 +429,15 @@ class Project < ActiveRecord::Base
repository.commit(ref) repository.commit(ref)
end 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') 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 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') def latest_success_builds_for(ref = 'master')
Ci::Build.joins(:pipeline). Ci::Build.joins(:pipeline).
merge(latest_success_pipeline_for(ref)). merge(latest_success_pipeline_for(ref)).
......
...@@ -38,6 +38,14 @@ shared_examples 'artifacts from ref successfully' do ...@@ -38,6 +38,14 @@ shared_examples 'artifacts from ref successfully' do
create(:ci_build, status, :artifacts, pipeline: new_pipeline) create(:ci_build, status, :artifacts, pipeline: new_pipeline)
end 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 context 'with regular branch' do
before do before do
pipeline.update(ref: 'master', pipeline.update(ref: 'master',
......
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