diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2016-07-18 20:10:50 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2016-07-18 20:10:50 +0800 |
commit | 85409a5a10d22bebbc54a9c7b7c76e7c0e11b208 (patch) | |
tree | e9589b9526596939222fb261bbd31be08751a808 | |
parent | 5c1f75e983c88d4c884a15e9f84550fd256fb07f (diff) | |
download | gitlab-ce-85409a5a10d22bebbc54a9c7b7c76e7c0e11b208.tar.gz |
Use ci_commits.ref (Pipeline#ref) to find builds
-rw-r--r-- | app/models/project.rb | 11 | ||||
-rw-r--r-- | spec/models/build_spec.rb | 5 | ||||
-rw-r--r-- | spec/requests/api/builds_spec.rb | 2 | ||||
-rw-r--r-- | spec/requests/projects/artifacts_controller_spec.rb | 2 | ||||
-rw-r--r-- | spec/requests/shared/artifacts_context.rb | 19 |
5 files changed, 15 insertions, 24 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index d6e37e66a8b..770ec1c8a68 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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 + Ci::Build.joins(:pipeline). + merge(Ci::Pipeline.where(ref: ref, project: self)) end def merge_base_commit(first_commit_id, second_commit_id) diff --git a/spec/models/build_spec.rb b/spec/models/build_spec.rb index a57f0b6886c..53064138a50 100644 --- a/spec/models/build_spec.rb +++ b/spec/models/build_spec.rb @@ -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 diff --git a/spec/requests/api/builds_spec.rb b/spec/requests/api/builds_spec.rb index bc6242a0d71..fb0f066498a 100644 --- a/spec/requests/api/builds_spec.rb +++ b/spec/requests/api/builds_spec.rb @@ -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 diff --git a/spec/requests/projects/artifacts_controller_spec.rb b/spec/requests/projects/artifacts_controller_spec.rb index c8a21f7d0ec..1782d37008a 100644 --- a/spec/requests/projects/artifacts_controller_spec.rb +++ b/spec/requests/projects/artifacts_controller_spec.rb @@ -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, diff --git a/spec/requests/shared/artifacts_context.rb b/spec/requests/shared/artifacts_context.rb index 0c9f33bfcb2..ff74b72a0b3 100644 --- a/spec/requests/shared/artifacts_context.rb +++ b/spec/requests/shared/artifacts_context.rb @@ -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 |