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
end
def builds_for(ref = 'HEAD')
commit_object = commit(ref)
if commit_object.nil?
Ci::Build.none
else
Ci::Build.joins(:pipeline).
merge(Ci::Pipeline.where(sha: commit_object.sha,
project: self))
end
merge(Ci::Pipeline.where(ref: ref, project: self))
end
def merge_base_commit(first_commit_id, second_commit_id)
......
......@@ -5,7 +5,8 @@ describe Ci::Build, models: true do
let(:pipeline) do
create(:ci_pipeline, project: project,
sha: project.commit.id)
sha: project.commit.id,
ref: 'fix')
end
let(:build) { create(:ci_build, pipeline: pipeline) }
......@@ -698,7 +699,7 @@ describe Ci::Build, models: true do
end
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)
end
......
......@@ -190,7 +190,7 @@ describe API::API, api: true do
describe 'GET /projects/:id/artifacts/:ref_name/download?job=name' do
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)
end
......
......@@ -10,7 +10,7 @@ describe Projects::ArtifactsController do
end
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(
project.namespace,
project,
......
......@@ -2,7 +2,10 @@ shared_context 'artifacts from ref and build name' do
let(:user) { create(:user) }
let(:project) { create(:project) }
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
let(:build) { create(:ci_build, :success, :artifacts, pipeline: pipeline) }
......@@ -30,17 +33,10 @@ shared_examples 'artifacts from ref with 404' do
end
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
before do
pipeline.update(sha: project.commit('master').sha)
pipeline.update(ref: 'master',
sha: project.commit('master').sha)
end
before do
......@@ -52,7 +48,8 @@ shared_examples 'artifacts from ref successfully' do
context 'with branch name containing slash' do
before do
pipeline.update(sha: project.commit('improve/awesome').sha)
pipeline.update(ref: 'improve/awesome',
sha: project.commit('improve/awesome').sha)
end
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