summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2016-07-18 23:17:43 +0800
committerLin Jen-Shin <godfat@godfat.org>2016-07-18 23:18:16 +0800
commit57a78c37c72b2d697bc863ebfb84d3ca61ba9d7b (patch)
tree6b3778b5a62e4c01131f1f8291027033a798bf08
parent72699d9719a269a82be6af0812d86d84733c77bd (diff)
downloadgitlab-ce-57a78c37c72b2d697bc863ebfb84d3ca61ba9d7b.tar.gz
Show notice if builds are not from latest pipeline
-rw-r--r--app/models/ci/build.rb3
-rw-r--r--app/models/project.rb12
-rw-r--r--app/views/projects/branches/_branch.html.haml32
-rw-r--r--app/views/projects/buttons/_download.html.haml18
-rw-r--r--app/views/projects/tags/_download.html.haml18
5 files changed, 52 insertions, 31 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index ffac3a22efc..9af04964b85 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -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
diff --git a/app/models/project.rb b/app/models/project.rb
index 12851c5d0ec..77431c3f538 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -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)
diff --git a/app/views/projects/branches/_branch.html.haml b/app/views/projects/branches/_branch.html.haml
index c2d7237f142..084a8474c4f 100644
--- a/app/views/projects/branches/_branch.html.haml
+++ b/app/views/projects/branches/_branch.html.haml
@@ -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
diff --git a/app/views/projects/buttons/_download.html.haml b/app/views/projects/buttons/_download.html.haml
index 2eedc0d9a42..24a11005e61 100644
--- a/app/views/projects/buttons/_download.html.haml
+++ b/app/views/projects/buttons/_download.html.haml
@@ -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}'
diff --git a/app/views/projects/tags/_download.html.haml b/app/views/projects/tags/_download.html.haml
index 4a8ef77ad8b..d2650809a3e 100644
--- a/app/views/projects/tags/_download.html.haml
+++ b/app/views/projects/tags/_download.html.haml
@@ -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}'