Commit 85409a5a authored by Lin Jen-Shin's avatar Lin Jen-Shin

Use ci_commits.ref (Pipeline#ref) to find builds

parent 5c1f75e9
...@@ -434,15 +434,8 @@ class Project < ActiveRecord::Base ...@@ -434,15 +434,8 @@ class Project < ActiveRecord::Base
end end
def builds_for(ref = 'HEAD') def builds_for(ref = 'HEAD')
commit_object = commit(ref) Ci::Build.joins(:pipeline).
merge(Ci::Pipeline.where(ref: ref, project: self))
if commit_object.nil?
Ci::Build.none
else
Ci::Build.joins(:pipeline).
merge(Ci::Pipeline.where(sha: commit_object.sha,
project: self))
end
end end
def merge_base_commit(first_commit_id, second_commit_id) def merge_base_commit(first_commit_id, second_commit_id)
......
...@@ -5,7 +5,8 @@ describe Ci::Build, models: true do ...@@ -5,7 +5,8 @@ describe Ci::Build, models: true do
let(:pipeline) do let(:pipeline) do
create(:ci_pipeline, project: project, create(:ci_pipeline, project: project,
sha: project.commit.id) sha: project.commit.id,
ref: 'fix')
end end
let(:build) { create(:ci_build, pipeline: pipeline) } let(:build) { create(:ci_build, pipeline: pipeline) }
...@@ -698,7 +699,7 @@ describe Ci::Build, models: true do ...@@ -698,7 +699,7 @@ describe Ci::Build, models: true do
end end
it 'returns builds from ref' do it 'returns builds from ref' do
builds = project.latest_success_builds_for('HEAD') builds = project.latest_success_builds_for('fix')
expect(builds).to contain_exactly(build) expect(builds).to contain_exactly(build)
end end
......
...@@ -190,7 +190,7 @@ describe API::API, api: true do ...@@ -190,7 +190,7 @@ describe API::API, api: true do
describe 'GET /projects/:id/artifacts/:ref_name/download?job=name' do describe 'GET /projects/:id/artifacts/:ref_name/download?job=name' do
include_context 'artifacts from ref and build name' include_context 'artifacts from ref and build name'
def path_from_ref(ref = pipeline.sha, job = build.name) def path_from_ref(ref = pipeline.ref, job = build.name)
api("/projects/#{project.id}/builds/artifacts/#{ref}/download?job=#{job}", user) api("/projects/#{project.id}/builds/artifacts/#{ref}/download?job=#{job}", user)
end end
......
...@@ -10,7 +10,7 @@ describe Projects::ArtifactsController do ...@@ -10,7 +10,7 @@ describe Projects::ArtifactsController do
end end
def path_from_ref( def path_from_ref(
ref = pipeline.sha, job = build.name, path = 'browse') ref = pipeline.ref, job = build.name, path = 'browse')
search_namespace_project_artifacts_path( search_namespace_project_artifacts_path(
project.namespace, project.namespace,
project, project,
......
...@@ -2,7 +2,10 @@ shared_context 'artifacts from ref and build name' do ...@@ -2,7 +2,10 @@ shared_context 'artifacts from ref and build name' do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project) } let(:project) { create(:project) }
let(:pipeline) do let(:pipeline) do
create(:ci_pipeline, project: project, sha: project.commit('fix').sha) create(:ci_pipeline,
project: project,
sha: project.commit('fix').sha,
ref: 'fix')
end end
let(:build) { create(:ci_build, :success, :artifacts, pipeline: pipeline) } let(:build) { create(:ci_build, :success, :artifacts, pipeline: pipeline) }
...@@ -30,17 +33,10 @@ shared_examples 'artifacts from ref with 404' do ...@@ -30,17 +33,10 @@ shared_examples 'artifacts from ref with 404' do
end end
shared_examples 'artifacts from ref successfully' do shared_examples 'artifacts from ref successfully' do
context 'with sha' do
before do
get path_from_ref
end
it('gives the file') { verify }
end
context 'with regular branch' do context 'with regular branch' do
before do before do
pipeline.update(sha: project.commit('master').sha) pipeline.update(ref: 'master',
sha: project.commit('master').sha)
end end
before do before do
...@@ -52,7 +48,8 @@ shared_examples 'artifacts from ref successfully' do ...@@ -52,7 +48,8 @@ shared_examples 'artifacts from ref successfully' do
context 'with branch name containing slash' do context 'with branch name containing slash' do
before do before do
pipeline.update(sha: project.commit('improve/awesome').sha) pipeline.update(ref: 'improve/awesome',
sha: project.commit('improve/awesome').sha)
end end
before do before do
......
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