From 49f72e705fa225175834b5e6b2b1f78f1f608b9c Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Tue, 2 Aug 2016 14:01:22 +0200 Subject: Show deployment status on a MR view --- app/models/deployment.rb | 7 ++++ app/models/environment.rb | 6 ++++ app/models/merge_request.rb | 6 ++++ .../merge_requests/widget/_heading.html.haml | 40 ++++++++++++++-------- 4 files changed, 45 insertions(+), 14 deletions(-) (limited to 'app') diff --git a/app/models/deployment.rb b/app/models/deployment.rb index 1a7cd60817e..67a4f3998ec 100644 --- a/app/models/deployment.rb +++ b/app/models/deployment.rb @@ -36,4 +36,11 @@ class Deployment < ActiveRecord::Base def manual_actions deployable.try(:other_actions) end + + def deployed_to(ref) + commit = project.commit(ref) + return false unless commit + + project.repository.merge_base(commit.id, sha) == commit.id + end end diff --git a/app/models/environment.rb b/app/models/environment.rb index baed106e8c8..f6fdb8d1ecf 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -25,4 +25,10 @@ class Environment < ActiveRecord::Base def nullify_external_url self.external_url = nil if self.external_url.blank? end + + def deployed_to?(ref) + return unless last_deployment + + last_deployment.deployed_to(ref) + end end diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index b1fb3ce5d69..85e4d1f6b51 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -590,6 +590,12 @@ class MergeRequest < ActiveRecord::Base !pipeline || pipeline.success? end + def environments + target_project.environments.select do |environment| + environment.deployed_to?(ref_path) + end + end + def state_human_name if merged? "Merged" diff --git a/app/views/projects/merge_requests/widget/_heading.html.haml b/app/views/projects/merge_requests/widget/_heading.html.haml index 6ef640bb654..0581659b742 100644 --- a/app/views/projects/merge_requests/widget/_heading.html.haml +++ b/app/views/projects/merge_requests/widget/_heading.html.haml @@ -1,21 +1,22 @@ - if @pipeline .mr-widget-heading - - %w[success success_with_warnings skipped canceled failed running pending].each do |status| - .ci_widget{ class: "ci-#{status}", style: ("display:none" unless @pipeline.status == status) } - = ci_icon_for_status(status) - %span - CI build - = ci_label_for_status(status) - for - - commit = @merge_request.diff_head_commit - = succeed "." do - = link_to @pipeline.short_sha, namespace_project_commit_path(@merge_request.source_project.namespace, @merge_request.source_project, @pipeline.sha), class: "monospace" - %span.ci-coverage - = link_to "View details", builds_namespace_project_merge_request_path(@project.namespace, @project, @merge_request), class: "js-show-tab", data: {action: 'builds'} + - @merge_request.environments.each do |environments| + - %w[success success_with_warnings skipped canceled failed running pending].each do |status| + .ci_widget{ class: "ci-#{status}", style: ("display:none" unless @pipeline.status == status) } + = ci_icon_for_status(status) + %span + CI build + = ci_label_for_status(status) + for + - commit = @merge_request.diff_head_commit + = succeed "." do + = link_to @pipeline.short_sha, namespace_project_commit_path(@merge_request.source_project.namespace, @merge_request.source_project, @pipeline.sha), class: "monospace" + %span.ci-coverage + = link_to "View details", builds_namespace_project_merge_request_path(@project.namespace, @project, @merge_request), class: "js-show-tab", data: {action: 'builds'} - elsif @merge_request.has_ci? - - # Compatibility with old CI integrations (ex jenkins) when you request status from CI server via AJAX - - # Remove in later versions when services like Jenkins will set CI status via Commit status API + // Compatibility with old CI integrations (ex jenkins) when you request status from CI server via AJAX + // Remove in later versions when services like Jenkins will set CI status via Commit status API .mr-widget-heading - %w[success skipped canceled failed running pending].each do |status| .ci_widget{class: "ci-#{status}", style: "display:none"} @@ -42,3 +43,14 @@ .ci_widget.ci-error{style: "display:none"} = icon("times-circle") Could not connect to the CI server. Please check your settings and try again. + +- @merge_request.environments.each do |environment| + .mr-widget-heading + .ci_widget{ class: "ci-success" } + = ci_icon_for_status("success") + %span + Released to #{environment.name} + = succeed '.' do + = time_ago_with_tooltip(environment.created_at, placement: 'bottom') + - if environment.external_url + = link_to icon('external-link'), environment.external_url -- cgit v1.2.1