Commit d84aa560 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Make Pipeline.latest_successful_for return the record

parent 2a435e1d
...@@ -21,12 +21,8 @@ module Ci ...@@ -21,12 +21,8 @@ module Ci
after_save :keep_around_commits after_save :keep_around_commits
# ref can't be HEAD or SHA, can only be branch/tag name # ref can't be HEAD or SHA, can only be branch/tag name
scope :latest_successful_for, ->(ref) do def self.latest_successful_for(ref)
latest_for(ref).success where(ref: ref).order(id: :desc).success.first
end
scope :latest_for, ->(ref) do
where(ref: ref).order(id: :desc).limit(1)
end end
def self.truncate_sha(sha) def self.truncate_sha(sha)
......
...@@ -432,7 +432,7 @@ class Project < ActiveRecord::Base ...@@ -432,7 +432,7 @@ class Project < ActiveRecord::Base
# ref can't be HEAD, can only be branch/tag name or SHA # ref can't be HEAD, can only be branch/tag name or SHA
def latest_successful_builds_for(ref = default_branch) def latest_successful_builds_for(ref = default_branch)
latest_pipeline = pipelines.latest_successful_for(ref).first latest_pipeline = pipelines.latest_successful_for(ref)
if latest_pipeline if latest_pipeline
latest_pipeline.builds.latest.with_artifacts latest_pipeline.builds.latest.with_artifacts
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
= link_to namespace_project_compare_index_path(@project.namespace, @project, from: @repository.root_ref, to: branch.name), class: 'btn btn-default', method: :post, title: "Compare" do = link_to namespace_project_compare_index_path(@project.namespace, @project, from: @repository.root_ref, to: branch.name), class: 'btn btn-default', method: :post, title: "Compare" do
Compare Compare
- pipeline = @project.pipelines.latest_successful_for(branch.name).first - pipeline = @project.pipelines.latest_successful_for(branch.name)
- if pipeline - if pipeline
- artifacts = pipeline.builds.latest.with_artifacts - artifacts = pipeline.builds.latest.with_artifacts
- if artifacts.any? - if artifacts.any?
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
%li %li
= link_to archive_namespace_project_repository_path(@project.namespace, @project, ref: @ref, format: 'tar.gz'), rel: 'nofollow' do = link_to archive_namespace_project_repository_path(@project.namespace, @project, ref: @ref, format: 'tar.gz'), rel: 'nofollow' do
%span Download tar.gz %span Download tar.gz
- pipeline = @project.pipelines.latest_successful_for(@ref).first - pipeline = @project.pipelines.latest_successful_for(@ref)
- if pipeline - if pipeline
- artifacts = pipeline.builds.latest.with_artifacts - artifacts = pipeline.builds.latest.with_artifacts
- if artifacts.any? - if artifacts.any?
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
= link_to archive_namespace_project_repository_path(@project.namespace, @project, ref: ref, format: 'tar'), rel: 'nofollow' do = link_to archive_namespace_project_repository_path(@project.namespace, @project, ref: ref, format: 'tar'), rel: 'nofollow' do
%i.fa.fa-download %i.fa.fa-download
%span Download tar %span Download tar
- pipeline = @project.pipelines.latest_successful_for(ref).first - pipeline = @project.pipelines.latest_successful_for(ref)
- if pipeline - if pipeline
- artifacts = pipeline.builds.latest.with_artifacts - artifacts = pipeline.builds.latest.with_artifacts
- if artifacts.any? - if artifacts.any?
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
%li %li
= link_to archive_namespace_project_repository_path(project.namespace, project, ref: ref, format: 'tar.gz'), rel: 'nofollow' do = link_to archive_namespace_project_repository_path(project.namespace, project, ref: ref, format: 'tar.gz'), rel: 'nofollow' do
%span Download tar.gz %span Download tar.gz
- pipeline = project.pipelines.latest_successful_for(ref).first - pipeline = project.pipelines.latest_successful_for(ref)
- if pipeline - if pipeline
- artifacts = pipeline.builds.latest.with_artifacts - artifacts = pipeline.builds.latest.with_artifacts
- if artifacts.any? - if artifacts.any?
......
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