Commit 57a78c37 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Show notice if builds are not from latest pipeline

parent 72699d97
......@@ -15,6 +15,9 @@ module Ci
scope :with_artifacts, ->() { where.not(artifacts_file: nil) }
scope :with_expired_artifacts, ->() { with_artifacts.where('artifacts_expire_at < ?', Time.now) }
scope :last_month, ->() { where('created_at > ?', Date.today - 1.month) }
scope :latest_success_with_artifacts, ->() do
with_artifacts.success.latest
end
mount_uploader :artifacts_file, ArtifactUploader
mount_uploader :artifacts_metadata, ArtifactUploader
......
......@@ -429,10 +429,16 @@ class Project < ActiveRecord::Base
repository.commit(ref)
end
def latest_success_builds_for(ref = 'HEAD')
# ref can't be HEAD or SHA, can only be branch/tag name
def latest_success_pipeline_for(ref = 'master')
pipelines.where(ref: ref).success.latest
end
# ref can't be HEAD or SHA, can only be branch/tag name
def latest_success_builds_for(ref = 'master')
Ci::Build.joins(:pipeline).
merge(pipelines.where(ref: ref).success.latest).
with_artifacts.success.latest
merge(latest_success_pipeline_for(ref)).
latest_success_with_artifacts
end
def merge_base_commit(first_commit_id, second_commit_id)
......
......@@ -27,20 +27,24 @@
= 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
- artifacts = @project.latest_success_builds_for(branch.name)
- if artifacts.any?
.dropdown.inline.artifacts-btn
%a.btn.dropdown-toggle{ 'data-toggle' => 'dropdown' }
= icon('download')
%span.caret
%span.sr-only
Select Archive Format
%ul.dropdown-menu.dropdown-menu-align-right{ role: 'menu' }
%li.dropdown-header Artifacts
- artifacts.each do |job|
%li
= link_to download_namespace_project_build_artifacts_path(@project.namespace, @project, job), rel: 'nofollow' do
%span Download '#{job.name}'
- pipeline = @project.latest_success_pipeline_for(branch.name).first
- if pipeline
- artifacts = pipeline.builds.latest_success_with_artifacts
- if artifacts.any?
.dropdown.inline.artifacts-btn
%a.btn.dropdown-toggle{ 'data-toggle' => 'dropdown' }
= icon('download')
%span.caret
%span.sr-only
Select Archive Format
%ul.dropdown-menu.dropdown-menu-align-right{ role: 'menu' }
%li.dropdown-header Artifacts
- unless pipeline.latest?
= " (not latest, but #{link_to(pipeline.short_sha, namespace_project_commits_path(@project.namespace, @project, pipeline.sha))})"
- artifacts.each do |job|
%li
= link_to download_namespace_project_build_artifacts_path(@project.namespace, @project, job), rel: 'nofollow' do
%span Download '#{job.name}'
- if can_remove_branch?(@project, branch.name)
= link_to namespace_project_branch_path(@project.namespace, @project, branch.name), class: 'btn btn-remove remove-row has-tooltip', title: "Delete branch", method: :delete, data: { confirm: "Deleting the '#{branch.name}' branch cannot be undone. Are you sure?", container: 'body' }, remote: true do
......
......@@ -14,10 +14,14 @@
%li
= link_to archive_namespace_project_repository_path(@project.namespace, @project, ref: @ref, format: 'tar.gz'), rel: 'nofollow' do
%span Download tar.gz
- artifacts = @project.latest_success_builds_for(@ref)
- if artifacts.any?
%li.dropdown-header Artifacts
- artifacts.each do |job|
%li
= link_to download_namespace_project_build_artifacts_path(@project.namespace, @project, job), rel: 'nofollow' do
%span Download '#{job.name}'
- pipeline = @project.latest_success_pipeline_for(@ref).first
- if pipeline
- artifacts = pipeline.builds.latest_success_with_artifacts
- if artifacts.any?
%li.dropdown-header Artifacts
- unless pipeline.latest?
= " (not latest, but #{link_to(pipeline.short_sha, namespace_project_commits_path(@project.namespace, @project, pipeline.sha))})"
- artifacts.each do |job|
%li
= link_to download_namespace_project_build_artifacts_path(@project.namespace, @project, job), rel: 'nofollow' do
%span Download '#{job.name}'
......@@ -12,10 +12,14 @@
%li
= link_to archive_namespace_project_repository_path(project.namespace, project, ref: ref, format: 'tar.gz'), rel: 'nofollow' do
%span Download tar.gz
- artifacts = project.latest_success_builds_for(ref)
- if artifacts.any?
%li.dropdown-header Artifacts
- artifacts.each do |job|
%li
= link_to download_namespace_project_build_artifacts_path(project.namespace, project, job), rel: 'nofollow' do
%span Download '#{job.name}'
- pipeline = project.latest_success_pipeline_for(ref).first
- if pipeline
- artifacts = pipeline.builds.latest_success_with_artifacts
- if artifacts.any?
%li.dropdown-header Artifacts
- unless pipeline.latest?
= " (not latest, but #{link_to(pipeline.short_sha, namespace_project_commits_path(project.namespace, project, pipeline.sha))})"
- artifacts.each do |job|
%li
= link_to download_namespace_project_build_artifacts_path(project.namespace, project, job), rel: 'nofollow' do
%span Download '#{job.name}'
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