Make Pipeline.latest_successful_for return the record
This commit is contained in:
parent
2a435e1d11
commit
d84aa56033
6 changed files with 7 additions and 11 deletions
|
@ -21,12 +21,8 @@ module Ci
|
|||
after_save :keep_around_commits
|
||||
|
||||
# ref can't be HEAD or SHA, can only be branch/tag name
|
||||
scope :latest_successful_for, ->(ref) do
|
||||
latest_for(ref).success
|
||||
end
|
||||
|
||||
scope :latest_for, ->(ref) do
|
||||
where(ref: ref).order(id: :desc).limit(1)
|
||||
def self.latest_successful_for(ref)
|
||||
where(ref: ref).order(id: :desc).success.first
|
||||
end
|
||||
|
||||
def self.truncate_sha(sha)
|
||||
|
|
|
@ -432,7 +432,7 @@ class Project < ActiveRecord::Base
|
|||
|
||||
# ref can't be HEAD, can only be branch/tag name or SHA
|
||||
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
|
||||
latest_pipeline.builds.latest.with_artifacts
|
||||
|
|
|
@ -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
|
||||
Compare
|
||||
|
||||
- pipeline = @project.pipelines.latest_successful_for(branch.name).first
|
||||
- pipeline = @project.pipelines.latest_successful_for(branch.name)
|
||||
- if pipeline
|
||||
- artifacts = pipeline.builds.latest.with_artifacts
|
||||
- if artifacts.any?
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
%li
|
||||
= link_to archive_namespace_project_repository_path(@project.namespace, @project, ref: @ref, format: 'tar.gz'), rel: 'nofollow' do
|
||||
%span Download tar.gz
|
||||
- pipeline = @project.pipelines.latest_successful_for(@ref).first
|
||||
- pipeline = @project.pipelines.latest_successful_for(@ref)
|
||||
- if pipeline
|
||||
- artifacts = pipeline.builds.latest.with_artifacts
|
||||
- if artifacts.any?
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
= link_to archive_namespace_project_repository_path(@project.namespace, @project, ref: ref, format: 'tar'), rel: 'nofollow' do
|
||||
%i.fa.fa-download
|
||||
%span Download tar
|
||||
- pipeline = @project.pipelines.latest_successful_for(ref).first
|
||||
- pipeline = @project.pipelines.latest_successful_for(ref)
|
||||
- if pipeline
|
||||
- artifacts = pipeline.builds.latest.with_artifacts
|
||||
- if artifacts.any?
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
%li
|
||||
= link_to archive_namespace_project_repository_path(project.namespace, project, ref: ref, format: 'tar.gz'), rel: 'nofollow' do
|
||||
%span Download tar.gz
|
||||
- pipeline = project.pipelines.latest_successful_for(ref).first
|
||||
- pipeline = project.pipelines.latest_successful_for(ref)
|
||||
- if pipeline
|
||||
- artifacts = pipeline.builds.latest.with_artifacts
|
||||
- if artifacts.any?
|
||||
|
|
Loading…
Reference in a new issue