Commit 06e3bb9f authored by Douwe Maan's avatar Douwe Maan

Merge branch 'zj-deployment-status-on-mr' into 'master'

Show deployment status on a MR view

## What are the relevant issue numbers?

Resolves #19571, one in the list of #19992

## Screenshots (if relevant)

external_url = nil
![Screen_Shot_2016-08-02_at_13.57.03](/uploads/20ea1587eea556c7a1acd0ff726a5bfb/Screen_Shot_2016-08-02_at_13.57.03.png)

external_url != nil
![Screen_Shot_2016-08-02_at_13.59.59](/uploads/0094b9ddece3f4bf76c83988840c096d/Screen_Shot_2016-08-02_at_13.59.59.png)

Note, the timings are weird between merging and deploying, that is because I did it in the wrong order.

## Does this MR meet the acceptance criteria?

- [X] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added
- Tests
  - [x] Added for this feature/bug
  - [x] All builds are passing

See merge request !5622
parents 9aa68b87 07fc2f85
...@@ -40,6 +40,7 @@ v 8.11.0 (unreleased) ...@@ -40,6 +40,7 @@ v 8.11.0 (unreleased)
- Update `timeago` plugin to use multiple string/locale settings - Update `timeago` plugin to use multiple string/locale settings
- Remove unused images (ClemMakesApps) - Remove unused images (ClemMakesApps)
- Limit git rev-list output count to one in forced push check - Limit git rev-list output count to one in forced push check
- Show deployment status on merge requests with external URLs
- Clean up unused routes (Josef Strzibny) - Clean up unused routes (Josef Strzibny)
- Fix issue on empty project to allow developers to only push to protected branches if given permission - Fix issue on empty project to allow developers to only push to protected branches if given permission
- Add green outline to New Branch button. !5447 (winniehell) - Add green outline to New Branch button. !5447 (winniehell)
......
...@@ -69,6 +69,10 @@ ...@@ -69,6 +69,10 @@
&.ci-success { &.ci-success {
color: $gl-success; color: $gl-success;
a.environment {
color: inherit;
}
} }
&.ci-success_with_warnings { &.ci-success_with_warnings {
...@@ -126,7 +130,6 @@ ...@@ -126,7 +130,6 @@
&.has-conflicts .fa-exclamation-triangle { &.has-conflicts .fa-exclamation-triangle {
color: $gl-warning; color: $gl-warning;
} }
} }
p:last-child { p:last-child {
......
...@@ -36,4 +36,10 @@ class Deployment < ActiveRecord::Base ...@@ -36,4 +36,10 @@ class Deployment < ActiveRecord::Base
def manual_actions def manual_actions
deployable.try(:other_actions) deployable.try(:other_actions)
end end
def includes_commit?(commit)
return false unless commit
project.repository.is_ancestor?(commit.id, sha)
end
end end
...@@ -25,4 +25,10 @@ class Environment < ActiveRecord::Base ...@@ -25,4 +25,10 @@ class Environment < ActiveRecord::Base
def nullify_external_url def nullify_external_url
self.external_url = nil if self.external_url.blank? self.external_url = nil if self.external_url.blank?
end end
def includes_commit?(commit)
return false unless last_deployment
last_deployment.includes_commit?(commit)
end
end end
...@@ -591,6 +591,14 @@ class MergeRequest < ActiveRecord::Base ...@@ -591,6 +591,14 @@ class MergeRequest < ActiveRecord::Base
!pipeline || pipeline.success? !pipeline || pipeline.success?
end end
def environments
return unless diff_head_commit
target_project.environments.select do |environment|
environment.includes_commit?(diff_head_commit)
end
end
def state_human_name def state_human_name
if merged? if merged?
"Merged" "Merged"
......
...@@ -42,3 +42,16 @@ ...@@ -42,3 +42,16 @@
.ci_widget.ci-error{style: "display:none"} .ci_widget.ci-error{style: "display:none"}
= icon("times-circle") = icon("times-circle")
Could not connect to the CI server. Please check your settings and try again. 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.ci-success
= ci_icon_for_status("success")
%span.hidden-sm
Deployed to
= succeed '.' do
= link_to environment.name, namespace_project_environment_path(@project.namespace, @project, environment), class: 'environment'
- external_url = environment.external_url
- if external_url
= link_to external_url, target: '_blank' do
= icon('external-link', text: "View on #{external_url.gsub(/\A.*?:\/\//, '')}", right: true)
...@@ -589,12 +589,12 @@ ActiveRecord::Schema.define(version: 20160810142633) do ...@@ -589,12 +589,12 @@ ActiveRecord::Schema.define(version: 20160810142633) do
t.datetime "locked_at" t.datetime "locked_at"
t.integer "updated_by_id" t.integer "updated_by_id"
t.string "merge_error" t.string "merge_error"
t.text "merge_params"
t.boolean "merge_when_build_succeeds", default: false, null: false t.boolean "merge_when_build_succeeds", default: false, null: false
t.integer "merge_user_id" t.integer "merge_user_id"
t.string "merge_commit_sha" t.string "merge_commit_sha"
t.datetime "deleted_at" t.datetime "deleted_at"
t.string "in_progress_merge_commit_sha" t.string "in_progress_merge_commit_sha"
t.text "merge_params"
end end
add_index "merge_requests", ["assignee_id"], name: "index_merge_requests_on_assignee_id", using: :btree add_index "merge_requests", ["assignee_id"], name: "index_merge_requests_on_assignee_id", using: :btree
......
...@@ -15,4 +15,28 @@ describe Deployment, models: true do ...@@ -15,4 +15,28 @@ describe Deployment, models: true do
it { is_expected.to validate_presence_of(:ref) } it { is_expected.to validate_presence_of(:ref) }
it { is_expected.to validate_presence_of(:sha) } it { is_expected.to validate_presence_of(:sha) }
describe '#includes_commit?' do
let(:project) { create(:project) }
let(:environment) { create(:environment, project: project) }
let(:deployment) do
create(:deployment, environment: environment, sha: project.commit.id)
end
context 'when there is no project commit' do
it 'returns false' do
commit = project.commit('feature')
expect(deployment.includes_commit?(commit)).to be false
end
end
context 'when they share the same tree branch' do
it 'returns true' do
commit = project.commit
expect(deployment.includes_commit?(commit)).to be true
end
end
end
end end
...@@ -30,4 +30,37 @@ describe Environment, models: true do ...@@ -30,4 +30,37 @@ describe Environment, models: true do
expect(env.external_url).to be_nil expect(env.external_url).to be_nil
end end
end end
describe '#includes_commit?' do
context 'without a last deployment' do
it "returns false" do
expect(environment.includes_commit?('HEAD')).to be false
end
end
context 'with a last deployment' do
let(:project) { create(:project) }
let(:environment) { create(:environment, project: project) }
let!(:deployment) do
create(:deployment, environment: environment, sha: project.commit('master').id)
end
context 'in the same branch' do
it 'returns true' do
expect(environment.includes_commit?(RepoHelpers.sample_commit)).to be true
end
end
context 'not in the same branch' do
before do
deployment.update(sha: project.commit('feature').id)
end
it 'returns false' do
expect(environment.includes_commit?(RepoHelpers.sample_commit)).to be false
end
end
end
end
end end
...@@ -674,6 +674,21 @@ describe MergeRequest, models: true do ...@@ -674,6 +674,21 @@ describe MergeRequest, models: true do
end end
end end
describe "#environments" do
let(:project) { create(:project) }
let!(:environment) { create(:environment, project: project) }
let!(:environment1) { create(:environment, project: project) }
let!(:environment2) { create(:environment, project: project) }
let(:merge_request) { create(:merge_request, source_project: project) }
it 'selects deployed environments' do
create(:deployment, environment: environment, sha: project.commit('master').id)
create(:deployment, environment: environment1, sha: project.commit('feature').id)
expect(merge_request.environments).to eq [environment]
end
end
describe "#reload_diff" do describe "#reload_diff" do
let(:note) { create(:diff_note_on_merge_request, project: subject.project, noteable: subject) } let(:note) { create(:diff_note_on_merge_request, project: subject.project, noteable: subject) }
......
require 'spec_helper'
describe 'projects/merge_requests/widget/_heading' do
include Devise::TestHelpers
context 'when released to an environment' do
let(:project) { merge_request.target_project }
let(:merge_request) { create(:merge_request, :merged) }
let(:environment) { create(:environment, project: project) }
let!(:deployment) do
create(:deployment, environment: environment, sha: project.commit('master').id)
end
before do
assign(:merge_request, merge_request)
assign(:project, project)
render
end
it 'displays that the environment is deployed' do
expect(rendered).to match("Deployed to")
expect(rendered).to match("#{environment.name}")
end
end
end
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